🐛 Bug fixes on duplicate message

This commit is contained in:
2024-06-23 19:13:07 +08:00
parent d0cd75d653
commit 8036930084
3 changed files with 27 additions and 2 deletions

View File

@ -18,9 +18,11 @@ class ChatHistoryController {
}
Future<void> getMessages(Channel channel, String scope) async {
isLoading.value = true;
totalHistoryCount.value =
await database.syncMessages(channel, scope: scope);
await syncHistory(channel);
isLoading.value = false;
}
Future<void> getMoreMessages(Channel channel, String scope) async {
@ -42,7 +44,23 @@ class ChatHistoryController {
receiveMessage(Message remote) async {
final entry = await database.receiveMessage(remote);
currentHistory.add(entry);
final idx = currentHistory.indexWhere((x) => x.data.uuid == remote.uuid);
if (idx != -1) {
currentHistory[idx] = entry;
} else {
currentHistory.insert(0, entry);
}
}
addTemporaryMessage(Message info) async {
currentHistory.insert(
0,
LocalMessage(
info.id,
info,
info.channelId,
),
);
}
void replaceMessage(Message remote) async {