mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Autoload last week of history on startup
Only if keeping history is enabled, of course
This commit is contained in:
parent
33b5e48b6a
commit
a158aed643
|
@ -23,12 +23,12 @@
|
|||
Friend::Friend(int FriendId, QString UserId)
|
||||
: friendId(FriendId)
|
||||
{
|
||||
widget = new FriendWidget(friendId, UserId);
|
||||
chatForm = new ChatForm(this);
|
||||
hasNewEvents = 0;
|
||||
friendStatus = Status::Offline;
|
||||
userID = ToxID::fromString(UserId);
|
||||
userName = UserId;
|
||||
widget = new FriendWidget(friendId, UserId);
|
||||
chatForm = new ChatForm(this);
|
||||
}
|
||||
|
||||
Friend::~Friend()
|
||||
|
|
|
@ -78,6 +78,9 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
if (Settings::getInstance().getEnableLogging())
|
||||
loadHistory(QDateTime::currentDateTime().addDays(-7));
|
||||
}
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
|
@ -688,30 +691,25 @@ void ChatForm::onAvatarRemoved(int FriendId)
|
|||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
||||
}
|
||||
|
||||
void ChatForm::onLoadHistory()
|
||||
void ChatForm::loadHistory(QDateTime since)
|
||||
{
|
||||
LoadHistoryDialog dlg;
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
||||
if (dlg.exec())
|
||||
{
|
||||
QDateTime fromTime = dlg.getFromDate();
|
||||
QDateTime toTime = QDateTime::currentDateTime();
|
||||
|
||||
if (fromTime > toTime)
|
||||
if (since > now)
|
||||
return;
|
||||
|
||||
if (earliestMessage)
|
||||
{
|
||||
if (*earliestMessage < fromTime)
|
||||
if (*earliestMessage < since)
|
||||
return;
|
||||
if (*earliestMessage < toTime)
|
||||
if (*earliestMessage < now)
|
||||
{
|
||||
toTime = *earliestMessage;
|
||||
toTime = toTime.addMSecs(-1);
|
||||
now = *earliestMessage;
|
||||
now = now.addMSecs(-1);
|
||||
}
|
||||
}
|
||||
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, fromTime, toTime);
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
|
||||
|
||||
ToxID storedPrevId;
|
||||
std::swap(storedPrevId, previousId);
|
||||
|
@ -727,12 +725,22 @@ void ChatForm::onLoadHistory()
|
|||
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
||||
|
||||
if (earliestMessage != nullptr)
|
||||
*earliestMessage = fromTime;
|
||||
*earliestMessage = since;
|
||||
|
||||
chatWidget->insertMessagesTop(historyMessages);
|
||||
|
||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
||||
}
|
||||
|
||||
void ChatForm::onLoadHistory()
|
||||
{
|
||||
LoadHistoryDialog dlg;
|
||||
|
||||
if (dlg.exec())
|
||||
{
|
||||
QDateTime fromTime = dlg.getFromDate();
|
||||
loadHistory(fromTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ private slots:
|
|||
void updateTime();
|
||||
|
||||
protected:
|
||||
void loadHistory(QDateTime since);
|
||||
// drag & drop
|
||||
void dragEnterEvent(QDragEnterEvent* ev);
|
||||
void dropEvent(QDropEvent* ev);
|
||||
|
|
Loading…
Reference in New Issue
Block a user