mirror of https://github.com/qTox/qTox.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.4 KiB
85 lines
3.4 KiB
/* |
|
Copyright © 2019 by The qTox Project Contributors |
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
|
|
|
qTox is libre software: you can redistribute it and/or modify |
|
it under the terms of the GNU General Public License as published by |
|
the Free Software Foundation, either version 3 of the License, or |
|
(at your option) any later version. |
|
|
|
qTox is distributed in the hope that it will be useful, |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
GNU General Public License for more details. |
|
|
|
You should have received a copy of the GNU General Public License |
|
along with qTox. If not, see <http://www.gnu.org/licenses/>. |
|
*/ |
|
|
|
#pragma once |
|
|
|
#include "ichatlog.h" |
|
#include "sessionchatlog.h" |
|
#include "src/model/brokenmessagereason.h" |
|
#include "src/persistence/history.h" |
|
|
|
#include <QSet> |
|
|
|
class Settings; |
|
|
|
class ChatHistory : public IChatLog |
|
{ |
|
Q_OBJECT |
|
public: |
|
ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& coreIdHandler_, |
|
const Settings& settings_, IMessageDispatcher& messageDispatcher); |
|
const ChatLogItem& at(ChatLogIdx idx) const override; |
|
SearchResult searchForward(SearchPos startIdx, const QString& phrase, |
|
const ParameterSearch& parameter) const override; |
|
SearchResult searchBackward(SearchPos startIdx, const QString& phrase, |
|
const ParameterSearch& parameter) const override; |
|
ChatLogIdx getFirstIdx() const override; |
|
ChatLogIdx getNextIdx() const override; |
|
std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override; |
|
void addSystemMessage(const SystemMessage& message) override; |
|
|
|
public slots: |
|
void onFileUpdated(const ToxPk& sender, const ToxFile& file); |
|
void onFileTransferRemotePausedUnpaused(const ToxPk& sender, const ToxFile& file, bool paused); |
|
void onFileTransferBrokenUnbroken(const ToxPk& sender, const ToxFile& file, bool broken); |
|
|
|
|
|
private slots: |
|
void onMessageReceived(const ToxPk& sender, const Message& message); |
|
void onMessageSent(DispatchedMessageId id, const Message& message); |
|
void onMessageComplete(DispatchedMessageId id); |
|
void onMessageBroken(DispatchedMessageId id, BrokenMessageReason reason); |
|
|
|
private: |
|
void ensureIdxInSessionChatLog(ChatLogIdx idx) const; |
|
void loadHistoryIntoSessionChatLog(ChatLogIdx start) const; |
|
void dispatchUnsentMessages(IMessageDispatcher& messageDispatcher); |
|
void handleDispatchedMessage(DispatchedMessageId dispatchId, RowId historyId); |
|
void completeMessage(DispatchedMessageId id); |
|
void breakMessage(DispatchedMessageId id, BrokenMessageReason reason); |
|
bool canUseHistory() const; |
|
ChatLogIdx getInitialChatLogIdx() const; |
|
|
|
Friend& f; |
|
History* history; |
|
const Settings& settings; |
|
const ICoreIdHandler& coreIdHandler; |
|
mutable SessionChatLog sessionChatLog; |
|
|
|
// If a message completes before it's inserted into history it will end up |
|
// in this set |
|
QSet<DispatchedMessageId> completedMessages; |
|
// If a message breaks before it's inserted into history it will end up |
|
// in this set |
|
QMap<DispatchedMessageId, BrokenMessageReason> brokenMessages; |
|
|
|
// If a message is inserted into history before it gets a completion |
|
// callback it will end up in this map |
|
QMap<DispatchedMessageId, RowId> dispatchedMessageRowIdMap; |
|
};
|
|
|