qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
chathistory.h
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "ichatlog.h"
23 #include "sessionchatlog.h"
26 
27 #include <QSet>
28 
29 class Settings;
30 
31 class ChatHistory : public IChatLog
32 {
33  Q_OBJECT
34 public:
35  ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& coreIdHandler,
36  const Settings& settings, IMessageDispatcher& messageDispatcher);
37  const ChatLogItem& at(ChatLogIdx idx) const override;
38  SearchResult searchForward(SearchPos startIdx, const QString& phrase,
39  const ParameterSearch& parameter) const override;
40  SearchResult searchBackward(SearchPos startIdx, const QString& phrase,
41  const ParameterSearch& parameter) const override;
42  ChatLogIdx getFirstIdx() const override;
43  ChatLogIdx getNextIdx() const override;
44  std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
45  void addSystemMessage(const SystemMessage& message) override;
46 
47 public slots:
48  void onFileUpdated(const ToxPk& sender, const ToxFile& file);
49  void onFileTransferRemotePausedUnpaused(const ToxPk& sender, const ToxFile& file, bool paused);
50  void onFileTransferBrokenUnbroken(const ToxPk& sender, const ToxFile& file, bool broken);
51 
52 
53 private slots:
54  void onMessageReceived(const ToxPk& sender, const Message& message);
58 
59 private:
60  void ensureIdxInSessionChatLog(ChatLogIdx idx) const;
61  void loadHistoryIntoSessionChatLog(ChatLogIdx start) const;
62  void dispatchUnsentMessages(IMessageDispatcher& messageDispatcher);
63  void handleDispatchedMessage(DispatchedMessageId dispatchId, RowId historyId);
66  bool canUseHistory() const;
68 
74 
75  // If a message completes before it's inserted into history it will end up
76  // in this set
77  QSet<DispatchedMessageId> completedMessages;
78  // If a message breaks before it's inserted into history it will end up
79  // in this set
80  QMap<DispatchedMessageId, BrokenMessageReason> brokenMessages;
81 
82  // If a message is inserted into history before it gets a completion
83  // callback it will end up in this map
84  QMap<DispatchedMessageId, RowId> dispatchedMessageRowIdMap;
85 };
ChatHistory::loadHistoryIntoSessionChatLog
void loadHistoryIntoSessionChatLog(ChatLogIdx start) const
Unconditionally loads the given index and all future messages that are not in the session chat log in...
Definition: chathistory.cpp:344
Settings
Definition: settings.h:51
ChatHistory::history
History * history
Definition: chathistory.h:70
ChatLogItem
Definition: chatlogitem.h:42
ChatHistory::getNextIdx
ChatLogIdx getNextIdx() const override
Definition: chathistory.cpp:181
history.h
ichatlog.h
ChatHistory::onMessageSent
void onMessageSent(DispatchedMessageId id, const Message &message)
Definition: chathistory.cpp:281
ChatHistory::onFileTransferRemotePausedUnpaused
void onFileTransferRemotePausedUnpaused(const ToxPk &sender, const ToxFile &file, bool paused)
Definition: chathistory.cpp:254
ParameterSearch
Definition: searchtypes.h:47
RowId
NamedType< int64_t, struct RowIdTag, Orderable > RowId
Definition: rawdatabase.h:49
ChatHistory::getFirstIdx
ChatLogIdx getFirstIdx() const override
The underlying chat log instance may not want to start at 0.
Definition: chathistory.cpp:172
ChatHistory::at
const ChatLogItem & at(ChatLogIdx idx) const override
Returns reference to item at idx.
Definition: chathistory.cpp:113
HistMessageContentType::file
@ file
ChatHistory
Definition: chathistory.h:31
brokenmessagereason.h
SystemMessage
Definition: systemmessage.h:47
IMessageDispatcher
Definition: imessagedispatcher.h:34
ChatHistory::f
Friend & f
Definition: chathistory.h:69
ChatHistory::onMessageBroken
void onMessageBroken(DispatchedMessageId id, BrokenMessageReason reason)
Definition: chathistory.cpp:312
ChatHistory::onFileTransferBrokenUnbroken
void onFileTransferBrokenUnbroken(const ToxPk &sender, const ToxFile &file, bool broken)
Definition: chathistory.cpp:260
SessionChatLog
Definition: sessionchatlog.h:31
IChatLog
Definition: ichatlog.h:83
ChatHistory::brokenMessages
QMap< DispatchedMessageId, BrokenMessageReason > brokenMessages
Definition: chathistory.h:80
ChatHistory::dispatchedMessageRowIdMap
QMap< DispatchedMessageId, RowId > dispatchedMessageRowIdMap
Definition: chathistory.h:84
ChatHistory::completedMessages
QSet< DispatchedMessageId > completedMessages
Definition: chathistory.h:77
ChatHistory::settings
const Settings & settings
Definition: chathistory.h:71
HistMessageContentType::message
@ message
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
ChatHistory::ensureIdxInSessionChatLog
void ensureIdxInSessionChatLog(ChatLogIdx idx) const
Forces the given index and all future indexes to be in the chatlog.
Definition: chathistory.cpp:328
Friend
Definition: friend.h:31
ChatHistory::handleDispatchedMessage
void handleDispatchedMessage(DispatchedMessageId dispatchId, RowId historyId)
Definition: chathistory.cpp:465
DispatchedMessageId
NamedType< size_t, struct SentMessageIdTag, Orderable, Incrementable > DispatchedMessageId
Definition: imessagedispatcher.h:31
ChatHistory::onMessageReceived
void onMessageReceived(const ToxPk &sender, const Message &message)
Definition: chathistory.cpp:265
ChatHistory::completeMessage
void completeMessage(DispatchedMessageId id)
Definition: chathistory.cpp:485
ChatHistory::breakMessage
void breakMessage(DispatchedMessageId id, BrokenMessageReason reason)
Definition: chathistory.cpp:497
ChatHistory::sessionChatLog
SessionChatLog sessionChatLog
Definition: chathistory.h:73
BrokenMessageReason
BrokenMessageReason
Definition: brokenmessagereason.h:23
ChatLogIdx
NamedType< size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable > ChatLogIdx
Definition: ichatlog.h:38
History
Interacts with the profile database to save the chat history.
Definition: history.h:135
SearchPos
Definition: ichatlog.h:41
sessionchatlog.h
ICoreIdHandler
Definition: icoreidhandler.h:25
ChatHistory::coreIdHandler
const ICoreIdHandler & coreIdHandler
Definition: chathistory.h:72
ChatHistory::onFileUpdated
void onFileUpdated(const ToxPk &sender, const ToxFile &file)
Definition: chathistory.cpp:219
ChatHistory::ChatHistory
ChatHistory(Friend &f_, History *history_, const ICoreIdHandler &coreIdHandler, const Settings &settings, IMessageDispatcher &messageDispatcher)
Definition: chathistory.cpp:73
ChatHistory::addSystemMessage
void addSystemMessage(const SystemMessage &message) override
Inserts a system message at the end of the chat.
Definition: chathistory.cpp:209
ChatHistory::searchForward
SearchResult searchForward(SearchPos startIdx, const QString &phrase, const ParameterSearch &parameter) const override
searches forwards through the chat log until phrase is found according to parameter
Definition: chathistory.cpp:122
ChatHistory::canUseHistory
bool canUseHistory() const
Definition: chathistory.cpp:509
ToxFile
Definition: toxfile.h:32
MessageState::broken
@ broken
ChatHistory::getDateIdxs
std::vector< DateChatLogIdxPair > getDateIdxs(const QDate &startDate, size_t maxDates) const override
Gets indexes for each new date starting at startDate.
Definition: chathistory.cpp:186
ChatHistory::searchBackward
SearchResult searchBackward(SearchPos startIdx, const QString &phrase, const ParameterSearch &parameter) const override
searches backwards through the chat log until phrase is found according to parameter
Definition: chathistory.cpp:138
ChatHistory::getInitialChatLogIdx
ChatLogIdx getInitialChatLogIdx() const
Gets the initial chat log index for a sessionChatLog with 0 items loaded from history....
Definition: chathistory.cpp:521
ChatHistory::onMessageComplete
void onMessageComplete(DispatchedMessageId id)
Definition: chathistory.cpp:303
Message
Definition: message.h:52
SearchResult
Definition: ichatlog.h:70
ChatHistory::dispatchUnsentMessages
void dispatchUnsentMessages(IMessageDispatcher &messageDispatcher)
Sends any unsent messages in history to the underlying message dispatcher.
Definition: chathistory.cpp:426