fix smaller issues

This commit is contained in:
otsmr 2026-07-07 21:41:50 +02:00
parent cec25675c3
commit 04680e0855
2 changed files with 51 additions and 48 deletions

View file

@ -263,6 +263,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
String text, String text,
DateTime timestamp, DateTime timestamp,
) async { ) async {
await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull(); final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null || msg.content == null || msg.senderId != contactId) { if (msg == null || msg.content == null || msg.senderId != contactId) {
return; return;
@ -283,6 +284,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
modifiedAt: Value(timestamp), modifiedAt: Value(timestamp),
), ),
); );
});
} }
Future<void> handleMessagesOpened( Future<void> handleMessagesOpened(
@ -291,7 +293,9 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
DateTime timestamp, DateTime timestamp,
) async { ) async {
if (contactId.present) { if (contactId.present) {
final contactExists = await twonlyDB.contactsDao.getContactById(contactId.value); final contactExists = await twonlyDB.contactsDao.getContactById(
contactId.value,
);
if (contactExists == null) { if (contactExists == null) {
Log.info( Log.info(
'handleMessagesOpened: Contact ${contactId.value} does not exist in database, ignoring messages opened action.', 'handleMessagesOpened: Contact ${contactId.value} does not exist in database, ignoring messages opened action.',
@ -301,25 +305,24 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
} }
for (final messageId in messageIds) { for (final messageId in messageIds) {
try { try {
var actionTimestamp = timestamp; await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull(); final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null) { if (msg == null) {
Log.info( Log.info(
'handleMessagesOpened: Message $messageId does not exist in database, skipping.', 'handleMessagesOpened: Message $messageId does not exist in database, skipping.',
); );
continue; return;
} }
if (actionTimestamp.isBefore(msg.createdAt)) { var ts = timestamp;
if (ts.isBefore(msg.createdAt)) {
Log.warn( Log.warn(
'Receiver clock skew detected for message $messageId. ' 'Receiver clock skew detected for message $messageId. '
'Action timestamp $actionTimestamp is before message creation ${msg.createdAt}. ' 'Action timestamp $ts is before message creation ${msg.createdAt}. '
'Clamping to creation time.', 'Clamping to creation time.',
); );
actionTimestamp = msg.createdAt; ts = msg.createdAt;
} }
final ts = actionTimestamp;
await transaction(() async {
await into(messageActions).insertOnConflictUpdate( await into(messageActions).insertOnConflictUpdate(
MessageActionsCompanion( MessageActionsCompanion(
messageId: Value(messageId), messageId: Value(messageId),
@ -353,7 +356,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
messages, messages,
)..where((tbl) => tbl.messageId.equals(messageId))).write( )..where((tbl) => tbl.messageId.equals(messageId))).write(
MessagesCompanion( MessagesCompanion(
openedAt: Value(actionTimestamp), openedAt: Value(timestamp),
), ),
); );
} }
@ -383,6 +386,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
); );
return; return;
} }
await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull(); final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null) { if (msg == null) {
Log.info( Log.info(
@ -390,7 +394,6 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
); );
return; return;
} }
await transaction(() async {
await into(messageActions).insertOnConflictUpdate( await into(messageActions).insertOnConflictUpdate(
MessageActionsCompanion( MessageActionsCompanion(
messageId: Value(messageId), messageId: Value(messageId),

View file

@ -112,7 +112,7 @@ Future<bool> createThumbnailsForImage(
); );
return true; return true;
} else { } else {
Log.error('Compressed image thumbnail is empty or missing.'); Log.warn('Compressed image thumbnail is empty or missing.');
try { try {
if (destinationFile.existsSync()) { if (destinationFile.existsSync()) {
destinationFile.deleteSync(); destinationFile.deleteSync();