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:
		
							parent
							
								
									eb744bc9a4
								
							
						
					
					
						commit
						b95fc032b0
					
				@ -19,12 +19,10 @@ void conversationMiddleware(Store<MoxxyState> store, action, NextDispatcher next
 | 
				
			|||||||
        "jid": args.jid
 | 
					        "jid": args.jid
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!store.state.messages.containsKey(args.jid)) {
 | 
					    FlutterBackgroundService().sendData({
 | 
				
			||||||
      FlutterBackgroundService().sendData({
 | 
					        "type": "LoadMessagesForJidAction",
 | 
				
			||||||
          "type": "LoadMessagesForJidAction",
 | 
					        "jid": args.jid
 | 
				
			||||||
          "jid": args.jid
 | 
					    });
 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  } else if (action is SetOpenConversationAction) {
 | 
					  } else if (action is SetOpenConversationAction) {
 | 
				
			||||||
    FlutterBackgroundService().sendData({
 | 
					    FlutterBackgroundService().sendData({
 | 
				
			||||||
        "type": "SetCurrentlyOpenChatAction",
 | 
					        "type": "SetCurrentlyOpenChatAction",
 | 
				
			||||||
 | 
				
			|||||||
@ -83,6 +83,16 @@ class DatabaseRepository {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  /// Loads all messages for the conversation with jid [jid].
 | 
					  /// Loads all messages for the conversation with jid [jid].
 | 
				
			||||||
  Future<void> loadMessagesForJid(String jid) async {
 | 
					  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();
 | 
					    final messages = await this.isar.dBMessages.where().conversationJidEqualTo(jid).findAll();
 | 
				
			||||||
    this.loadedConversations.add(jid);
 | 
					    this.loadedConversations.add(jid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user