mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
History: retrieve history from save
This commit is contained in:
parent
6860790205
commit
625cb32b32
|
@ -147,6 +147,7 @@ QTextTable *ChatAreaWidget::getMsgTable()
|
|||
|
||||
QTextCursor tc = textCursor();
|
||||
tc.movePosition(QTextCursor::End);
|
||||
|
||||
QTextTable *chatTextTable = tc.insertTable(1, 5, *tableFrmt);
|
||||
|
||||
return chatTextTable;
|
||||
|
@ -183,3 +184,8 @@ void ChatAreaWidget::clearChatArea()
|
|||
insertMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatAreaWidget::rerenderContent()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
explicit ChatAreaWidget(QWidget *parent = 0);
|
||||
virtual ~ChatAreaWidget();
|
||||
void insertMessage(ChatAction *msgAction);
|
||||
QList<ChatAction*>& getMesages() {return messages;}
|
||||
void rerenderContent();
|
||||
|
||||
int nameColWidth() {return nameWidth;}
|
||||
void setNameColWidth(int w);
|
||||
|
|
|
@ -90,6 +90,7 @@ void ChatForm::onSendTriggered()
|
|||
if (msg.isEmpty())
|
||||
return;
|
||||
QString name = Widget::getInstance()->getUsername();
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey);
|
||||
if (msg.startsWith("/me "))
|
||||
{
|
||||
msg = msg.right(msg.length() - 4);
|
||||
|
@ -102,8 +103,6 @@ void ChatForm::onSendTriggered()
|
|||
emit sendMessage(f->friendId, msg);
|
||||
}
|
||||
msgEdit->clear();
|
||||
|
||||
HistoryKeeper::getInstance()->addChatEntry(f->userId, msg, Core::getInstance()->getSelfId().publicKey);
|
||||
}
|
||||
|
||||
void ChatForm::onAttachClicked()
|
||||
|
@ -540,10 +539,52 @@ void ChatForm::onLoadHistory()
|
|||
if (dlg.exec())
|
||||
{
|
||||
QDateTime fromTime = dlg.getFromDate();
|
||||
QDateTime toTime = dlg.getToDate();
|
||||
QDateTime toTime = QDateTime::currentDateTime();
|
||||
|
||||
if (fromTime > toTime)
|
||||
return;
|
||||
|
||||
if (earliestMessage)
|
||||
{
|
||||
if (*earliestMessage < fromTime)
|
||||
return;
|
||||
if (*earliestMessage < toTime)
|
||||
toTime = *earliestMessage;
|
||||
}
|
||||
|
||||
fromTime = fromTime.toUTC();
|
||||
toTime = toTime.toUTC();
|
||||
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, Core::getInstance()->getSelfId().publicKey,
|
||||
f->userId, fromTime, toTime);
|
||||
// do smth with messages
|
||||
|
||||
QString storedPrevName = previousName;
|
||||
previousName = "";
|
||||
QList<ChatAction*> historyMessages;
|
||||
|
||||
for (const auto &it : msgs)
|
||||
{
|
||||
bool isAction = false;
|
||||
QString name = f->getName();
|
||||
if (it.sender == Core::getInstance()->getSelfId().publicKey)
|
||||
name = Core::getInstance()->getUsername();
|
||||
|
||||
ChatAction *ca = genMessageActionAction(name, it.message, isAction, it.timestamp.toLocalTime());
|
||||
historyMessages.append(ca);
|
||||
}
|
||||
previousName = storedPrevName;
|
||||
|
||||
for (ChatAction *ca : chatWidget->getMesages())
|
||||
historyMessages.append(ca);
|
||||
|
||||
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
||||
chatWidget->getMesages().clear();
|
||||
chatWidget->clear();
|
||||
|
||||
for (ChatAction *ca : historyMessages)
|
||||
chatWidget->insertMessage(ca);
|
||||
|
||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
#include "widget/maskablepixmapwidget.h"
|
||||
|
||||
GenericChatForm::GenericChatForm(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
QWidget(parent),
|
||||
earliestMessage(nullptr)
|
||||
{
|
||||
curRow = 0;
|
||||
|
||||
|
@ -124,7 +125,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
|
|||
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
menu.addAction(tr("Save chat log"), this, SLOT(onSaveLogClicked()));
|
||||
menu.addAction(tr("Clear displayed messages"), this, SLOT(clearChatArea()));
|
||||
menu.addAction(tr("Clear displayed messages"), this, SLOT(clearChatArea(bool)));
|
||||
menu.addSeparator();
|
||||
|
||||
connect(emoteButton, SIGNAL(clicked()), this, SLOT(onEmoteButtonClicked()));
|
||||
|
@ -169,29 +170,10 @@ void GenericChatForm::onSaveLogClicked()
|
|||
file.close();
|
||||
}
|
||||
|
||||
void GenericChatForm::addMessage(QString author, QString message, bool isAction, QDateTime datetime)
|
||||
void GenericChatForm::addMessage(const QString &author, const QString &message, bool isAction, const QDateTime &datetime)
|
||||
{
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
bool isMe = (author == Widget::getInstance()->getUsername());
|
||||
|
||||
if (!isAction && message.startsWith("/me "))
|
||||
{ // always render actions regardless of what core thinks
|
||||
isAction = true;
|
||||
message = message.right(message.length()-4);
|
||||
}
|
||||
|
||||
if (isAction)
|
||||
{
|
||||
chatWidget->insertMessage(new ActionAction (getElidedName(author), message, date, isMe));
|
||||
previousName = ""; // next msg has a name regardless
|
||||
return;
|
||||
}
|
||||
else if (previousName == author)
|
||||
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
||||
else
|
||||
chatWidget->insertMessage(new MessageAction(getElidedName(author), message, date, isMe));
|
||||
|
||||
previousName = author;
|
||||
ChatAction *ca = genMessageActionAction(author, message, isAction, datetime);
|
||||
chatWidget->insertMessage(ca);
|
||||
}
|
||||
|
||||
void GenericChatForm::onEmoteButtonClicked()
|
||||
|
@ -228,10 +210,8 @@ void GenericChatForm::focusInput()
|
|||
|
||||
void GenericChatForm::addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime)
|
||||
{
|
||||
previousName = "";
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
|
||||
chatWidget->insertMessage(new SystemMessageAction(message, type, date));
|
||||
ChatAction *ca = genSystemInfoAction(message, type, datetime);
|
||||
chatWidget->insertMessage(ca);
|
||||
}
|
||||
|
||||
QString GenericChatForm::getElidedName(const QString& name)
|
||||
|
@ -242,9 +222,58 @@ QString GenericChatForm::getElidedName(const QString& name)
|
|||
return fm.elidedText(name, Qt::ElideRight, chatWidget->nameColWidth());
|
||||
}
|
||||
|
||||
void GenericChatForm::clearChatArea()
|
||||
void GenericChatForm::clearChatArea(bool notinform)
|
||||
{
|
||||
chatWidget->clearChatArea();
|
||||
previousName = "";
|
||||
addSystemInfoMessage(tr("Cleared"), "green");
|
||||
|
||||
if (!notinform)
|
||||
addSystemInfoMessage(tr("Cleared"), "green");
|
||||
|
||||
if (earliestMessage)
|
||||
{
|
||||
delete earliestMessage;
|
||||
earliestMessage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ChatAction* GenericChatForm::genMessageActionAction(const QString &author, QString message,
|
||||
bool isAction, const QDateTime &datetime)
|
||||
{
|
||||
if (earliestMessage == nullptr)
|
||||
{
|
||||
earliestMessage = new QDateTime(datetime);
|
||||
}
|
||||
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
bool isMe = (author == Widget::getInstance()->getUsername());
|
||||
|
||||
if (!isAction && message.startsWith("/me "))
|
||||
{ // always render actions regardless of what core thinks
|
||||
isAction = true;
|
||||
message = message.right(message.length()-4);
|
||||
}
|
||||
|
||||
if (isAction)
|
||||
{
|
||||
previousName = ""; // next msg has a name regardless
|
||||
return (new ActionAction (getElidedName(author), message, date, isMe));
|
||||
}
|
||||
|
||||
ChatAction *res;
|
||||
if (previousName == author)
|
||||
res = (new MessageAction("", message, date, isMe));
|
||||
else
|
||||
res = (new MessageAction(getElidedName(author), message, date, isMe));
|
||||
|
||||
previousName = author;
|
||||
return res;
|
||||
}
|
||||
|
||||
ChatAction* GenericChatForm::genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime)
|
||||
{
|
||||
previousName = "";
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
|
||||
return (new SystemMessageAction(message, type, date));
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ class CroppingLabel;
|
|||
class ChatTextEdit;
|
||||
class ChatAreaWidget;
|
||||
class MaskablePixmapWidget;
|
||||
class ChatAction;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -45,7 +46,8 @@ public:
|
|||
|
||||
virtual void setName(const QString &newName);
|
||||
virtual void show(Ui::MainWindow &ui);
|
||||
void addMessage(QString author, QString message, bool isAction = false, QDateTime datetime=QDateTime::currentDateTime());
|
||||
void addMessage(const QString &author, const QString &message, bool isAction = false,
|
||||
const QDateTime &datetime=QDateTime::currentDateTime());
|
||||
void addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime=QDateTime::currentDateTime());
|
||||
|
||||
signals:
|
||||
|
@ -60,10 +62,14 @@ protected slots:
|
|||
void onSaveLogClicked();
|
||||
void onEmoteButtonClicked();
|
||||
void onEmoteInsertRequested(QString str);
|
||||
void clearChatArea();
|
||||
void clearChatArea(bool);
|
||||
|
||||
protected:
|
||||
QString getElidedName(const QString& name);
|
||||
ChatAction* genMessageActionAction(const QString &author, QString message, bool isAction = false,
|
||||
const QDateTime &datetime=QDateTime::currentDateTime());
|
||||
ChatAction* genSystemInfoAction(const QString &message, const QString &type,
|
||||
const QDateTime &datetime=QDateTime::currentDateTime());
|
||||
|
||||
QMenu menu;
|
||||
CroppingLabel *nameLabel;
|
||||
|
@ -76,6 +82,7 @@ protected:
|
|||
QString previousName;
|
||||
ChatAreaWidget *chatWidget;
|
||||
int curRow;
|
||||
QDateTime *earliestMessage;
|
||||
};
|
||||
|
||||
#endif // GENERICCHATFORM_H
|
||||
|
|
|
@ -34,9 +34,3 @@ QDateTime LoadHistoryDialog::getFromDate()
|
|||
QDateTime res(ui->fromDate->selectedDate());
|
||||
return res;
|
||||
}
|
||||
|
||||
QDateTime LoadHistoryDialog::getToDate()
|
||||
{
|
||||
QDateTime res(ui->toDate->selectedDate().addDays(1));
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ public:
|
|||
~LoadHistoryDialog();
|
||||
|
||||
QDateTime getFromDate();
|
||||
QDateTime getToDate();
|
||||
|
||||
private:
|
||||
Ui::LoadHistoryDialog *ui;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>574</width>
|
||||
<width>347</width>
|
||||
<height>264</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -15,40 +15,18 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="fromLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="fromLabel">
|
||||
<property name="text">
|
||||
<string>From Date</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCalendarWidget" name="fromDate">
|
||||
<property name="gridVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="toLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="toLabel">
|
||||
<property name="text">
|
||||
<string>To Date</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCalendarWidget" name="toDate"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QLabel" name="fromLabel">
|
||||
<property name="text">
|
||||
<string>From Date</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCalendarWidget" name="fromDate">
|
||||
<property name="gridVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
|
|
|
@ -30,12 +30,12 @@ void ActionAction::setup(QTextCursor cursor, QTextEdit *)
|
|||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
// message.clear();
|
||||
// message.squeeze();
|
||||
// name.clear();
|
||||
// name.squeeze();
|
||||
// date.clear();
|
||||
// date.squeeze();
|
||||
}
|
||||
|
||||
QString ActionAction::getName()
|
||||
|
|
|
@ -79,11 +79,11 @@ void FileTransferAction::updateHtml()
|
|||
if (w->getState() == FileTransferInstance::TransfState::tsCanceled
|
||||
|| w->getState() == FileTransferInstance::TransfState::tsFinished)
|
||||
{
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
cur = QTextCursor();
|
||||
// name.clear();
|
||||
// name.squeeze();
|
||||
// date.clear();
|
||||
// date.squeeze();
|
||||
// cur = QTextCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ void MessageAction::setup(QTextCursor cursor, QTextEdit *)
|
|||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
// message.clear();
|
||||
// message.squeeze();
|
||||
// name.clear();
|
||||
// name.squeeze();
|
||||
// date.clear();
|
||||
// date.squeeze();
|
||||
}
|
||||
|
||||
QString MessageAction::getMessage()
|
||||
|
|
|
@ -35,12 +35,12 @@ void SystemMessageAction::setup(QTextCursor cursor, QTextEdit *)
|
|||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
type.clear();
|
||||
type.squeeze();
|
||||
// message.clear();
|
||||
// message.squeeze();
|
||||
// name.clear();
|
||||
// name.squeeze();
|
||||
// date.clear();
|
||||
// date.squeeze();
|
||||
// type.clear();
|
||||
// type.squeeze();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user