mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 08:04:07 +00:00
Fix: Sometimes old messages were being received as duplicates
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
This commit is contained in:
parent
77d057c248
commit
2a6fd61a32
4 changed files with 23 additions and 18 deletions
|
|
@ -6,7 +6,8 @@
|
||||||
- Improve: Backup screen clearer and easier to understand
|
- Improve: Backup screen clearer and easier to understand
|
||||||
- Improve: Show username above messages in group chats
|
- Improve: Show username above messages in group chats
|
||||||
- Fix: Background audio correctly pauses and resumes when viewing videos
|
- Fix: Background audio correctly pauses and resumes when viewing videos
|
||||||
- Fix: Multiple bug fixes
|
- Fix: Sometimes old messages were being received as duplicates
|
||||||
|
- Fix: Multiple smaller bug fixes
|
||||||
|
|
||||||
## 0.5.0
|
## 0.5.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class ReceiptsDao extends DatabaseAccessor<TwonlyDB> with _$ReceiptsDaoMixin {
|
||||||
await (delete(receivedReceipts)..where(
|
await (delete(receivedReceipts)..where(
|
||||||
(t) => (t.createdAt.isSmallerThanValue(
|
(t) => (t.createdAt.isSmallerThanValue(
|
||||||
clock.now().subtract(
|
clock.now().subtract(
|
||||||
const Duration(days: 25),
|
const Duration(days: 45),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -114,22 +114,6 @@ Future<(Uint8List, Uint8List?)?> _tryToSendCompleteMessageInternal({
|
||||||
// ignore: parameter_assignments
|
// ignore: parameter_assignments
|
||||||
receipt = loadedReceipt;
|
receipt = loadedReceipt;
|
||||||
|
|
||||||
if (receipt.retryCount >= 2) {
|
|
||||||
// After two retries, change the receiptId. This addresses a bug where the receiver received the message and marked it as received,
|
|
||||||
// but the app was closed before the message was fully processed. Because the receipt was already stored, subsequent retries were
|
|
||||||
// detected as duplicates and rejected.
|
|
||||||
final oldReceiptId = receipt.receiptId;
|
|
||||||
final updatedReceipt = await twonlyDB.receiptsDao.rotateReceiptId(
|
|
||||||
oldReceiptId,
|
|
||||||
);
|
|
||||||
if (updatedReceipt != null) {
|
|
||||||
Log.info(
|
|
||||||
'Changed receiptId $oldReceiptId to ${updatedReceipt.receiptId} as retryCount is ${receipt.retryCount}',
|
|
||||||
);
|
|
||||||
receipt = updatedReceipt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final contact = await twonlyDB.contactsDao.getContactById(
|
final contact = await twonlyDB.contactsDao.getContactById(
|
||||||
receipt.contactId,
|
receipt.contactId,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,26 @@ Future<void> _handleClient2ClientMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
||||||
|
Log.info(
|
||||||
|
'[$receiptId] Message is a duplicate. Sending delivery receipt again.',
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
final response = Message(type: Message_Type.SENDER_DELIVERY_RECEIPT);
|
||||||
|
await twonlyDB.receiptsDao.insertReceipt(
|
||||||
|
ReceiptsCompanion(
|
||||||
|
receiptId: Value(receiptId),
|
||||||
|
contactId: Value(fromUserId),
|
||||||
|
message: Value(response.writeToBuffer()),
|
||||||
|
contactWillSendsReceipt: const Value(false),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tryToSendCompleteMessage(
|
||||||
|
receiptId: receiptId,
|
||||||
|
blocking: false,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn('[$receiptId] Error handling duplicate receipt ACK: $e');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue