1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Removes chat history of friend when removed, fixes #1486

This commit is contained in:
kushagra 2015-03-29 13:34:05 +05:30
parent 885dc0638a
commit 07ba0c9ae0
3 changed files with 20 additions and 0 deletions

View File

@ -138,6 +138,24 @@ HistoryKeeper::~HistoryKeeper()
delete db; 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) qint64 HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent)
{ {
QList<QString> cmds = generateAddChatEntryCmd(chat, message, sender, dt, isSent); QList<QString> cmds = generateAddChatEntryCmd(chat, message, sender, dt, isSent);

View File

@ -54,6 +54,7 @@ public:
static bool removeHistory(int encrypted = -1); static bool removeHistory(int encrypted = -1);
static QList<HistMessage> exportMessagesDeleteFile(int encrypted = -1); static QList<HistMessage> 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 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); qint64 addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt);
QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to); QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to);

View File

@ -825,6 +825,7 @@ void Widget::removeFriend(Friend* f, bool fake)
} }
FriendList::removeFriend(f->getFriendID(), fake); FriendList::removeFriend(f->getFriendID(), fake);
Nexus::getCore()->removeFriend(f->getFriendID(), fake); Nexus::getCore()->removeFriend(f->getFriendID(), fake);
HistoryKeeper::getInstance()->removeFriendHistory(f->getToxID().publicKey);
delete f; delete f;
if (ui->mainHead->layout()->isEmpty()) if (ui->mainHead->layout()->isEmpty())
onAddClicked(); onAddClicked();