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

delete obsolete history.

- add ConversationModel::deleteObsoleteHistory. This method can be
  called from clients.

- add database::deleteObsoleteHistory. This method is used only by
  ConversationModel::deleteObsoleteHistory.

Change-Id: I4d1187efee13e2927e8c963d15b5d5e34ac88b4d
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 1f7b84cd
...@@ -142,6 +142,11 @@ public: ...@@ -142,6 +142,11 @@ public:
* clear all history * clear all history
*/ */
void clearAllHistory(); void clearAllHistory();
/**
* delete obsolete history from the database
* @param days, number of days from today. Below this date, interactions will be deleted
*/
void deleteObsoleteHistory(int date);
Q_SIGNALS: Q_SIGNALS:
/** /**
......
...@@ -358,6 +358,12 @@ countUnreadFromInteractions(Database& db, const std::string& conversationId) ...@@ -358,6 +358,12 @@ countUnreadFromInteractions(Database& db, const std::string& conversationId)
return db.count("status", "interactions", "status='UNREAD' AND conversation_id='" + conversationId + "'"); return db.count("status", "interactions", "status='UNREAD' AND conversation_id='" + conversationId + "'");
} }
void
deleteObsoleteHistory(Database& db, long int date)
{
db.deleteFrom("interactions", "timestamp<=:date", {{":date", std::to_string(date)}});
}
} // namespace database } // namespace database
} // namespace authority } // namespace authority
......
...@@ -194,6 +194,13 @@ void clearHistory(Database& db, ...@@ -194,6 +194,13 @@ void clearHistory(Database& db,
*/ */
void clearAllHistoryFor(Database& db, const std::string& accountUri); void clearAllHistoryFor(Database& db, const std::string& accountUri);
/**
* delete obsolete histori from the database
* @param db
* @param date in second since epoch. Below this date, interactions will be deleted
*/
void deleteObsoleteHistory(Database& db, long int date);
/** /**
* 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.
......
...@@ -378,6 +378,18 @@ ConversationModel::removeConversation(const std::string& uid, bool banned) ...@@ -378,6 +378,18 @@ ConversationModel::removeConversation(const std::string& uid, bool banned)
owner.contactModel->removeContact(participant, banned); owner.contactModel->removeContact(participant, banned);
} }
void
ConversationModel::deleteObsoleteHistory(int days)
{
if(days < 1)
return; // unlimited history
auto currentTime = static_cast<long int>(std::time(nullptr)); // since epoch, in seconds...
auto date = currentTime - (days * 86400);
database::deleteObsoleteHistory(pimpl_->db, date);
}
void void
ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly) ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly)
{ {
......
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