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

View file

@ -10,7 +10,10 @@ Future<void> handleReaction(
EncryptedContent_Reaction reaction,
String receiptId,
) 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(
fromUserId,
reaction.targetMessageId,

View file

@ -350,7 +350,9 @@ Future<void> insertAndSendAskAboutUserMessage(
) async {
final directChat = await twonlyDB.groupsDao.createOrGetDirectChat(contactId);
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;
}
@ -483,6 +485,17 @@ Future<(Uint8List, Uint8List?)?> sendCipherText(
);
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(
receipt: receipt,
onlyReturnEncryptedData: onlyReturnEncryptedData,
@ -568,3 +581,21 @@ Future<void> sendContactMyProfileData(int contactId) async {
);
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?
return;
} else {
await androidVolumeDownSub?.cancel();
androidVolumeDownSub = FlutterAndroidVolumeKeydown.stream.listen((
event,
) {
@ -233,6 +234,7 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
}
if (Platform.isAndroid) {
await androidVolumeDownSub?.cancel();
androidVolumeDownSub = null;
}
}

View file

@ -24,15 +24,15 @@ enum MessageSendState {
MessageSendState messageSendStateFromMessage(Message msg) {
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...
if (msg.ackByServer == null) {
return MessageSendState.sending;
}
if (msg.openedAt != null) {
return MessageSendState.sendOpened;
} else {
return MessageSendState.send;
}
return MessageSendState.send;
}
// message received

View file

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