diff --git a/src/jamidht/conversation.cpp b/src/jamidht/conversation.cpp index 313a81dadfab2fa75d08342c69460c3d9a983a63..21ce9e035284b393eab70ec8c7e56a49d2970e31 100644 --- a/src/jamidht/conversation.cpp +++ b/src/jamidht/conversation.cpp @@ -660,6 +660,11 @@ public: // Note: only store int32_t cause it's easy to pass to dbus this way // memberToStatus serves as a cache for loading messages mutable std::map<std::string, int32_t> memberToStatus; + + // Note: lastSwarmMessageIdLoaded stores an interactionId and is used to prevent clearing + // the memberToStatus in case messages are not from the beginning + mutable std::string lastSwarmMessageIdLoaded; + // futureStatus is used to store the status for receiving messages // (because we're not sure to fetch the commit before receiving a status change for this) mutable std::map<std::string, std::map<std::string, int32_t>> futureStatus; @@ -828,6 +833,14 @@ Conversation::Impl::loadMessages2(const LogOptions& options, History* optHistory isLoadingHistory_ = true; } + // Reset variables if needed to get the correct status. + // options.from stores a swarmMessageId; this option is used + // to load the messages of a conversation from a specific message + if (options.from != lastSwarmMessageIdLoaded) { + memberToStatus.clear(); + lastSwarmMessageIdLoaded.clear(); + } + auto startLogging = options.from == ""; auto breakLogging = false; auto currentHistorySize = loadedHistory_.messageList.size(); @@ -1101,6 +1114,10 @@ Conversation::Impl::addToHistory(const std::vector<std::map<std::string, std::st } // Else we need to compute the status. auto& cache = memberToStatus[member.uri]; + // And we need to update lastSwarmMessageIdLoaded to guarantee that we will clear the cache if + // we don't load messages from a specific message in order to get the correct status everytime + // we call this function + lastSwarmMessageIdLoaded = sharedCommit->id; if (cache == 0) { // Message is sending, sent or displayed cache = static_cast<int32_t>(libjami::Account::MessageStates::SENDING);