diff --git a/android/app/build.gradle b/android/app/build.gradle index 8dd6e45..c11ef42 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -33,7 +33,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId = "eu.twonly.testing" + applicationId = "eu.twonly" multiDexEnabled true // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. diff --git a/lib/src/services/api/messages.dart b/lib/src/services/api/messages.dart index 3fefdd9..13539df 100644 --- a/lib/src/services/api/messages.dart +++ b/lib/src/services/api/messages.dart @@ -40,6 +40,20 @@ Future sendRetransmitMessage(int retransId) async { return; } + MessageJson json = MessageJson.fromJson( + jsonDecode( + utf8.decode( + gzip.decode(retrans.plaintextContent), + ), + ), + ); + Log.info("Retransmitting: ${json.kind} to ${retrans.contactId}"); + // if (json.kind + // .contains(MessageKind.pushKey.name)) { + // await twonlyDB.messageRetransmissionDao.deleteRetransmissionById(retransId); + // return; + // } + Contact? contact = await twonlyDB.contactsDao .getContactByUserId(retrans.contactId) .getSingleOrNull(); diff --git a/lib/src/services/api/server_messages.dart b/lib/src/services/api/server_messages.dart index c547c19..726d199 100644 --- a/lib/src/services/api/server_messages.dart +++ b/lib/src/services/api/server_messages.dart @@ -80,9 +80,11 @@ Future handleNewMessage(int fromUserId, Uint8List body) async { return client.Response()..ok = ok; } - Log.info("Got: ${message.kind}"); + Log.info("Got: ${message.kind} from $fromUserId"); - if (message.kind != MessageKind.ack && message.retransId != null) { + if (message.kind != MessageKind.ack && + message.kind != MessageKind.pushKey && + message.retransId != null) { Log.info("Sending ACK for ${message.kind}"); /// ACK every message diff --git a/lib/src/services/notifications/pushkeys.notifications.dart b/lib/src/services/notifications/pushkeys.notifications.dart index 4ae9a5f..489d090 100644 --- a/lib/src/services/notifications/pushkeys.notifications.dart +++ b/lib/src/services/notifications/pushkeys.notifications.dart @@ -20,6 +20,20 @@ import 'package:twonly/src/utils/log.dart'; Future setupNotificationWithUsers({bool force = false}) async { var pushUsers = await getPushKeys(SecureStorageKeys.receivingPushKeys); + // HotFIX: Search for user with id 0 if not there remove all + // and create new push keys with all users. + PushUser? pushUser = pushUsers.firstWhereOrNull((x) => x.userId == 0); + if (pushUser == null) { + Log.info("Clearing push keys"); + await setPushKeys(SecureStorageKeys.receivingPushKeys, []); + pushUsers = await getPushKeys(SecureStorageKeys.receivingPushKeys); + pushUsers.add(PushUser( + userId: Int64(0), + displayName: "NoUser", + pushKeys: [], + )); + } + var wasChanged = false; final random = Random.secure(); @@ -49,8 +63,12 @@ Future setupNotificationWithUsers({bool force = false}) async { pushUser.pushKeys.add(lastKey); pushUser.pushKeys.add(pushKey); wasChanged = true; + Log.info("Creating new pushkey for ${contact.userId}"); } } else { + Log.info( + "User ${contact.userId} not yet in pushkeys. Creating a new user.", + ); wasChanged = true; /// Insert a new push user @@ -61,6 +79,7 @@ Future setupNotificationWithUsers({bool force = false}) async { ); await sendNewPushKey(contact.userId, pushKey); pushUsers.add(PushUser( + userId: Int64(contact.userId), displayName: getContactDisplayName(contact), blocked: contact.blocked, pushKeys: [pushKey], @@ -88,6 +107,7 @@ Future sendNewPushKey(int userId, PushKey pushKey) async { pushKey.createdAtUnixTimestamp.toInt(), ), ), + willNotGetACKByUser: true, // hot fix, this can be removed later... ); } @@ -99,6 +119,7 @@ Future updatePushUser(Contact contact) async { if (pushUser == null) { pushKeys.add(PushUser( + userId: Int64(contact.userId), displayName: getContactDisplayName(contact), pushKeys: [], blocked: contact.blocked, diff --git a/lib/src/services/signal/prekeys.signal.dart b/lib/src/services/signal/prekeys.signal.dart index 97ee205..7bfdaec 100644 --- a/lib/src/services/signal/prekeys.signal.dart +++ b/lib/src/services/signal/prekeys.signal.dart @@ -26,9 +26,9 @@ DateTime lastSignedPreKeyRequest = DateTime.now().subtract(Duration(hours: 1)); Future requestNewPrekeysForContact(int contactId) async { if (lastPreKeyRequest .isAfter(DateTime.now().subtract(Duration(seconds: 60)))) { - Log.info("last pre request was 60s before"); return; } + Log.info("Requesting new PREKEYS for $contactId"); lastPreKeyRequest = DateTime.now(); requestNewKeys.protect(() async { final otherKeys = await apiService.getPreKeysByUserId(contactId); @@ -54,7 +54,6 @@ Future requestNewPrekeysForContact(int contactId) async { Future getPreKeyByContactId(int contactId) async { int count = await twonlyDB.signalDao.countPreKeysByContactId(contactId); if (count < 10) { - Log.info("Requesting new prekeys: $count < 10"); requestNewPrekeysForContact(contactId); } return twonlyDB.signalDao.popPreKeyByContactId(contactId); diff --git a/pubspec.yaml b/pubspec.yaml index f44f60a..4ef6204 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 0.0.37+37 +version: 0.0.40+40 environment: sdk: ^3.6.0