Skip to content
Snippets Groups Projects
Commit 1f7b84cd authored by Nicolas Jager's avatar Nicolas Jager Committed by Anthony Léonard
Browse files

ConversationModel : add clearAllHistory


- ConversationModel::clearAllHistory erase all interaction stored
by the database with database::clearAllHistoryFor. Then it clean
the ConversationModel itself.

Change-Id: Ib78783a28381a31904e04046c886e7c216126638
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent ffc180d0
No related branches found
No related tags found
No related merge requests found
...@@ -138,6 +138,10 @@ public: ...@@ -138,6 +138,10 @@ public:
* @param msgId, id of the interaction * @param msgId, id of the interaction
*/ */
void setInteractionRead(const std::string& convId, const uint64_t& msgId); void setInteractionRead(const std::string& convId, const uint64_t& msgId);
/**
* clear all history
*/
void clearAllHistory();
Q_SIGNALS: Q_SIGNALS:
/** /**
...@@ -178,6 +182,11 @@ Q_SIGNALS: ...@@ -178,6 +182,11 @@ Q_SIGNALS:
* @param uid * @param uid
*/ */
void conversationRemoved(const std::string& uid) const; void conversationRemoved(const std::string& uid) const;
/**
* Emitted after all history were cleared
* @note the client must connect this signal to know when update the view of the list
*/
void allHistoryCleared() const;
private: private:
std::unique_ptr<ConversationModelPimpl> pimpl_; std::unique_ptr<ConversationModelPimpl> pimpl_;
......
...@@ -280,6 +280,16 @@ void clearHistory(Database& db, ...@@ -280,6 +280,16 @@ void clearHistory(Database& db,
db.deleteFrom("interactions", "conversation_id=:id", {{":id", conversationId}}); db.deleteFrom("interactions", "conversation_id=:id", {{":id", conversationId}});
} }
void clearAllHistoryFor(Database& db, const std::string& accountUri)
{
auto accountId = db.select("id", "profiles","uri=:uri", {{":uri", accountUri}}).payloads;
if (accountId.empty())
return;
db.deleteFrom("interactions", "account_id=:account_id", {{":account_id", accountId[0]}});
}
void void
removeContact(Database& db, const std::string& accountUri, const std::string& contactUri) removeContact(Database& db, const std::string& accountUri, const std::string& contactUri)
{ {
......
...@@ -187,6 +187,13 @@ void updateInteractionStatus(Database& db, unsigned int id, ...@@ -187,6 +187,13 @@ void updateInteractionStatus(Database& db, unsigned int id,
void clearHistory(Database& db, void clearHistory(Database& db,
const std::string& conversationId); const std::string& conversationId);
/**
* Clear all history stored in the database for the account uri
* @param db
* @param accountUri
*/
void clearAllHistoryFor(Database& db, const std::string& accountUri);
/** /**
* Remove a conversation between an account and a contact. Remove corresponding entries in * Remove a conversation between an account and a contact. Remove corresponding entries in
* the conversations table and profiles if the profile is not present in conversations. * the conversations table and profiles if the profile is not present in conversations.
......
...@@ -601,6 +601,17 @@ ConversationModel::clearHistory(const std::string& uid) ...@@ -601,6 +601,17 @@ ConversationModel::clearHistory(const std::string& uid)
emit conversationCleared(uid); emit conversationCleared(uid);
} }
void
ConversationModel::clearAllHistory()
{
database::clearAllHistoryFor(pimpl_->db, owner.profileInfo.uri);
for (auto& conversation : pimpl_->conversations) {
conversation.interactions.clear();
database::getHistory(pimpl_->db, conversation);
}
}
void void
ConversationModel::setInteractionRead(const std::string& convId, const uint64_t& msgId) ConversationModel::setInteractionRead(const std::string& convId, const uint64_t& msgId)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment