mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 09:44:07 +00:00
Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7412daf373 | |||
| 2ce240279f |
5 changed files with 62 additions and 7 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
- Hotfix: Fixed an infinite loop involving delivery receipts
|
||||||
|
|
||||||
## 0.5.1
|
## 0.5.1
|
||||||
|
|
||||||
- Improve: Show delivery and read receipt indicators for text messages
|
- Improve: Show delivery and read receipt indicators for text messages
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,25 @@ class ReceiptsDao extends DatabaseAccessor<TwonlyDB> with _$ReceiptsDaoMixin {
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Claims a new delivery-receipt attempt after [cooldown] has elapsed.
|
||||||
|
///
|
||||||
|
/// Updating the timestamp before sending prevents repeated server batches from
|
||||||
|
/// starting multiple delivery-receipt attempts during the same cooldown.
|
||||||
|
Future<bool> claimDuplicateReceiptResend(
|
||||||
|
String receiptId,
|
||||||
|
Duration cooldown,
|
||||||
|
) async {
|
||||||
|
final now = clock.now();
|
||||||
|
final updated =
|
||||||
|
await (update(receivedReceipts)..where(
|
||||||
|
(t) =>
|
||||||
|
t.receiptId.equals(receiptId) &
|
||||||
|
t.createdAt.isSmallerOrEqualValue(now.subtract(cooldown)),
|
||||||
|
))
|
||||||
|
.write(ReceivedReceiptsCompanion(createdAt: Value(now)));
|
||||||
|
return updated > 0;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> gotReceipt(String receiptId) async {
|
Future<void> gotReceipt(String receiptId) async {
|
||||||
await into(
|
await into(
|
||||||
receivedReceipts,
|
receivedReceipts,
|
||||||
|
|
|
||||||
|
|
@ -299,9 +299,17 @@ class ApiService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> sendResponse(ClientToServer response) async {
|
Future<bool> sendResponse(ClientToServer response) async {
|
||||||
if (_channel != null) {
|
final channel = _channel;
|
||||||
_channel!.sink.add(response.writeToBuffer());
|
if (channel == null || channel.closeCode != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
channel.sink.add(response.writeToBuffer());
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
Log.warn('Could not send response to server: $e');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,16 @@ Future<void> handleServerMessage(server.ServerToClient msg) async {
|
||||||
..seq = msg.v0.seq
|
..seq = msg.v0.seq
|
||||||
..response = response;
|
..response = response;
|
||||||
|
|
||||||
await apiService.sendResponse(ClientToServer()..v0 = v0);
|
final responseSent = await apiService.sendResponse(ClientToServer()..v0 = v0);
|
||||||
|
if (responseSent) {
|
||||||
|
Log.info(
|
||||||
|
'Successfully queued response for server message ${msg.v0.seq}.',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Log.warn('Could not send response for server message ${msg.v0.seq}.');
|
||||||
|
}
|
||||||
AppState.gotMessageFromServer = true;
|
AppState.gotMessageFromServer = true;
|
||||||
Log.info('All messages from the server proccessed.');
|
Log.info('All messages from the server processed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime lastPushKeyRequest = clock.now().subtract(const Duration(hours: 1));
|
DateTime lastPushKeyRequest = clock.now().subtract(const Duration(hours: 1));
|
||||||
|
|
@ -141,8 +148,25 @@ Future<void> _handleClient2ClientMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
||||||
|
if (message.type == Message_Type.SENDER_DELIVERY_RECEIPT) {
|
||||||
Log.info(
|
Log.info(
|
||||||
'[$receiptId] Message is a duplicate. Sending delivery receipt again.',
|
'[$receiptId] Delivery receipt is a duplicate. Skipping receipt response.',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const duplicateReceiptCooldown = Duration(days: 10);
|
||||||
|
final shouldResend = await twonlyDB.receiptsDao.claimDuplicateReceiptResend(
|
||||||
|
receiptId,
|
||||||
|
duplicateReceiptCooldown,
|
||||||
|
);
|
||||||
|
if (!shouldResend) {
|
||||||
|
Log.info(
|
||||||
|
'[$receiptId] Message is a duplicate. Skipping delivery receipt during cooldown.',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.info(
|
||||||
|
'[$receiptId] Message is a duplicate and cooldown elapsed. Sending delivery receipt again.',
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
final response = Message(type: Message_Type.SENDER_DELIVERY_RECEIPT);
|
final response = Message(type: Message_Type.SENDER_DELIVERY_RECEIPT);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec
|
||||||
|
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.5.1+171
|
version: 0.5.2+172
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.11.0
|
sdk: ^3.11.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue