diff --git a/lib/src/database/daos/message_retransmissions.dao.dart b/lib/src/database/daos/message_retransmissions.dao.dart index caf61c8..d154350 100644 --- a/lib/src/database/daos/message_retransmissions.dao.dart +++ b/lib/src/database/daos/message_retransmissions.dao.dart @@ -45,7 +45,7 @@ class MessageRetransmissionDao extends DatabaseAccessor .write(updatedValues); } - Future resetAckStatusForAllMessages() async { + Future resetAckStatusForAllMessages(int fromUserId) async { final deletedCount = await (delete(messageRetransmissions) ..where((m) => m.willNotGetACKByUser.equals(true) & @@ -55,7 +55,9 @@ class MessageRetransmissionDao extends DatabaseAccessor Log.info('$deletedCount faulty retransmission messages where deleted.'); } return ((update(messageRetransmissions)) - ..where((m) => m.willNotGetACKByUser.equals(false))) + ..where((m) => + m.willNotGetACKByUser.equals(false) & + m.contactId.equals(fromUserId))) .write( MessageRetransmissionsCompanion( acknowledgeByServerAt: Value(null), diff --git a/lib/src/services/api/messages.dart b/lib/src/services/api/messages.dart index 13539df..0efeeb8 100644 --- a/lib/src/services/api/messages.dart +++ b/lib/src/services/api/messages.dart @@ -24,13 +24,20 @@ Future tryTransmitMessages() async { if (retransIds.isEmpty) return; + bool filterPreKeys = false; + + if (retransIds.length > 100) { + filterPreKeys = true; // just a workaround until I can fix the real issue :/ + } + for (final retransId in retransIds) { - sendRetransmitMessage(retransId); + sendRetransmitMessage(retransId, filterPreKeys: filterPreKeys); //twonlyDB.messageRetransmissionDao.deleteRetransmissionById(retransId); } } -Future sendRetransmitMessage(int retransId) async { +Future sendRetransmitMessage(int retransId, + {bool filterPreKeys = false}) async { MessageRetransmission? retrans = await twonlyDB.messageRetransmissionDao .getRetransmissionById(retransId) .getSingleOrNull(); @@ -47,6 +54,14 @@ Future sendRetransmitMessage(int retransId) async { ), ), ); + if (filterPreKeys && json.kind == MessageKind.pushKey) { + if (!retrans.willNotGetACKByUser) { + Log.error("Why is willNotGetACKByUser false????"); + } + Log.info("Filtering preKeys: ${json.kind} to ${retrans.contactId}"); + await twonlyDB.messageRetransmissionDao.deleteRetransmissionById(retransId); + return; + } Log.info("Retransmitting: ${json.kind} to ${retrans.contactId}"); // if (json.kind // .contains(MessageKind.pushKey.name)) { @@ -87,6 +102,7 @@ Future sendRetransmitMessage(int retransId) async { bool retry = true; if (resp.isError) { + Log.error("Could not retransmit message."); if (resp.error == ErrorCode.UserIdNotFound) { retry = false; if (retrans.messageId != null) { @@ -116,7 +132,12 @@ Future sendRetransmitMessage(int retransId) async { } if (!retry) { - if (retrans.willNotGetACKByUser) { + if (!retrans.willNotGetACKByUser && json.kind == MessageKind.pushKey) { + Log.error("Why is willNotGetACKByUser false????"); + } + if (retrans.willNotGetACKByUser || + json.kind == MessageKind.pushKey || + json.kind == MessageKind.ack) { await twonlyDB.messageRetransmissionDao .deleteRetransmissionById(retransId); } else { diff --git a/lib/src/services/api/server_messages.dart b/lib/src/services/api/server_messages.dart index c2668a2..cea2b7f 100644 --- a/lib/src/services/api/server_messages.dart +++ b/lib/src/services/api/server_messages.dart @@ -131,7 +131,8 @@ Future handleNewMessage(int fromUserId, Uint8List body) async { lastSignalDecryptMessage = DateTime.now(); await twonlyDB.signalDao.deleteAllPreKeysByContactId(fromUserId); await requestNewPrekeysForContact(fromUserId); - await twonlyDB.messageRetransmissionDao.resetAckStatusForAllMessages(); + await twonlyDB.messageRetransmissionDao + .resetAckStatusForAllMessages(fromUserId); tryTransmitMessages(); } diff --git a/lib/src/views/settings/notification.view.dart b/lib/src/views/settings/notification.view.dart index 6e64537..e8c2a87 100644 --- a/lib/src/views/settings/notification.view.dart +++ b/lib/src/views/settings/notification.view.dart @@ -1,12 +1,14 @@ import 'dart:io'; import 'package:fixnum/fixnum.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:twonly/globals.dart'; import 'package:twonly/src/constants/secure_storage_keys.dart'; import 'package:twonly/src/model/protobuf/push_notification/push_notification.pbserver.dart'; +import 'package:twonly/src/services/api/messages.dart'; import 'package:twonly/src/services/notifications/pushkeys.notifications.dart'; import 'package:twonly/src/views/components/alert_dialog.dart'; import 'package:twonly/src/services/fcm.service.dart'; @@ -27,6 +29,13 @@ class NotificationView extends StatelessWidget { ListTile( title: Text(context.lang.settingsNotifyTroubleshooting), subtitle: Text(context.lang.settingsNotifyTroubleshootingDesc), + onLongPress: (kDebugMode) + ? () async { + await twonlyDB.messageRetransmissionDao + .resetAckStatusForAllMessages(537506372); + tryTransmitMessages(); + } + : null, onTap: () async { await initFCMAfterAuthenticated(); String? storedToken = await FlutterSecureStorage() diff --git a/pubspec.yaml b/pubspec.yaml index 4ef6204..7e65bc4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 0.0.40+40 +version: 0.0.43+43 environment: sdk: ^3.6.0