From b49b9cf452c13bf282db4f8808731f381a89d592 Mon Sep 17 00:00:00 2001 From: otsmr Date: Sun, 7 Jun 2026 12:23:54 +0200 Subject: [PATCH] fix groups where not ordered correctly in the chat list --- lib/src/database/daos/groups.dao.dart | 9 +++++++-- lib/src/database/twonly.db.dart | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/database/daos/groups.dao.dart b/lib/src/database/daos/groups.dao.dart index 1763432b..929dc2e0 100644 --- a/lib/src/database/daos/groups.dao.dart +++ b/lib/src/database/daos/groups.dao.dart @@ -1,3 +1,4 @@ +import 'package:clock/clock.dart' show clock; import 'package:drift/drift.dart'; import 'package:hashlib/random.dart'; import 'package:twonly/locator.dart'; @@ -327,12 +328,16 @@ class GroupsDao extends DatabaseAccessor with _$GroupsDaoMixin { String groupId, DateTime newLastMessage, ) async { + final now = clock.now(); + final clampedLastMessage = newLastMessage.isAfter(now) + ? now + : newLastMessage; await (update(groups)..where( (t) => t.groupId.equals(groupId) & - (t.lastMessageExchange.isSmallerThanValue(newLastMessage)), + (t.lastMessageExchange.isSmallerThanValue(clampedLastMessage)), )) - .write(GroupsCompanion(lastMessageExchange: Value(newLastMessage))); + .write(GroupsCompanion(lastMessageExchange: Value(clampedLastMessage))); } Stream> watchNonDirectGroupsForMember(int contactId) { diff --git a/lib/src/database/twonly.db.dart b/lib/src/database/twonly.db.dart index 812b03e9..91fe020e 100644 --- a/lib/src/database/twonly.db.dart +++ b/lib/src/database/twonly.db.dart @@ -239,8 +239,11 @@ class TwonlyDB extends _$TwonlyDB { } void markUpdated() { - notifyUpdates({TableUpdate.onTable(messages, kind: UpdateKind.update)}); - notifyUpdates({TableUpdate.onTable(contacts, kind: UpdateKind.update)}); + notifyUpdates({ + TableUpdate.onTable(messages, kind: UpdateKind.update), + TableUpdate.onTable(contacts, kind: UpdateKind.update), + TableUpdate.onTable(groups, kind: UpdateKind.update), + }); } Future printTableSizes() async {