fix groups where not ordered correctly in the chat list
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run

This commit is contained in:
otsmr 2026-06-07 12:23:54 +02:00
parent d1eb5d5be6
commit b49b9cf452
2 changed files with 12 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import 'package:clock/clock.dart' show clock;
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
import 'package:hashlib/random.dart'; import 'package:hashlib/random.dart';
import 'package:twonly/locator.dart'; import 'package:twonly/locator.dart';
@ -327,12 +328,16 @@ class GroupsDao extends DatabaseAccessor<TwonlyDB> with _$GroupsDaoMixin {
String groupId, String groupId,
DateTime newLastMessage, DateTime newLastMessage,
) async { ) async {
final now = clock.now();
final clampedLastMessage = newLastMessage.isAfter(now)
? now
: newLastMessage;
await (update(groups)..where( await (update(groups)..where(
(t) => (t) =>
t.groupId.equals(groupId) & t.groupId.equals(groupId) &
(t.lastMessageExchange.isSmallerThanValue(newLastMessage)), (t.lastMessageExchange.isSmallerThanValue(clampedLastMessage)),
)) ))
.write(GroupsCompanion(lastMessageExchange: Value(newLastMessage))); .write(GroupsCompanion(lastMessageExchange: Value(clampedLastMessage)));
} }
Stream<List<Group>> watchNonDirectGroupsForMember(int contactId) { Stream<List<Group>> watchNonDirectGroupsForMember(int contactId) {

View file

@ -239,8 +239,11 @@ class TwonlyDB extends _$TwonlyDB {
} }
void markUpdated() { void markUpdated() {
notifyUpdates({TableUpdate.onTable(messages, kind: UpdateKind.update)}); notifyUpdates({
notifyUpdates({TableUpdate.onTable(contacts, kind: UpdateKind.update)}); TableUpdate.onTable(messages, kind: UpdateKind.update),
TableUpdate.onTable(contacts, kind: UpdateKind.update),
TableUpdate.onTable(groups, kind: UpdateKind.update),
});
} }
Future<void> printTableSizes() async { Future<void> printTableSizes() async {