delete faulty messages

This commit is contained in:
otsmr 2025-06-23 21:01:40 +02:00
parent 5e7567416f
commit b2426a9ec5
4 changed files with 18 additions and 5 deletions

View file

@ -45,7 +45,15 @@ class MessageRetransmissionDao extends DatabaseAccessor<TwonlyDatabase>
.write(updatedValues);
}
Future resetAckStatusForAllMessages() {
Future resetAckStatusForAllMessages() async {
final deletedCount = await (delete(messageRetransmissions)
..where((m) =>
m.willNotGetACKByUser.equals(true) &
m.acknowledgeByServerAt.isNotNull()))
.go();
if (deletedCount > 0) {
Log.info('$deletedCount faulty retransmission messages where deleted.');
}
return ((update(messageRetransmissions))
..where((m) => m.willNotGetACKByUser.equals(false)))
.write(

View file

@ -222,7 +222,7 @@ Future<client.Response> handleNewMessage(int fromUserId, Uint8List body) async {
if (lastPushKeyRequest
.isBefore(DateTime.now().subtract(Duration(seconds: 60)))) {
lastPushKeyRequest = DateTime.now();
setupNotificationWithUsers(force: true);
setupNotificationWithUsers(forceContact: fromUserId);
}
case MessageKind.pushKey:

View file

@ -17,7 +17,8 @@ import 'package:twonly/src/services/api/messages.dart';
import 'package:twonly/src/utils/log.dart';
/// This function must be called after the database is setup
Future setupNotificationWithUsers({bool force = false}) async {
Future setupNotificationWithUsers(
{bool force = false, int? forceContact}) async {
var pushUsers = await getPushKeys(SecureStorageKeys.receivingPushKeys);
// HotFIX: Search for user with id 0 if not there remove all
@ -51,7 +52,9 @@ Future setupNotificationWithUsers({bool force = false}) async {
final createdAt = DateTime.fromMillisecondsSinceEpoch(
lastKey.createdAtUnixTimestamp.toInt());
if (force || createdAt.isBefore(timeBefore)) {
if (force ||
(forceContact == contact.userId) ||
createdAt.isBefore(timeBefore)) {
final pushKey = PushKey(
id: lastKey.id + random.nextInt(5),
key: List<int>.generate(32, (index) => random.nextInt(256)),

View file

@ -95,7 +95,9 @@ class _SearchUsernameView extends State<AddNewUserView> {
if (added > 0) {
if (await createNewSignalSession(res.value.userdata)) {
// before notifying the other party, add
await setupNotificationWithUsers();
await setupNotificationWithUsers(
forceContact: res.value.userdata.userId.toInt(),
);
await encryptAndSendMessageAsync(
null,
res.value.userdata.userId.toInt(),