fixing the problem

This commit is contained in:
otsmr 2025-06-23 22:57:58 +02:00
parent b2426a9ec5
commit 79caf95afe
5 changed files with 40 additions and 7 deletions

View file

@ -45,7 +45,7 @@ class MessageRetransmissionDao extends DatabaseAccessor<TwonlyDatabase>
.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<TwonlyDatabase>
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),

View file

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

View file

@ -131,7 +131,8 @@ Future<client.Response> 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();
}

View file

@ -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()

View file

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