diff --git a/android/app/build.gradle b/android/app/build.gradle index 3dd8482..23c5f38 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -252,7 +252,7 @@ dependencies { implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" - implementation 'org.java-websocket:Java-WebSocket:1.5.3' + implementation 'com.neovisionaries:nv-websocket-client:2.14' implementation 'com.facebook.fresco:animated-webp:2.6.0' implementation 'com.facebook.fresco:webpsupport:2.6.0' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 0deb2f7..907e7fe 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -23,7 +23,7 @@ - + diff --git a/android/app/src/main/java/com/nostros/classes/Relay.java b/android/app/src/main/java/com/nostros/classes/Relay.java index 17db2d6..1b0e63b 100644 --- a/android/app/src/main/java/com/nostros/classes/Relay.java +++ b/android/app/src/main/java/com/nostros/classes/Relay.java @@ -9,7 +9,6 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.nostros.modules.DatabaseModule; import java.io.IOException; -import java.net.URISyntaxException; public class Relay { private Websocket webSocket; @@ -39,11 +38,7 @@ public class Relay { } public void connect(String userPubKey) throws IOException { - try { - webSocket.connect(userPubKey); - } catch (URISyntaxException e) { - e.printStackTrace(); - } + webSocket.connect(userPubKey); } public void save(SQLiteDatabase database) { diff --git a/android/app/src/main/java/com/nostros/classes/Websocket.java b/android/app/src/main/java/com/nostros/classes/Websocket.java index 466915c..31bb01c 100644 --- a/android/app/src/main/java/com/nostros/classes/Websocket.java +++ b/android/app/src/main/java/com/nostros/classes/Websocket.java @@ -6,22 +6,19 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketAdapter; +import com.neovisionaries.ws.client.WebSocketFactory; +import com.neovisionaries.ws.client.WebSocketFrame; 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; -import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; public class Websocket { - private WebSocketClient webSocket; + private WebSocket webSocket; private DatabaseModule database; private String url; private String pubKey; @@ -36,58 +33,51 @@ public class Websocket { public void send(String message) { if (webSocket != null) { Log.d("Websocket", "SEND URL:" + url + " __ " + message); - try { - webSocket.send(message); - } catch (WebsocketNotConnectedException e) { - + if (!webSocket.isOpen()) { + try { + this.connect(pubKey); + } catch (IOException e) { + e.printStackTrace(); + } } + webSocket.sendText(message); } } public void disconnect() { if (webSocket != null) { - webSocket.close(); + webSocket.disconnect(); } } - public void connect(String userPubKey) throws IOException, URISyntaxException { + public void connect(String userPubKey) throws IOException { + WebSocketFactory factory = new WebSocketFactory(); pubKey = userPubKey; - webSocket = new WebSocketClient(new URI(url)) { - @Override - public void onOpen(ServerHandshake handshakedata) { - - } + webSocket = factory.createSocket(url); + webSocket.setMissingCloseFrameAllowed(true); + webSocket.setPingInterval(25 * 1000); + webSocket.addListener(new WebSocketAdapter() { @Override - public void onMessage(String message) { + public void onTextMessage(WebSocket websocket, String message) throws Exception { 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(); + JSONArray 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()); } } - @Override - public void onClose(int code, String reason, boolean remote) { - webSocket.connect(); + public void onDisconnected(WebSocket ws, WebSocketFrame serverCloseFrame, + WebSocketFrame clientCloseFrame, boolean closedByServer) { + ws.connectAsynchronously(); } - - @Override - public void onError(Exception ex) { - ex.printStackTrace(); - } - }; - webSocket.connect(); + }); + webSocket.connectAsynchronously(); } public void reactNativeEvent(String eventId) { diff --git a/android/app/src/main/java/com/nostros/modules/DatabaseModule.java b/android/app/src/main/java/com/nostros/modules/DatabaseModule.java index 1d5d103..26028af 100644 --- a/android/app/src/main/java/com/nostros/modules/DatabaseModule.java +++ b/android/app/src/main/java/com/nostros/modules/DatabaseModule.java @@ -106,11 +106,6 @@ 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 { diff --git a/frontend/Functions/DatabaseFunctions/Notes/index.ts b/frontend/Functions/DatabaseFunctions/Notes/index.ts index 0de863f..df53b17 100644 --- a/frontend/Functions/DatabaseFunctions/Notes/index.ts +++ b/frontend/Functions/DatabaseFunctions/Notes/index.ts @@ -51,11 +51,10 @@ 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.pubkey != '${pubKey}' - AND (nostros_notes.reply_event_id IN ( + WHERE (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} ` diff --git a/yarn.lock b/yarn.lock index 17dda1d..d0af661 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7230,6 +7230,11 @@ 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"