improve logging
Some checks failed
Flutter analyze & test / flutter_analyze_and_test (push) Has been cancelled

This commit is contained in:
otsmr 2026-05-26 11:57:59 +02:00
parent 789bcda34f
commit c7826ad6dd
7 changed files with 77 additions and 34 deletions

View file

@ -253,23 +253,19 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
List<String> messageIds, List<String> messageIds,
DateTime timestamp, DateTime timestamp,
) async { ) async {
try { for (final messageId in messageIds) {
await twonlyDB.batch((batch) async { try {
for (final messageId in messageIds) { await into(messageActions).insertOnConflictUpdate(
batch.insert( MessageActionsCompanion(
messageActions, messageId: Value(messageId),
MessageActionsCompanion( contactId: contactId,
messageId: Value(messageId), type: const Value(MessageActionType.openedAt),
contactId: contactId, actionAt: Value(timestamp),
type: const Value(MessageActionType.openedAt), ),
actionAt: Value(timestamp), );
), } catch (e) {
mode: InsertMode.insertOrReplace, Log.error('handleMessagesOpened insert failed for $messageId: $e');
); }
}
});
} catch (e) {
Log.error(e);
} }
for (final messageId in messageIds) { for (final messageId in messageIds) {
@ -278,16 +274,20 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
messageId, messageId,
MessageActionType.openedAt, MessageActionType.openedAt,
); );
await (update( final rowsUpdated =
messages, await (update(
)..where((tbl) => tbl.messageId.equals(messageId))).write( messages,
MessagesCompanion( )..where((tbl) => tbl.messageId.equals(messageId))).write(
openedAt: Value(timestamp), MessagesCompanion(
openedByAll: Value(isOpenedByAll ? timestamp : null), openedAt: Value(timestamp),
), openedByAll: Value(isOpenedByAll ? timestamp : null),
),
);
Log.info(
'handleMessagesOpened updated $rowsUpdated rows for message $messageId',
); );
} catch (e) { } catch (e) {
Log.error(e); Log.error('handleMessagesOpened update failed: $e');
} }
} }
} }

View file

@ -29,7 +29,14 @@ class ReactionsDao extends DatabaseAccessor<TwonlyDB> with _$ReactionsDaoMixin {
final msg = await twonlyDB.messagesDao final msg = await twonlyDB.messagesDao
.getMessageById(messageId) .getMessageById(messageId)
.getSingleOrNull(); .getSingleOrNull();
if (msg == null || msg.groupId != groupId) return; if (msg == null) {
Log.error('updateReaction: Message $messageId not found!');
return;
}
if (msg.groupId != groupId) {
Log.error('updateReaction: Message groupId ${msg.groupId} != $groupId');
return;
}
try { try {
if (remove) { if (remove) {

View file

@ -10,7 +10,10 @@ Future<void> handleReaction(
EncryptedContent_Reaction reaction, EncryptedContent_Reaction reaction,
String receiptId, String receiptId,
) async { ) async {
Log.info('[$receiptId] Got a reaction from $fromUserId (remove=${reaction.remove})'); Log.info(
'[$receiptId] Got a reaction from for ${reaction.targetMessageId} (remove=${reaction.remove})',
);
await twonlyDB.reactionsDao.updateReaction( await twonlyDB.reactionsDao.updateReaction(
fromUserId, fromUserId,
reaction.targetMessageId, reaction.targetMessageId,

View file

@ -350,7 +350,9 @@ Future<void> insertAndSendAskAboutUserMessage(
) async { ) async {
final directChat = await twonlyDB.groupsDao.createOrGetDirectChat(contactId); final directChat = await twonlyDB.groupsDao.createOrGetDirectChat(contactId);
if (directChat == null) { if (directChat == null) {
Log.error('Failed to get or create direct chat group for contact $contactId'); Log.error(
'Failed to get or create direct chat group for contact $contactId',
);
return; return;
} }
@ -483,6 +485,17 @@ Future<(Uint8List, Uint8List?)?> sendCipherText(
); );
if (receipt != null) { if (receipt != null) {
try {
final typeKeys = _getEncryptedContentTypes(encryptedContent);
Log.info(
'sendCipherText: type=[$typeKeys] messageId=$messageId receiptId=${receipt.receiptId}',
);
} catch (_) {
Log.info(
'sendCipherText: messageId=$messageId receiptId=${receipt.receiptId}',
);
}
final tmp = tryToSendCompleteMessage( final tmp = tryToSendCompleteMessage(
receipt: receipt, receipt: receipt,
onlyReturnEncryptedData: onlyReturnEncryptedData, onlyReturnEncryptedData: onlyReturnEncryptedData,
@ -568,3 +581,21 @@ Future<void> sendContactMyProfileData(int contactId) async {
); );
await sendCipherText(contactId, encryptedContent, blocking: false); await sendCipherText(contactId, encryptedContent, blocking: false);
} }
String _getEncryptedContentTypes(pb.EncryptedContent content) {
final ignoredFields = {
'groupId',
'isDirectChat',
'senderProfileCounter',
'senderUserDiscoveryVersion',
};
final types = <String>[];
for (final field in content.info_.byName.values) {
if (content.hasField(field.tagNumber) &&
!ignoredFields.contains(field.name)) {
types.add(field.name);
}
}
return types.join(', ');
}

View file

@ -212,6 +212,7 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
// Maybe this is the reason? // Maybe this is the reason?
return; return;
} else { } else {
await androidVolumeDownSub?.cancel();
androidVolumeDownSub = FlutterAndroidVolumeKeydown.stream.listen(( androidVolumeDownSub = FlutterAndroidVolumeKeydown.stream.listen((
event, event,
) { ) {
@ -233,6 +234,7 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
} }
if (Platform.isAndroid) { if (Platform.isAndroid) {
await androidVolumeDownSub?.cancel(); await androidVolumeDownSub?.cancel();
androidVolumeDownSub = null;
} }
} }

View file

@ -24,15 +24,15 @@ enum MessageSendState {
MessageSendState messageSendStateFromMessage(Message msg) { MessageSendState messageSendStateFromMessage(Message msg) {
if (msg.senderId == null) { if (msg.senderId == null) {
if (msg.openedByAll != null || msg.openedAt != null) {
return MessageSendState.sendOpened;
}
/// messages was send by me, look up if every messages was received by the server... /// messages was send by me, look up if every messages was received by the server...
if (msg.ackByServer == null) { if (msg.ackByServer == null) {
return MessageSendState.sending; return MessageSendState.sending;
} }
if (msg.openedAt != null) { return MessageSendState.send;
return MessageSendState.sendOpened;
} else {
return MessageSendState.send;
}
} }
// message received // message received

View file

@ -3,7 +3,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec
publish_to: 'none' publish_to: 'none'
version: 0.2.20+129 version: 0.2.21+130
environment: environment:
sdk: ^3.11.0 sdk: ^3.11.0