示例#1
0
文件: chatform.cpp 项目: stqism/qTox
void ChatForm::onLoadHistory()
{
    LoadHistoryDialog dlg;

    if (dlg.exec())
    {
        QDateTime fromTime = dlg.getFromDate();
        loadHistory(fromTime);
    }
}
示例#2
0
文件: chatform.cpp 项目: Pik-9/qTox
void ChatForm::onLoadHistory()
{
    if (!Nexus::getProfile()->isHistoryEnabled())
        return;

    LoadHistoryDialog dlg;

    if (dlg.exec())
    {
        QDateTime fromTime = dlg.getFromDate();
        loadHistory(fromTime);
    }
}
示例#3
0
void ChatForm::onLoadHistory()
{
    LoadHistoryDialog dlg;

    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->userId, 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);
    }
}