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,
DateTime timestamp,
) async {
await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null || msg.content == null || msg.senderId != contactId) {
return;
@ -283,6 +284,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
modifiedAt: Value(timestamp),
),
);
});
}
Future<void> handleMessagesOpened(
@ -291,7 +293,9 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> 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<TwonlyDB> with _$MessagesDaoMixin {
}
for (final messageId in messageIds) {
try {
var actionTimestamp = timestamp;
await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null) {
Log.info(
'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(
'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.',
);
actionTimestamp = msg.createdAt;
ts = msg.createdAt;
}
final ts = actionTimestamp;
await transaction(() async {
await into(messageActions).insertOnConflictUpdate(
MessageActionsCompanion(
messageId: Value(messageId),
@ -353,7 +356,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
messages,
)..where((tbl) => tbl.messageId.equals(messageId))).write(
MessagesCompanion(
openedAt: Value(actionTimestamp),
openedAt: Value(timestamp),
),
);
}
@ -383,6 +386,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
);
return;
}
await transaction(() async {
final msg = await getMessageById(messageId).getSingleOrNull();
if (msg == null) {
Log.info(
@ -390,7 +394,6 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
);
return;
}
await transaction(() async {
await into(messageActions).insertOnConflictUpdate(
MessageActionsCompanion(
messageId: Value(messageId),

View file

@ -112,7 +112,7 @@ Future<bool> 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();