ui: Again fix issue with conversations not loading

Again: If we receive a message before first loading a
conversation, it won't load it on open.
This commit is contained in:
PapaTutuWawa 2022-01-16 18:12:42 +01:00
parent eb744bc9a4
commit b95fc032b0
2 changed files with 14 additions and 6 deletions

View File

@ -19,12 +19,10 @@ void conversationMiddleware(Store<MoxxyState> store, action, NextDispatcher next
"jid": args.jid
});
if (!store.state.messages.containsKey(args.jid)) {
FlutterBackgroundService().sendData({
"type": "LoadMessagesForJidAction",
"jid": args.jid
});
}
FlutterBackgroundService().sendData({
"type": "LoadMessagesForJidAction",
"jid": args.jid
});
} else if (action is SetOpenConversationAction) {
FlutterBackgroundService().sendData({
"type": "SetCurrentlyOpenChatAction",

View File

@ -83,6 +83,16 @@ class DatabaseRepository {
/// Loads all messages for the conversation with jid [jid].
Future<void> loadMessagesForJid(String jid) async {
if (this.loadedConversations.indexOf(jid) != -1) {
this.sendData({
"type": "LoadMessagesForJidResult",
"jid": jid,
"messages": this._messageCache[jid]!.map((m) => m.toJson()).toList()
});
return;
}
final messages = await this.isar.dBMessages.where().conversationJidEqualTo(jid).findAll();
this.loadedConversations.add(jid);