List of active calls in swarm is initialized incorrectly when linking an account to a new device
One of the constructors for the Conversation::Impl
class (in src/jamidht/conversation.cpp
) first tries to clone the conversation and then, if successful, computes the list of active calls by iterating over the list of commits in the conversation's git repo and calling the updateActiveCalls
function for each for them:
for (const auto& c : repository_->convCommitsToMap(commits))
updateActiveCalls(c);
The updateActiveCalls
function appears to have been written under the assumption that its argument is the most recent commit in a conversation, which means that in order for the above loop to produce the correct result, the list of commits returned by convCommitsToMap
would have to be in chronological order (i.e. oldest commits first). Unfortunately, convCommitsToMap
actually returns the commits in the opposite order. This can result in the active calls list containing many or even all of the past calls in the conversation's history.
A secondary issue is that updateActiveCalls
writes the list of active calls to disk and emits the ActiveCallsChanged
signal every time it adds or removes an element from the list. Thus, in the case of a conversation with, say, 50 past calls in its history, we could end up unnecessarily writing to the activeCalls
file, as well as emitting a signal containing incorrect information, up to 49 times.