Skip to content
Snippets Groups Projects
Commit 988e8841 authored by Léopold Chappuis's avatar Léopold Chappuis Committed by Andreas Traczyk
Browse files

loadMessages2: fix messages status when loading multiple times

Messages status are applied from the last message to the older one. The
variables memberToStatus has to be reset if we are not loading messages
from the middle.

Change-Id: I229b689c760c3d835143cc261e841076f8755b04
parent f5c560e8
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment