diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d5cdb..d84b081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Improve: Improved troubleshooting for issues with push notifications - Fix: Flash not activated when starting a video recording - Fix: Problem sending media when a recipient has deleted their account. +- Fix: Incorrect processing of messages that have already been fetched from the server causes the UI to freeze ## 0.1.1 diff --git a/lib/src/services/api.service.dart b/lib/src/services/api.service.dart index cac8dd2..f54ace1 100644 --- a/lib/src/services/api.service.dart +++ b/lib/src/services/api.service.dart @@ -137,7 +137,10 @@ class ApiService { reconnectionTimer = Timer(Duration(seconds: _reconnectionDelay), () async { Log.info('Reconnection timer triggered'); reconnectionTimer = null; - await connect(); + // only try to reconnect in case the app is in the foreground + if (!globalIsAppInBackground) { + await connect(); + } }); _reconnectionDelay = 3; } diff --git a/lib/src/services/api/server_messages.dart b/lib/src/services/api/server_messages.dart index 69b767a..75c7f7a 100644 --- a/lib/src/services/api/server_messages.dart +++ b/lib/src/services/api/server_messages.dart @@ -79,14 +79,19 @@ Future handleClient2ClientMessage(NewMessage newMessage) async { final message = Message.fromBuffer(body); final receiptId = message.receiptId; - await protectReceiptCheck.protect(() async { + final isDuplicated = await protectReceiptCheck.protect(() async { if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) { Log.warn('Got duplicated message from the server.'); - return; + return true; } await twonlyDB.receiptsDao.gotReceipt(receiptId); + return false; }); + if (isDuplicated) { + return; + } + switch (message.type) { case Message_Type.SENDER_DELIVERY_RECEIPT: Log.info('Got delivery receipt for $receiptId!'); @@ -131,8 +136,9 @@ Future handleClient2ClientMessage(NewMessage newMessage) async { if (message.hasEncryptedContent()) { Value? receiptIdDB; - final encryptedContentRaw = - Uint8List.fromList(message.encryptedContent); + final encryptedContentRaw = Uint8List.fromList( + message.encryptedContent, + ); Message? response; @@ -155,8 +161,10 @@ Future handleClient2ClientMessage(NewMessage newMessage) async { } if (response == null) { - final (encryptedContent, plainTextContent) = - await handleEncryptedMessage( + final ( + encryptedContent, + plainTextContent, + ) = await handleEncryptedMessage( fromUserId, encryptedContentRaw, message.type, @@ -215,7 +223,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage( null, PlaintextContent() ..decryptionErrorMessage = (PlaintextContent_DecryptionErrorMessage() - ..type = decryptionErrorType!) + ..type = decryptionErrorType!), ); } @@ -235,7 +243,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage( return ( null, PlaintextContent() - ..retryControlError = PlaintextContent_RetryErrorMessage() + ..retryControlError = PlaintextContent_RetryErrorMessage(), ); } return (null, null); @@ -312,7 +320,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage( relatedReceiptId: receiptId, ), ), - null + null, ); } Log.info( @@ -333,7 +341,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage( return ( null, PlaintextContent() - ..retryControlError = PlaintextContent_RetryErrorMessage() + ..retryControlError = PlaintextContent_RetryErrorMessage(), ); } @@ -365,7 +373,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage( return ( null, PlaintextContent() - ..retryControlError = PlaintextContent_RetryErrorMessage() + ..retryControlError = PlaintextContent_RetryErrorMessage(), ); } return (null, null);