Commit 1f7b84cd authored by Nicolas Jager's avatar Nicolas Jager Committed by Anthony Léonard

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
......@@ -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_;
......
......@@ -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)
{
......
......@@ -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.
......
......@@ -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)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment