Browse Source

Merge branch 'pr1489'

Removes chat history of friend when removed, fixes #1486
pull/1602/head
tux3 10 years ago
parent
commit
a232e5afd6
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 18
      src/historykeeper.cpp
  2. 1
      src/historykeeper.h
  3. 1
      src/widget/widget.cpp

18
src/historykeeper.cpp

@ -138,6 +138,24 @@ HistoryKeeper::~HistoryKeeper() @@ -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<QString> cmds = generateAddChatEntryCmd(chat, message, sender, dt, isSent);

1
src/historykeeper.h

@ -54,6 +54,7 @@ public: @@ -54,6 +54,7 @@ public:
static bool removeHistory(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 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);

1
src/widget/widget.cpp

@ -866,6 +866,7 @@ void Widget::removeFriend(Friend* f, bool fake) @@ -866,6 +866,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();

Loading…
Cancel
Save