Skip to content
Snippets Groups Projects
Commit a2f29911 authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

conversationmodel: add interaction cache clear function

jami-client-qt#550

Change-Id: Ib4366178408171ab54a57508ad4fe2311b18fd95
parent 1b71f12e
Branches
No related tags found
No related merge requests found
...@@ -258,6 +258,11 @@ public: ...@@ -258,6 +258,11 @@ public:
* @param interactionId * @param interactionId
*/ */
void clearInteractionFromConversation(const QString& convId, const QString& interactionId); void clearInteractionFromConversation(const QString& convId, const QString& interactionId);
/**
* Clear the cache for interactions in the conversation
* @param convId
*/
void clearInteractionsCache(const QString& convId);
/** /**
* Retry to send a message. In fact, will delete the previous interaction and resend a new one. * Retry to send a message. In fact, will delete the previous interaction and resend a new one.
* @param convId * @param convId
......
...@@ -1324,6 +1324,27 @@ ConversationModel::clearInteractionFromConversation(const QString& convId, ...@@ -1324,6 +1324,27 @@ ConversationModel::clearInteractionFromConversation(const QString& convId,
} }
} }
void
ConversationModel::clearInteractionsCache(const QString& convId)
{
auto conversationIdx = pimpl_->indexOf(convId);
if (conversationIdx == -1)
return;
try {
auto& conversation = pimpl_->conversations.at(conversationIdx);
{
std::lock_guard<std::mutex> lk(pimpl_->interactionsLocks[convId]);
conversation.interactions->clear(1);
}
conversation.allMessagesLoaded = false;
conversation.lastMessageUid = conversation.interactions->last().first;
} catch (const std::out_of_range& e) {
qDebug() << "can't find interaction from conversation: " << e.what();
return;
}
}
void void
ConversationModel::retryInteraction(const QString& convId, const QString& interactionId) ConversationModel::retryInteraction(const QString& convId, const QString& interactionId)
{ {
......
...@@ -157,9 +157,9 @@ MessageListModel::size() const ...@@ -157,9 +157,9 @@ MessageListModel::size() const
} }
void void
MessageListModel::clear() MessageListModel::clear(int leaveN)
{ {
interactions_.clear(); interactions_.erase(interactions_.begin(), std::prev(interactions_.end(), leaveN));
} }
bool bool
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
constIterator begin() const; constIterator begin() const;
reverseIterator rbegin(); reverseIterator rbegin();
int size() const; int size() const;
void clear(); void clear(int leaveN = 0);
bool empty() const; bool empty() const;
interaction::Info at(const QString& intId) const; interaction::Info at(const QString& intId) const;
QPair<QString, interaction::Info> front() const; QPair<QString, interaction::Info> front() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment