summaryrefslogtreecommitdiffstats
path: root/pica-client
diff options
context:
space:
mode:
authorAnton <anton@picapica>2019-04-27 20:59:48 +0400
committerAnton <anton@picapica>2019-04-27 20:59:48 +0400
commit850b332e7e591064bd8b3245554a05752240408e (patch)
treebb40b9caaa6f7a168896e9c34b88c59031399a1e /pica-client
parent194a8e3dede66de73323d539e9fdd4136ac111ed (diff)
downloadpica-pica-850b332e7e591064bd8b3245554a05752240408e.tar.gz
pica-pica-850b332e7e591064bd8b3245554a05752240408e.zip
pica-client: search in message history
Diffstat (limited to 'pica-client')
-rw-r--r--pica-client/chatwindow.cpp15
-rw-r--r--pica-client/chatwindow.h2
-rw-r--r--pica-client/history.cpp35
-rw-r--r--pica-client/history.h1
4 files changed, 53 insertions, 0 deletions
diff --git a/pica-client/chatwindow.cpp b/pica-client/chatwindow.cpp
index f50d489..cf2eba8 100644
--- a/pica-client/chatwindow.cpp
+++ b/pica-client/chatwindow.cpp
@@ -26,6 +26,7 @@
#include <QMessageBox>
#include <QDateTime>
#include <QMessageBox>
+#include <QInputDialog>
ChatWindow::ChatWindow(QByteArray peer_id, QString status) :
@@ -115,6 +116,7 @@ ChatWindow::ChatWindow(QByteArray peer_id, QString status) :
hist24h = new QAction(tr("Last 24 &Hours"), this);
hist1week = new QAction(tr("Last &Week"), this);
histAll = new QAction(tr("&All"), this);
+ histSearch = new QAction(tr("&Search History..."), this);
{
QMenu *m;
@@ -123,12 +125,14 @@ ChatWindow::ChatWindow(QByteArray peer_id, QString status) :
m->addAction(hist24h);
m->addAction(hist1week);
m->addAction(histAll);
+ m->addAction(histSearch);
}
layout->insertSpacing(0, menu->size().height());
connect(hist24h, SIGNAL(triggered()), this, SLOT(show_history24h()));
connect(hist1week, SIGNAL(triggered()), this, SLOT(show_history1w()));
connect(histAll, SIGNAL(triggered()), this, SLOT(show_historyAll()));
+ connect(histSearch, SIGNAL(triggered()), this, SLOT(show_historySearch()));
}
@@ -359,6 +363,17 @@ void ChatWindow::show_historyAll()
print_history(hist.GetMessages(peer_id_, 0, QDateTime::currentDateTime().toTime_t()));
}
+void ChatWindow::show_historySearch()
+{
+ bool ok;
+ QString keyword = QInputDialog::getText(this, tr("Search in message history"),
+ tr("Find:"), QLineEdit::Normal,
+ QString(), &ok);
+
+ if (ok)
+ print_history(hist.GetMessages(peer_id_, keyword));
+}
+
void ChatWindow::addct_yes()
{
Contacts ct(config_dbname, Accounts::GetCurrentAccount().id);
diff --git a/pica-client/chatwindow.h b/pica-client/chatwindow.h
index fa306a9..3cdce01 100644
--- a/pica-client/chatwindow.h
+++ b/pica-client/chatwindow.h
@@ -74,6 +74,7 @@ private:
QAction *hist24h;
QAction *hist1week;
QAction *histAll;
+ QAction *histSearch;
QString peer_name_;
QString my_name_;
bool addcontactquestion;
@@ -96,6 +97,7 @@ private slots:
void show_history24h();
void show_history1w();
void show_historyAll();
+ void show_historySearch();
void addct_yes();
void addct_no();
diff --git a/pica-client/history.cpp b/pica-client/history.cpp
index 3d4e127..bef61b1 100644
--- a/pica-client/history.cpp
+++ b/pica-client/history.cpp
@@ -83,6 +83,41 @@ void History::SetDelivered(QByteArray peer_id)
lasterr = query.lastError();
}
+QList<History::HistoryRecord> History::GetMessages(QByteArray peer_id, QString keyword)
+{
+ QList<HistoryRecord> L;
+ HistoryRecord r;
+ QSqlQuery query;
+
+ query.setForwardOnly(true);
+ query.prepare("select contact_id, is_me, is_delivered, timestamp, message from history \
+ where contact_id=:peer_id and account_id=:me and message like :keyword order by id"
+ );
+
+ query.bindValue(":peer_id", peer_id);
+ query.bindValue(":me", me_);
+ query.bindValue(":keyword", QString("%%1%").arg(keyword));
+ query.exec();
+
+ lasterr = query.lastError();
+
+ if (lasterr.isValid())
+ return L;
+
+ while(query.next())
+ {
+ r.peer_id = query.value(0).toByteArray();
+ r.is_me = query.value(1).toBool();
+ r.is_delivered = query.value(2).toBool();
+ r.timestamp = query.value(3).toUInt();
+ r.message = query.value(4).toString();
+
+ L << r;
+ }
+
+ return L;
+}
+
QList<History::HistoryRecord> History::GetMessages(QByteArray peer_id, quint32 start_timestamp, quint32 end_timestamp)
{
QList<HistoryRecord> L;
diff --git a/pica-client/history.h b/pica-client/history.h
index 1896a65..6281828 100644
--- a/pica-client/history.h
+++ b/pica-client/history.h
@@ -40,6 +40,7 @@ public:
void Add(QByteArray peer_id, QString message, bool is_me);//is_me - true - message from me to peer, false - from peer to me
void SetDelivered(QByteArray peer_id); //mark first undelivered message from me to peer as delivered
QList<HistoryRecord> GetMessages(QByteArray peer_id, quint32 start_timestamp, quint32 end_timestamp);
+ QList<HistoryRecord> GetMessages(QByteArray peer_id, QString keyword);
QMap<QByteArray, QList<QString> > GetUndeliveredMessages();
bool isOK();
QString GetLastError();