mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #4488
tWido (1): feat(chatform): Highlight chat history
This commit is contained in:
commit
23fd6962a1
@ -285,6 +285,47 @@ QList<History::HistMessage> History::getChatHistory(const QString& friendPk, con
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fetches chat messages counts for each day from the database.
|
||||||
|
* @param friendPk Friend public key to fetch.
|
||||||
|
* @param from Start of period to fetch.
|
||||||
|
* @param to End of period to fetch.
|
||||||
|
* @return List of structs containing days offset and message count for that day.
|
||||||
|
*/
|
||||||
|
QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk, const QDate& from,
|
||||||
|
const QDate& to)
|
||||||
|
{
|
||||||
|
if (!isValid()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
QDateTime fromTime(from);
|
||||||
|
QDateTime toTime(to);
|
||||||
|
|
||||||
|
QList<DateMessages> counts;
|
||||||
|
|
||||||
|
auto rowCallback = [&counts](const QVector<QVariant>& row) {
|
||||||
|
DateMessages app;
|
||||||
|
app.count = row[0].toUInt();
|
||||||
|
app.offsetDays = row[1].toUInt();
|
||||||
|
counts.append(app);
|
||||||
|
};
|
||||||
|
|
||||||
|
QString queryText =
|
||||||
|
QString("SELECT COUNT(history.id), ((timestamp / 1000 / 60 / 60 / 24) - %4 ) AS day "
|
||||||
|
"FROM history "
|
||||||
|
"JOIN peers chat ON chat_id = chat.id "
|
||||||
|
"WHERE timestamp BETWEEN %1 AND %2 AND chat.public_key='%3'"
|
||||||
|
"GROUP BY day;")
|
||||||
|
.arg(fromTime.toMSecsSinceEpoch())
|
||||||
|
.arg(toTime.toMSecsSinceEpoch())
|
||||||
|
.arg(friendPk.toString())
|
||||||
|
.arg(QDateTime::fromMSecsSinceEpoch(0).daysTo(fromTime));
|
||||||
|
|
||||||
|
db->execNow({queryText, rowCallback});
|
||||||
|
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Marks a message as sent.
|
* @brief Marks a message as sent.
|
||||||
* Removing message from the faux-offline pending messages list.
|
* Removing message from the faux-offline pending messages list.
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <tox/toxencryptsave.h>
|
#include <tox/toxencryptsave.h>
|
||||||
|
|
||||||
|
#include "src/core/toxpk.h"
|
||||||
#include "src/persistence/db/rawdatabase.h"
|
#include "src/persistence/db/rawdatabase.h"
|
||||||
|
|
||||||
class Profile;
|
class Profile;
|
||||||
@ -58,6 +59,12 @@ public:
|
|||||||
bool isSent;
|
bool isSent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DateMessages
|
||||||
|
{
|
||||||
|
uint offsetDays;
|
||||||
|
uint count;
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit History(std::shared_ptr<RawDatabase> db);
|
explicit History(std::shared_ptr<RawDatabase> db);
|
||||||
~History();
|
~History();
|
||||||
@ -73,6 +80,9 @@ public:
|
|||||||
|
|
||||||
QList<HistMessage> getChatHistory(const QString& friendPk, const QDateTime& from,
|
QList<HistMessage> getChatHistory(const QString& friendPk, const QDateTime& from,
|
||||||
const QDateTime& to);
|
const QDateTime& to);
|
||||||
|
|
||||||
|
QList<DateMessages> getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to);
|
||||||
|
|
||||||
void markAsSent(qint64 messageId);
|
void markAsSent(qint64 messageId);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -820,7 +820,7 @@ void ChatForm::onLoadHistory()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadHistoryDialog dlg;
|
LoadHistoryDialog dlg(f->getPublicKey());
|
||||||
if (dlg.exec()) {
|
if (dlg.exec()) {
|
||||||
QDateTime fromTime = dlg.getFromDate();
|
QDateTime fromTime = dlg.getFromDate();
|
||||||
loadHistory(fromTime);
|
loadHistory(fromTime);
|
||||||
|
@ -19,12 +19,21 @@
|
|||||||
|
|
||||||
#include "loadhistorydialog.h"
|
#include "loadhistorydialog.h"
|
||||||
#include "ui_loadhistorydialog.h"
|
#include "ui_loadhistorydialog.h"
|
||||||
|
#include "src/nexus.h"
|
||||||
|
#include "src/persistence/history.h"
|
||||||
|
#include "src/persistence/profile.h"
|
||||||
|
#include <QDate>
|
||||||
|
#include <QTextCharFormat>
|
||||||
|
|
||||||
LoadHistoryDialog::LoadHistoryDialog(QWidget* parent)
|
LoadHistoryDialog::LoadHistoryDialog(const ToxPk& friendPk, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, ui(new Ui::LoadHistoryDialog)
|
, ui(new Ui::LoadHistoryDialog)
|
||||||
|
, friendPk(friendPk)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
highlightDates(QDate::currentDate().year(), QDate::currentDate().month());
|
||||||
|
connect(ui->fromDate, &QCalendarWidget::currentPageChanged, this,
|
||||||
|
&LoadHistoryDialog::highlightDates);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadHistoryDialog::~LoadHistoryDialog()
|
LoadHistoryDialog::~LoadHistoryDialog()
|
||||||
@ -43,3 +52,20 @@ QDateTime LoadHistoryDialog::getFromDate()
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadHistoryDialog::highlightDates(int year, int month)
|
||||||
|
{
|
||||||
|
History* history = Nexus::getProfile()->getHistory();
|
||||||
|
QDate monthStart(year, month, 1);
|
||||||
|
QDate monthEnd(year, month + 1, 1);
|
||||||
|
QList<History::DateMessages> counts =
|
||||||
|
history->getChatHistoryCounts(this->friendPk, monthStart, monthEnd);
|
||||||
|
|
||||||
|
QTextCharFormat bold;
|
||||||
|
bold.setFontWeight(QFont::Bold);
|
||||||
|
|
||||||
|
QCalendarWidget* calendar = ui->fromDate;
|
||||||
|
for (History::DateMessages p : counts) {
|
||||||
|
calendar->setDateTextFormat(monthStart.addDays(p.offsetDays), bold);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef LOADHISTORYDIALOG_H
|
#ifndef LOADHISTORYDIALOG_H
|
||||||
#define LOADHISTORYDIALOG_H
|
#define LOADHISTORYDIALOG_H
|
||||||
|
|
||||||
|
#include "src/core/toxpk.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
@ -32,13 +33,17 @@ class LoadHistoryDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LoadHistoryDialog(QWidget* parent = 0);
|
explicit LoadHistoryDialog(const ToxPk& friendPk, QWidget* parent = 0);
|
||||||
~LoadHistoryDialog();
|
~LoadHistoryDialog();
|
||||||
|
|
||||||
QDateTime getFromDate();
|
QDateTime getFromDate();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void highlightDates(int year, int month);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LoadHistoryDialog* ui;
|
Ui::LoadHistoryDialog* ui;
|
||||||
|
const ToxPk friendPk;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOADHISTORYDIALOG_H
|
#endif // LOADHISTORYDIALOG_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user