diff --git a/src/api/conversationmodel.h b/src/api/conversationmodel.h index 30dce4111277d7fe7f9ecc6e14eabf4dac75b4c7..3203e787d8920e976b5df484335efa771b2071d0 100644 --- a/src/api/conversationmodel.h +++ b/src/api/conversationmodel.h @@ -142,6 +142,11 @@ public: * clear all history */ 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: /** diff --git a/src/authority/databasehelper.cpp b/src/authority/databasehelper.cpp index 31066901c2fda11e10510a3a139868a92332b454..053b50d9e7690c97f2e2d582755548c54c27f9d6 100644 --- a/src/authority/databasehelper.cpp +++ b/src/authority/databasehelper.cpp @@ -358,6 +358,12 @@ countUnreadFromInteractions(Database& db, const std::string& 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 authority diff --git a/src/authority/databasehelper.h b/src/authority/databasehelper.h index 57e3a77ad828020a5ad7ffbe4a154210842da739..d750a3136571c5ea79b0de03c02593452b36737e 100644 --- a/src/authority/databasehelper.h +++ b/src/authority/databasehelper.h @@ -194,6 +194,13 @@ void clearHistory(Database& db, */ 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 * the conversations table and profiles if the profile is not present in conversations. diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 6197d67282dcd2fc5b79909463919a21705f2682..3eb82442c9af6cf80b57e27604d4f827a4f1a4f6 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -378,6 +378,18 @@ ConversationModel::removeConversation(const std::string& uid, bool 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 ConversationModelPimpl::placeCall(const std::string& uid, bool isAudioOnly) {