From 04680e085596a5fd0db3d10ba607a1476faf9b02 Mon Sep 17 00:00:00 2001 From: otsmr Date: Tue, 7 Jul 2026 21:41:50 +0200 Subject: [PATCH] fix smaller issues --- lib/src/database/daos/messages.dao.dart | 97 ++++++++++--------- .../mediafiles/thumbnail.service.dart | 2 +- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/lib/src/database/daos/messages.dao.dart b/lib/src/database/daos/messages.dao.dart index fdf8b0b8..697efc7c 100644 --- a/lib/src/database/daos/messages.dao.dart +++ b/lib/src/database/daos/messages.dao.dart @@ -263,26 +263,28 @@ class MessagesDao extends DatabaseAccessor with _$MessagesDaoMixin { String text, DateTime timestamp, ) async { - final msg = await getMessageById(messageId).getSingleOrNull(); - if (msg == null || msg.content == null || msg.senderId != contactId) { - return; - } - await into(messageHistories).insert( - MessageHistoriesCompanion( - messageId: Value(messageId), - content: Value(msg.content), - createdAt: Value(timestamp), - ), - ); - await (update(messages)..where( - (t) => t.messageId.equals(messageId), - )) - .write( - MessagesCompanion( - content: Value(text), - modifiedAt: Value(timestamp), - ), - ); + await transaction(() async { + final msg = await getMessageById(messageId).getSingleOrNull(); + if (msg == null || msg.content == null || msg.senderId != contactId) { + return; + } + await into(messageHistories).insert( + MessageHistoriesCompanion( + messageId: Value(messageId), + content: Value(msg.content), + createdAt: Value(timestamp), + ), + ); + await (update(messages)..where( + (t) => t.messageId.equals(messageId), + )) + .write( + MessagesCompanion( + content: Value(text), + modifiedAt: Value(timestamp), + ), + ); + }); } Future handleMessagesOpened( @@ -291,7 +293,9 @@ class MessagesDao extends DatabaseAccessor with _$MessagesDaoMixin { DateTime timestamp, ) async { if (contactId.present) { - final contactExists = await twonlyDB.contactsDao.getContactById(contactId.value); + final contactExists = await twonlyDB.contactsDao.getContactById( + contactId.value, + ); if (contactExists == null) { Log.info( 'handleMessagesOpened: Contact ${contactId.value} does not exist in database, ignoring messages opened action.', @@ -301,25 +305,24 @@ class MessagesDao extends DatabaseAccessor with _$MessagesDaoMixin { } for (final messageId in messageIds) { try { - var actionTimestamp = timestamp; - final msg = await getMessageById(messageId).getSingleOrNull(); - if (msg == null) { - Log.info( - 'handleMessagesOpened: Message $messageId does not exist in database, skipping.', - ); - continue; - } - if (actionTimestamp.isBefore(msg.createdAt)) { - Log.warn( - 'Receiver clock skew detected for message $messageId. ' - 'Action timestamp $actionTimestamp is before message creation ${msg.createdAt}. ' - 'Clamping to creation time.', - ); - actionTimestamp = msg.createdAt; - } - - final ts = actionTimestamp; await transaction(() async { + final msg = await getMessageById(messageId).getSingleOrNull(); + if (msg == null) { + Log.info( + 'handleMessagesOpened: Message $messageId does not exist in database, skipping.', + ); + return; + } + var ts = timestamp; + if (ts.isBefore(msg.createdAt)) { + Log.warn( + 'Receiver clock skew detected for message $messageId. ' + 'Action timestamp $ts is before message creation ${msg.createdAt}. ' + 'Clamping to creation time.', + ); + ts = msg.createdAt; + } + await into(messageActions).insertOnConflictUpdate( MessageActionsCompanion( messageId: Value(messageId), @@ -353,7 +356,7 @@ class MessagesDao extends DatabaseAccessor with _$MessagesDaoMixin { messages, )..where((tbl) => tbl.messageId.equals(messageId))).write( MessagesCompanion( - openedAt: Value(actionTimestamp), + openedAt: Value(timestamp), ), ); } @@ -383,14 +386,14 @@ class MessagesDao extends DatabaseAccessor with _$MessagesDaoMixin { ); return; } - final msg = await getMessageById(messageId).getSingleOrNull(); - if (msg == null) { - Log.info( - 'handleMessageAckByServer: Message $messageId does not exist in database, skipping.', - ); - return; - } await transaction(() async { + final msg = await getMessageById(messageId).getSingleOrNull(); + if (msg == null) { + Log.info( + 'handleMessageAckByServer: Message $messageId does not exist in database, skipping.', + ); + return; + } await into(messageActions).insertOnConflictUpdate( MessageActionsCompanion( messageId: Value(messageId), diff --git a/lib/src/services/mediafiles/thumbnail.service.dart b/lib/src/services/mediafiles/thumbnail.service.dart index 35fd86a6..ef733657 100644 --- a/lib/src/services/mediafiles/thumbnail.service.dart +++ b/lib/src/services/mediafiles/thumbnail.service.dart @@ -112,7 +112,7 @@ Future createThumbnailsForImage( ); return true; } else { - Log.error('Compressed image thumbnail is empty or missing.'); + Log.warn('Compressed image thumbnail is empty or missing.'); try { if (destinationFile.existsSync()) { destinationFile.deleteSync();