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
- 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

View file

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

View file

@ -79,14 +79,19 @@ Future<void> 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<void> handleClient2ClientMessage(NewMessage newMessage) async {
if (message.hasEncryptedContent()) {
Value<String>? receiptIdDB;
final encryptedContentRaw =
Uint8List.fromList(message.encryptedContent);
final encryptedContentRaw = Uint8List.fromList(
message.encryptedContent,
);
Message? response;
@ -155,8 +161,10 @@ Future<void> 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);