Library working

This commit is contained in:
KoalaSat 2023-01-27 12:32:17 +01:00
parent fc6e6e9bdf
commit e01051a8c5
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
4 changed files with 30 additions and 31 deletions

View File

@ -9,6 +9,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.nostros.modules.DatabaseModule;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.exceptions.WebsocketNotConnectedException;
import org.java_websocket.handshake.ServerHandshake;
import org.json.JSONArray;
@ -35,14 +36,11 @@ public class Websocket {
public void send(String message) {
if (webSocket != null) {
Log.d("Websocket", "SEND URL:" + url + " __ " + message);
if (!webSocket.isOpen()) {
try {
this.connect(pubKey);
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
try {
webSocket.send(message);
} catch (WebsocketNotConnectedException e) {
}
webSocket.send(message);
}
}
@ -62,31 +60,31 @@ public class Websocket {
@Override
public void onMessage(String message) {
// Log.d("Websocket", "RECEIVE URL:" + url + " __ " + message);
// JSONArray jsonArray;
// try {
// jsonArray = new JSONArray(message);
// String messageType = jsonArray.get(0).toString();
// if (messageType.equals("EVENT")) {
// JSONObject data = jsonArray.getJSONObject(2);
// database.saveEvent(data, userPubKey);
// reactNativeEvent(data.getString("id"));
// } else if (messageType.equals("OK")) {
// reactNativeConfirmation(jsonArray.get(1).toString());
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
Log.d("Websocket", "RECEIVE URL:" + url + " __ " + message);
JSONArray jsonArray;
try {
jsonArray = new JSONArray(message);
String messageType = jsonArray.get(0).toString();
if (messageType.equals("EVENT")) {
JSONObject data = jsonArray.getJSONObject(2);
database.saveEvent(data, userPubKey);
reactNativeEvent(data.getString("id"));
} else if (messageType.equals("OK")) {
reactNativeConfirmation(jsonArray.get(1).toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onClose(int code, String reason, boolean remote) {
// this.connect();
webSocket.connect();
}
@Override
public void onError(Exception ex) {
// ex.printStackTrace();
ex.printStackTrace();
}
};
webSocket.connect();

View File

@ -106,6 +106,11 @@ public class DatabaseModule {
try {
database.execSQL("ALTER TABLE nostros_relays ADD COLUMN active BOOLEAN DEFAULT TRUE;");
} catch (SQLException e) { }
try {
database.execSQL("CREATE INDEX nostros_direct_messages_created_at_index ON nostros_direct_messages(created_at); ");
database.execSQL("CREATE INDEX nostros_notes_user_mentioned_index ON nostros_notes(user_mentioned); ");
database.execSQL("CREATE INDEX nostros_notes_created_at_index ON nostros_notes(created_at); ");
} catch (SQLException e) { }
}
public void saveEvent(JSONObject data, String userPubKey) throws JSONException {

View File

@ -51,10 +51,11 @@ export const getMentionNotes: (
nostros_notes.*, nostros_users.nip05, nostros_users.valid_nip05, nostros_users.lnurl, nostros_users.name, nostros_users.picture, nostros_users.contact, nostros_users.created_at as user_created_at FROM nostros_notes
LEFT JOIN
nostros_users ON nostros_users.id = nostros_notes.pubkey
WHERE (nostros_notes.reply_event_id IN (
WHERE
nostros_notes.pubkey != '${pubKey}'
AND (nostros_notes.reply_event_id IN (
SELECT nostros_notes.id FROM nostros_notes WHERE pubkey = '${pubKey}'
) OR nostros_notes.user_mentioned = 1)
AND nostros_notes.pubkey != '${pubKey}'
ORDER BY created_at DESC
LIMIT ${limit}
`

View File

@ -7230,11 +7230,6 @@ react-native-codegen@^0.70.6:
jscodeshift "^0.13.1"
nullthrows "^1.1.1"
react-native-device-info@^10.3.0:
version "10.3.0"
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.3.0.tgz#6bab64d84d3415dd00cc446c73ec5e2e61fddbe7"
integrity sha512-/ziZN1sA1REbJTv5mQZ4tXggcTvSbct+u5kCaze8BmN//lbxcTvWsU6NQd4IihLt89VkbX+14IGc9sVApSxd/w==
react-native-gesture-handler@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.8.0.tgz#ef9857871c10663c95a51546225b6e00cd4740cf"