qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
sessionchatlog.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 "imessagedispatcher.h"
24 
25 #include <QList>
26 #include <QObject>
27 
28 struct SessionChatLogMetadata;
29 
30 
31 class SessionChatLog : public IChatLog
32 {
33  Q_OBJECT
34 public:
37 
39  const ChatLogItem& at(ChatLogIdx idx) const override;
40  SearchResult searchForward(SearchPos startIdx, const QString& phrase,
41  const ParameterSearch& parameter) const override;
42  SearchResult searchBackward(SearchPos startIdx, const QString& phrase,
43  const ParameterSearch& parameter) const override;
44  ChatLogIdx getFirstIdx() const override;
45  ChatLogIdx getNextIdx() const override;
46  std::vector<DateChatLogIdxPair> getDateIdxs(const QDate& startDate, size_t maxDates) const override;
47  void addSystemMessage(const SystemMessage& message) override;
48 
49  void insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName,
50  const ChatLogMessage& message);
51  void insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName,
52  const ChatLogMessage& message, DispatchedMessageId dispatchId);
53  void insertBrokenMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName,
54  const ChatLogMessage& message);
55  void insertFileAtIdx(ChatLogIdx idx, const ToxPk& sender, QString senderName, const ChatLogFile& file);
57 
58 public slots:
59  void onMessageReceived(const ToxPk& sender, const Message& message);
63 
64  void onFileUpdated(const ToxPk& sender, const ToxFile& file);
65  void onFileTransferRemotePausedUnpaused(const ToxPk& sender, const ToxFile& file, bool paused);
66  void onFileTransferBrokenUnbroken(const ToxPk& sender, const ToxFile& file, bool broken);
67 
68 
69 private:
70  QString resolveSenderNameFromSender(const ToxPk &sender);
71 
72 
73 private:
75 
77 
78  std::map<ChatLogIdx, ChatLogItem> items;
79 
81  {
84  };
85 
91  std::vector<CurrentFileTransfer> currentFileTransfers;
92 
97  QMap<DispatchedMessageId, ChatLogIdx> outgoingMessages;
98 };
SessionChatLog::getFirstIdx
ChatLogIdx getFirstIdx() const override
The underlying chat log instance may not want to start at 0.
Definition: sessionchatlog.cpp:280
SessionChatLog::onMessageBroken
void onMessageBroken(DispatchedMessageId id, BrokenMessageReason reason)
Definition: sessionchatlog.cpp:439
ChatLogItem
Definition: chatlogitem.h:42
SessionChatLog::onFileUpdated
void onFileUpdated(const ToxPk &sender, const ToxFile &file)
Updates file state in the chatlog.
Definition: sessionchatlog.cpp:467
ichatlog.h
SessionChatLog::getDateIdxs
std::vector< DateChatLogIdxPair > getDateIdxs(const QDate &startDate, size_t maxDates) const override
Gets indexes for each new date starting at startDate.
Definition: sessionchatlog.cpp:294
SessionChatLog::CurrentFileTransfer::idx
ChatLogIdx idx
Definition: sessionchatlog.h:82
ParameterSearch
Definition: searchtypes.h:47
SessionChatLog::onMessageSent
void onMessageSent(DispatchedMessageId id, const Message &message)
Inserts message data into the chatlog buffer.
Definition: sessionchatlog.cpp:397
SessionChatLog::CurrentFileTransfer
Definition: sessionchatlog.h:80
HistMessageContentType::file
@ file
SessionChatLog::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: sessionchatlog.cpp:213
SessionChatLog::outgoingMessages
QMap< DispatchedMessageId, ChatLogIdx > outgoingMessages
Definition: sessionchatlog.h:97
SystemMessage
Definition: systemmessage.h:47
SessionChatLog::addSystemMessage
void addSystemMessage(const SystemMessage &message) override
Inserts a system message at the end of the chat.
Definition: sessionchatlog.cpp:322
SessionChatLog
Definition: sessionchatlog.h:31
SessionChatLog::onFileTransferRemotePausedUnpaused
void onFileTransferRemotePausedUnpaused(const ToxPk &sender, const ToxFile &file, bool paused)
Definition: sessionchatlog.cpp:501
IChatLog
Definition: ichatlog.h:83
SessionChatLog::at
const ChatLogItem & at(ChatLogIdx idx) const override
Returns reference to item at idx.
Definition: sessionchatlog.cpp:150
SessionChatLog::onFileTransferBrokenUnbroken
void onFileTransferBrokenUnbroken(const ToxPk &sender, const ToxFile &file, bool broken)
Definition: sessionchatlog.cpp:507
SessionChatLog::insertBrokenMessageAtIdx
void insertBrokenMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message)
Definition: sessionchatlog.cpp:353
SessionChatLog::coreIdHandler
const ICoreIdHandler & coreIdHandler
Definition: sessionchatlog.h:74
HistMessageContentType::message
@ message
SessionChatLog::insertCompleteMessageAtIdx
void insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message)
Definition: sessionchatlog.cpp:331
ToxPk
This class represents a Tox Public Key, which is a part of Tox ID.
Definition: toxpk.h:26
SessionChatLog::getNextIdx
ChatLogIdx getNextIdx() const override
Definition: sessionchatlog.cpp:289
ChatLogMessage
Definition: chatlogitem.h:30
DispatchedMessageId
NamedType< size_t, struct SentMessageIdTag, Orderable, Incrementable > DispatchedMessageId
Definition: imessagedispatcher.h:31
SessionChatLog::currentFileTransfers
std::vector< CurrentFileTransfer > currentFileTransfers
Definition: sessionchatlog.h:91
SessionChatLog::insertIncompleteMessageAtIdx
void insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message, DispatchedMessageId dispatchId)
Definition: sessionchatlog.cpp:341
SessionChatLog::SessionChatLog
SessionChatLog(const ICoreIdHandler &coreIdHandler)
Definition: sessionchatlog.cpp:128
BrokenMessageReason
BrokenMessageReason
Definition: brokenmessagereason.h:23
SessionChatLog::items
std::map< ChatLogIdx, ChatLogItem > items
Definition: sessionchatlog.h:78
SessionChatLog::CurrentFileTransfer::file
ToxFile file
Definition: sessionchatlog.h:83
ChatLogIdx
NamedType< size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable > ChatLogIdx
Definition: ichatlog.h:38
SearchPos
Definition: ichatlog.h:41
SessionChatLog::~SessionChatLog
~SessionChatLog()
ICoreIdHandler
Definition: icoreidhandler.h:25
SessionChatLog::insertSystemMessageAtIdx
void insertSystemMessageAtIdx(ChatLogIdx idx, SystemMessage message)
Definition: sessionchatlog.cpp:370
SessionChatLog::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: sessionchatlog.cpp:160
SessionChatLog::resolveSenderNameFromSender
QString resolveSenderNameFromSender(const ToxPk &sender)
Definition: sessionchatlog.cpp:142
SessionChatLog::onMessageReceived
void onMessageReceived(const ToxPk &sender, const Message &message)
Inserts message data into the chatlog buffer.
Definition: sessionchatlog.cpp:381
SessionChatLog::onMessageComplete
void onMessageComplete(DispatchedMessageId id)
Marks the associated message as complete and notifies any listeners.
Definition: sessionchatlog.cpp:417
imessagedispatcher.h
ToxFile
Definition: toxfile.h:32
MessageState::broken
@ broken
SessionChatLog::insertFileAtIdx
void insertFileAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogFile &file)
Definition: sessionchatlog.cpp:363
SessionChatLog::nextIdx
ChatLogIdx nextIdx
Definition: sessionchatlog.h:76
Message
Definition: message.h:52
SearchResult
Definition: ichatlog.h:70
ChatLogFile
Definition: chatlogitem.h:36