diff --git a/src/historykeeper.cpp b/src/historykeeper.cpp index 4a7a1b467..e2671661e 100644 --- a/src/historykeeper.cpp +++ b/src/historykeeper.cpp @@ -138,6 +138,24 @@ HistoryKeeper::~HistoryKeeper() delete db; } +void HistoryKeeper::removeFriendHistory(const QString& chat) +{ + int chat_id = getChatID(chat, ctSingle).first; + + db->exec("BEGIN TRANSACTION;"); + + QString cmd = QString("DELETE FROM chats WHERE name = '%1';").arg(chat); + db->exec(cmd); + cmd = QString("DELETE FROM aliases WHERE user_id = '%1';").arg(chat); + db->exec(cmd); + cmd = QString("DELETE FROM sent_status WHERE id IN (SELECT id FROM history WHERE chat_id = '%1');").arg(chat_id); + db->exec(cmd); + cmd = QString("DELETE FROM history WHERE chat_id = '%1';").arg(chat_id); + db->exec(cmd); + + db->exec("COMMIT TRANSACTION;"); +} + qint64 HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent) { QList cmds = generateAddChatEntryCmd(chat, message, sender, dt, isSent); diff --git a/src/historykeeper.h b/src/historykeeper.h index ad80b536f..8c1abcbb7 100644 --- a/src/historykeeper.h +++ b/src/historykeeper.h @@ -54,6 +54,7 @@ public: static bool removeHistory(int encrypted = -1); static QList exportMessagesDeleteFile(int encrypted = -1); + void removeFriendHistory(const QString& chat); qint64 addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent); qint64 addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt); QList getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index fdb4e5591..eb4929641 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -825,6 +825,7 @@ void Widget::removeFriend(Friend* f, bool fake) } FriendList::removeFriend(f->getFriendID(), fake); Nexus::getCore()->removeFriend(f->getFriendID(), fake); + HistoryKeeper::getInstance()->removeFriendHistory(f->getToxID().publicKey); delete f; if (ui->mainHead->layout()->isEmpty()) onAddClicked();