diff --git a/src/api/conversationmodel.h b/src/api/conversationmodel.h index c14fae9a251ef377fa97fdbc4158f83dcc5b8ca4..30dce4111277d7fe7f9ecc6e14eabf4dac75b4c7 100644 --- a/src/api/conversationmodel.h +++ b/src/api/conversationmodel.h @@ -138,6 +138,10 @@ public: * @param msgId, id of the interaction */ void setInteractionRead(const std::string& convId, const uint64_t& msgId); + /** + * clear all history + */ + void clearAllHistory(); Q_SIGNALS: /** @@ -178,6 +182,11 @@ Q_SIGNALS: * @param uid */ 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: std::unique_ptr<ConversationModelPimpl> pimpl_; diff --git a/src/authority/databasehelper.cpp b/src/authority/databasehelper.cpp index 79601e12008b437ad65bfec80fc01c2a2ba089ee..31066901c2fda11e10510a3a139868a92332b454 100644 --- a/src/authority/databasehelper.cpp +++ b/src/authority/databasehelper.cpp @@ -280,6 +280,16 @@ void clearHistory(Database& db, 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 removeContact(Database& db, const std::string& accountUri, const std::string& contactUri) { diff --git a/src/authority/databasehelper.h b/src/authority/databasehelper.h index b61d616713a03b69f20398b7725a687c80a7388d..57e3a77ad828020a5ad7ffbe4a154210842da739 100644 --- a/src/authority/databasehelper.h +++ b/src/authority/databasehelper.h @@ -187,6 +187,13 @@ void updateInteractionStatus(Database& db, unsigned int id, void clearHistory(Database& db, 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 * the conversations table and profiles if the profile is not present in conversations. diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 77388bbdc72a70cb097e8b74cf067e79b1f123e0..6197d67282dcd2fc5b79909463919a21705f2682 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -601,6 +601,17 @@ ConversationModel::clearHistory(const std::string& 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 ConversationModel::setInteractionRead(const std::string& convId, const uint64_t& msgId) {