fixes duplicated messages from the server
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run

This commit is contained in:
otsmr 2026-04-05 22:17:45 +02:00
parent 2d5f004222
commit aa26766bdf
3 changed files with 24 additions and 12 deletions

View file

@ -6,6 +6,7 @@
- Improve: Improved troubleshooting for issues with push notifications - Improve: Improved troubleshooting for issues with push notifications
- Fix: Flash not activated when starting a video recording - Fix: Flash not activated when starting a video recording
- Fix: Problem sending media when a recipient has deleted their account. - 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 ## 0.1.1

View file

@ -137,7 +137,10 @@ class ApiService {
reconnectionTimer = Timer(Duration(seconds: _reconnectionDelay), () async { reconnectionTimer = Timer(Duration(seconds: _reconnectionDelay), () async {
Log.info('Reconnection timer triggered'); Log.info('Reconnection timer triggered');
reconnectionTimer = null; reconnectionTimer = null;
await connect(); // only try to reconnect in case the app is in the foreground
if (!globalIsAppInBackground) {
await connect();
}
}); });
_reconnectionDelay = 3; _reconnectionDelay = 3;
} }

View file

@ -79,14 +79,19 @@ Future<void> handleClient2ClientMessage(NewMessage newMessage) async {
final message = Message.fromBuffer(body); final message = Message.fromBuffer(body);
final receiptId = message.receiptId; final receiptId = message.receiptId;
await protectReceiptCheck.protect(() async { final isDuplicated = await protectReceiptCheck.protect(() async {
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) { if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
Log.warn('Got duplicated message from the server.'); Log.warn('Got duplicated message from the server.');
return; return true;
} }
await twonlyDB.receiptsDao.gotReceipt(receiptId); await twonlyDB.receiptsDao.gotReceipt(receiptId);
return false;
}); });
if (isDuplicated) {
return;
}
switch (message.type) { switch (message.type) {
case Message_Type.SENDER_DELIVERY_RECEIPT: case Message_Type.SENDER_DELIVERY_RECEIPT:
Log.info('Got delivery receipt for $receiptId!'); Log.info('Got delivery receipt for $receiptId!');
@ -131,8 +136,9 @@ Future<void> handleClient2ClientMessage(NewMessage newMessage) async {
if (message.hasEncryptedContent()) { if (message.hasEncryptedContent()) {
Value<String>? receiptIdDB; Value<String>? receiptIdDB;
final encryptedContentRaw = final encryptedContentRaw = Uint8List.fromList(
Uint8List.fromList(message.encryptedContent); message.encryptedContent,
);
Message? response; Message? response;
@ -155,8 +161,10 @@ Future<void> handleClient2ClientMessage(NewMessage newMessage) async {
} }
if (response == null) { if (response == null) {
final (encryptedContent, plainTextContent) = final (
await handleEncryptedMessage( encryptedContent,
plainTextContent,
) = await handleEncryptedMessage(
fromUserId, fromUserId,
encryptedContentRaw, encryptedContentRaw,
message.type, message.type,
@ -215,7 +223,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage(
null, null,
PlaintextContent() PlaintextContent()
..decryptionErrorMessage = (PlaintextContent_DecryptionErrorMessage() ..decryptionErrorMessage = (PlaintextContent_DecryptionErrorMessage()
..type = decryptionErrorType!) ..type = decryptionErrorType!),
); );
} }
@ -235,7 +243,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage(
return ( return (
null, null,
PlaintextContent() PlaintextContent()
..retryControlError = PlaintextContent_RetryErrorMessage() ..retryControlError = PlaintextContent_RetryErrorMessage(),
); );
} }
return (null, null); return (null, null);
@ -312,7 +320,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage(
relatedReceiptId: receiptId, relatedReceiptId: receiptId,
), ),
), ),
null null,
); );
} }
Log.info( Log.info(
@ -333,7 +341,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage(
return ( return (
null, null,
PlaintextContent() PlaintextContent()
..retryControlError = PlaintextContent_RetryErrorMessage() ..retryControlError = PlaintextContent_RetryErrorMessage(),
); );
} }
@ -365,7 +373,7 @@ Future<(EncryptedContent?, PlaintextContent?)> handleEncryptedMessage(
return ( return (
null, null,
PlaintextContent() PlaintextContent()
..retryControlError = PlaintextContent_RetryErrorMessage() ..retryControlError = PlaintextContent_RetryErrorMessage(),
); );
} }
return (null, null); return (null, null);