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,6 +691,48 @@ void ChatForm::onAvatarRemoved(int FriendId)
|
|||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
|
||||
}
|
||||
|
||||
void ChatForm::loadHistory(QDateTime since)
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
|
||||
if (since > now)
|
||||
return;
|
||||
|
||||
if (earliestMessage)
|
||||
{
|
||||
if (*earliestMessage < since)
|
||||
return;
|
||||
if (*earliestMessage < now)
|
||||
{
|
||||
now = *earliestMessage;
|
||||
now = now.addMSecs(-1);
|
||||
}
|
||||
}
|
||||
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);
|
||||
|
||||
ToxID storedPrevId;
|
||||
std::swap(storedPrevId, previousId);
|
||||
QList<ChatActionPtr> historyMessages;
|
||||
|
||||
for (const auto &it : msgs)
|
||||
{
|
||||
ChatActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, it.timestamp.toLocalTime());
|
||||
historyMessages.append(ca);
|
||||
}
|
||||
std::swap(storedPrevId, previousId);
|
||||
|
||||
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
||||
|
||||
if (earliestMessage != nullptr)
|
||||
*earliestMessage = since;
|
||||
|
||||
chatWidget->insertMessagesTop(historyMessages);
|
||||
|
||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
||||
}
|
||||
|
||||
void ChatForm::onLoadHistory()
|
||||
{
|
||||
LoadHistoryDialog dlg;
|
||||
|
@ -695,44 +740,7 @@ void ChatForm::onLoadHistory()
|
|||
if (dlg.exec())
|
||||
{
|
||||
QDateTime fromTime = dlg.getFromDate();
|
||||
QDateTime toTime = QDateTime::currentDateTime();
|
||||
|
||||
if (fromTime > toTime)
|
||||
return;
|
||||
|
||||
if (earliestMessage)
|
||||
{
|
||||
if (*earliestMessage < fromTime)
|
||||
return;
|
||||
if (*earliestMessage < toTime)
|
||||
{
|
||||
toTime = *earliestMessage;
|
||||
toTime = toTime.addMSecs(-1);
|
||||
}
|
||||
}
|
||||
|
||||
auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, fromTime, toTime);
|
||||
|
||||
ToxID storedPrevId;
|
||||
std::swap(storedPrevId, previousId);
|
||||
QList<ChatActionPtr> historyMessages;
|
||||
|
||||
for (const auto &it : msgs)
|
||||
{
|
||||
ChatActionPtr ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, it.timestamp.toLocalTime());
|
||||
historyMessages.append(ca);
|
||||
}
|
||||
std::swap(storedPrevId, previousId);
|
||||
|
||||
int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
||||
|
||||
if (earliestMessage != nullptr)
|
||||
*earliestMessage = fromTime;
|
||||
|
||||
chatWidget->insertMessagesTop(historyMessages);
|
||||
|
||||
savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
|
||||
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
|
||||
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