1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

conversationmodel: fix loading for some conversations

If there was too much following merge commits, sometimes the
conversation was not correctly loaded.
Moreover, the lastMessageUID was not correctly calculated from
time to time, leading to empty conversations in the smartlist.

Change-Id: I1224269c5df72936ae51f34211ce3f63dbf606ff
This commit is contained in:
Sébastien Blin 2022-10-21 09:33:36 -04:00
parent 644c841a39
commit 1a994173ec
No known key found for this signature in database
GPG key ID: C894BB01EEB2A9A9
3 changed files with 28 additions and 14 deletions

View file

@ -2312,9 +2312,11 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId,
try {
auto& conversation = getConversationForUid(conversationId).get();
QString oldLast; // Used to detect loading loops just in case.
if (conversation.interactions->size() != 0)
QString oldLast, oldBegin; // Used to detect loading loops just in case.
if (conversation.interactions->size() != 0) {
oldBegin = conversation.interactions->begin()->first;
oldLast = conversation.interactions->rbegin()->first;
}
for (const auto& message : messages) {
if (message["type"].isEmpty()) {
continue;
@ -2362,21 +2364,19 @@ ConversationModelPimpl::slotConversationLoaded(uint32_t requestId,
}
}
for (int j = conversation.interactions->size() - 1; j >= 0; j--) {
if (conversation.interactions->atIndex(j).second.type != interaction::Type::MERGE) {
conversation.lastMessageUid = conversation.interactions->atIndex(j).first;
break;
}
}
conversation.lastMessageUid = conversation.interactions->lastMessageUid();
if (conversation.lastMessageUid.isEmpty() && !conversation.allMessagesLoaded
&& messages.size() != 0) {
if (conversation.interactions->size() > 0) {
QString newLast;
if (conversation.interactions->size() > 0)
QString newLast, newBegin;
if (conversation.interactions->size() > 0) {
newBegin = conversation.interactions->begin()->first;
newLast = conversation.interactions->rbegin()->first;
if (newLast == oldLast && !newLast.isEmpty()) { // [[unlikely]] in c++20
qCritical() << "Loading loop detected for " << conversationId << "(" << newLast
<< ")";
}
if (newLast == oldLast && !newLast.isEmpty() && newBegin == oldBegin
&& !newBegin.isEmpty()) { // [[unlikely]] in c++20
qCritical() << "Loading loop detected for " << conversationId << "(" << newBegin
<< " ; " << newLast << ")";
return;
}
}
@ -2473,7 +2473,7 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId,
invalidateModel();
return;
}
conversation.lastMessageUid = msgId;
conversation.lastMessageUid = conversation.interactions->lastMessageUid();
invalidateModel();
if (!interaction::isOutgoing(msg)) {
Q_EMIT behaviorController.newUnreadInteraction(linked.owner.id,

View file

@ -541,4 +541,16 @@ MessageListModel::emitDataChanged(const QString& msgId, VectorInt roles)
Q_EMIT dataChanged(modelIndex, modelIndex, roles);
}
QString
MessageListModel::lastMessageUid() const
{
for (auto it = interactions_.rbegin(); it != interactions_.rend(); ++it) {
auto lastType = it->second.type;
if (lastType != interaction::Type::MERGE and !it->second.body.isEmpty()) {
return it->first;
}
}
return {};
}
} // namespace lrc

View file

@ -130,6 +130,8 @@ public:
Q_SIGNAL void timestampUpdate();
QString lastMessageUid() const;
protected:
using Role = MessageList::Role;