qTox
Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
|
Go to the documentation of this file.
58 bool handleActionPrefix(QString& content)
78 , coreIdHandler(coreIdHandler)
79 , sessionChatLog(getInitialChatLogIdx(), coreIdHandler)
99 constexpr
auto defaultNumMessagesToLoad = 100;
149 auto earliestMessageDate =
151 ? QDateTime::currentDateTime()
159 auto dateWherePhraseFound =
187 size_t maxDates)
const
191 startDate, maxDates);
193 std::vector<IChatLog::DateChatLogIdxPair> ret;
194 std::transform(counts.begin(), counts.end(), std::back_inserter(ret),
196 DateChatLogIdxPair pair;
197 pair.date = historyDateIdx.date;
198 pair.idx.get() = historyDateIdx.numMessagesIn;
222 switch (
file.status) {
232 file.filePath,
file.progress.getFileSize(), sender,
233 QDateTime::currentDateTime(), username);
241 file.hashGenerator->result());
270 auto content =
message.content;
287 auto content =
message.content;
357 assert(messages.size() ==
static_cast<int>(end.get() - start.get()));
360 for (
const auto&
message : messages) {
363 auto currentIdx = nextIdx++;
364 switch (
message.content.getType()) {
367 const auto date =
message.timestamp;
375 auto messageContent =
message.content.asMessage();
377 auto isAction = handleActionPrefix(messageContent);
385 auto processedMessage =
Message{isAction, messageContent,
message.timestamp};
387 auto dispatchedMessageIt =
389 [&](
RowId dispatchedId) { return dispatchedId == message.id; });
402 chatLogMessage, dispatchedMessageIt.key());
412 const auto& systemMessage =
message.content.asSystemMessage();
419 assert(nextIdx == end);
430 auto requiredExtensions = std::accumulate(
431 unsentMessages.begin(), unsentMessages.end(),
436 for (
auto&
message : unsentMessages) {
441 auto messageContent =
message.content.asMessage();
442 auto isAction = handleActionPrefix(messageContent);
449 auto dispatchId = requiredExtensions.none()
453 ? messageDispatcher.
sendMessage(isAction, messageContent).second
472 assert(!(isCompleted && isBroken));
477 }
else if (isBroken) {
void loadHistoryIntoSessionChatLog(ChatLogIdx start) const
Unconditionally loads the given index and all future messages that are not in the session chat log in...
ChatLogIdx getFirstIdx() const override
The underlying chat log instance may not want to start at 0.
void onMessageBroken(DispatchedMessageId id, BrokenMessageReason reason)
void setFileFinished(const QString &fileId, bool success, const QString &filePath, const QByteArray &fileHash)
ChatLogIdx getNextIdx() const override
void onFileUpdated(const ToxPk &sender, const ToxFile &file)
Updates file state in the chatlog.
std::vector< DateChatLogIdxPair > getDateIdxs(const QDate &startDate, size_t maxDates) const override
Gets indexes for each new date starting at startDate.
void onMessageSent(DispatchedMessageId id, const Message &message)
virtual QString getUsername() const =0
void onFileTransferRemotePausedUnpaused(const ToxPk &sender, const ToxFile &file, bool paused)
void markAsBroken(RowId messageId, BrokenMessageReason reason)
void onMessageSent(DispatchedMessageId id, const Message &message)
Inserts message data into the chatlog buffer.
NamedType< int64_t, struct RowIdTag, Orderable > RowId
ChatLogIdx getFirstIdx() const override
The underlying chat log instance may not want to start at 0.
const ChatLogItem & at(ChatLogIdx idx) const override
Returns reference to item at idx.
virtual std::pair< DispatchedMessageId, DispatchedMessageId > sendMessage(bool isAction, const QString &content)=0
Sends message to associated chat.
SearchResult searchBackward(SearchPos startIdx, const QString &phrase, const ParameterSearch ¶meter) const override
searches backwards through the chat log until phrase is found according to parameter
void onMessageBroken(DispatchedMessageId id, BrokenMessageReason reason)
void messageSent(DispatchedMessageId id, const Message &message)
Emitted when a message is processed and sent.
void addSystemMessage(const SystemMessage &message) override
Inserts a system message at the end of the chat.
ExtensionSet extensionSet
void onFileTransferBrokenUnbroken(const ToxPk &sender, const ToxFile &file, bool broken)
ContentType getContentType() const
void onFileTransferRemotePausedUnpaused(const ToxPk &sender, const ToxFile &file, bool paused)
const ChatLogItem & at(ChatLogIdx idx) const override
Returns reference to item at idx.
void onFileTransferBrokenUnbroken(const ToxPk &sender, const ToxFile &file, bool broken)
void insertBrokenMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message)
void addNewSystemMessage(const ToxPk &friendPk, const SystemMessage &systemMessage)
void markAsDelivered(RowId messageId)
Marks a message as delivered. Removing message from the faux-offline pending messages list.
QMap< DispatchedMessageId, BrokenMessageReason > brokenMessages
size_t getNumMessagesForFriendBeforeDate(const ToxPk &friendPk, const QDateTime &date)
QMap< DispatchedMessageId, RowId > dispatchedMessageRowIdMap
QSet< DispatchedMessageId > completedMessages
QList< HistMessage > getUndeliveredMessagesForFriend(const ToxPk &friendPk)
const Settings & settings
void messageComplete(DispatchedMessageId id)
Emitted when a receiver report is received from the associated chat.
void insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message)
This class represents a Tox Public Key, which is a part of Tox ID.
void ensureIdxInSessionChatLog(ChatLogIdx idx) const
Forces the given index and all future indexes to be in the chatlog.
ChatLogIdx getNextIdx() const override
QList< DateIdx > getNumMessagesForFriendBeforeDateBoundaries(const ToxPk &friendPk, const QDate &from, size_t maxNum)
Gets date boundaries in conversation with friendPk. History doesn't model conversation indexes,...
virtual ToxPk getSelfPublicKey() const =0
void handleDispatchedMessage(DispatchedMessageId dispatchId, RowId historyId)
QList< HistMessage > getMessagesForFriend(const ToxPk &friendPk, size_t firstIdx, size_t lastIdx)
NamedType< size_t, struct SentMessageIdTag, Orderable, Incrementable > DispatchedMessageId
void onMessageReceived(const ToxPk &sender, const Message &message)
void completeMessage(DispatchedMessageId id)
void breakMessage(DispatchedMessageId id, BrokenMessageReason reason)
void itemUpdated(ChatLogIdx idx)
void insertIncompleteMessageAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogMessage &message, DispatchedMessageId dispatchId)
SessionChatLog sessionChatLog
QString getDisplayedName() const override
Friend::getDisplayedName Gets the name that should be displayed for a user.
NamedType< size_t, struct ChatLogIdxTag, Orderable, UnderlyingAddable, UnitlessDifferencable, Incrementable > ChatLogIdx
ChatLogMessage & getContentAsMessage()
std::bitset< ExtensionType::max > ExtensionSet
Interacts with the profile database to save the chat history.
void addNewFileMessage(const ToxPk &friendPk, const QString &fileId, const QString &fileName, const QString &filePath, int64_t size, const ToxPk &sender, const QDateTime &time, QString const &dispName)
size_t getNumMessagesForFriend(const ToxPk &friendPk)
bool getEnableLogging() const
const ToxPk & getPublicKey() const
void insertSystemMessageAtIdx(ChatLogIdx idx, SystemMessage message)
SearchResult searchForward(SearchPos startIdx, const QString &phrase, const ParameterSearch ¶meter) const override
searches forwards through the chat log until phrase is found according to parameter
void messageReceived(const ToxPk &sender, const Message &message)
Emitted when a message is received and processed.
void addNewMessage(const ToxPk &friendPk, const QString &message, const ToxPk &sender, const QDateTime &time, bool isDelivered, ExtensionSet extensions, QString dispName, const std::function< void(RowId)> &insertIdCallback={})
Saves a chat message in the database.
const ICoreIdHandler & coreIdHandler
virtual std::pair< DispatchedMessageId, DispatchedMessageId > sendExtendedMessage(const QString &content, ExtensionSet extensions)=0
Sends message to associated chat ensuring that extensions are available.
void onFileUpdated(const ToxPk &sender, const ToxFile &file)
ChatHistory(Friend &f_, History *history_, const ICoreIdHandler &coreIdHandler, const Settings &settings, IMessageDispatcher &messageDispatcher)
void addSystemMessage(const SystemMessage &message) override
Inserts a system message at the end of the chat.
void onMessageReceived(const ToxPk &sender, const Message &message)
Inserts message data into the chatlog buffer.
void onMessageComplete(DispatchedMessageId id)
Marks the associated message as complete and notifies any listeners.
SearchResult searchForward(SearchPos startIdx, const QString &phrase, const ParameterSearch ¶meter) const override
searches forwards through the chat log until phrase is found according to parameter
bool canUseHistory() const
QDateTime getDateWhereFindPhrase(const ToxPk &friendPk, const QDateTime &from, QString phrase, const ParameterSearch ¶meter)
Search phrase in chat messages.
void insertFileAtIdx(ChatLogIdx idx, const ToxPk &sender, QString senderName, const ChatLogFile &file)
std::vector< DateChatLogIdxPair > getDateIdxs(const QDate &startDate, size_t maxDates) const override
Gets indexes for each new date starting at startDate.
SearchResult searchBackward(SearchPos startIdx, const QString &phrase, const ParameterSearch ¶meter) const override
searches backwards through the chat log until phrase is found according to parameter
void messageBroken(DispatchedMessageId id, BrokenMessageReason reason)
ChatLogIdx getInitialChatLogIdx() const
Gets the initial chat log index for a sessionChatLog with 0 items loaded from history....
void onMessageComplete(DispatchedMessageId id)
void dispatchUnsentMessages(IMessageDispatcher &messageDispatcher)
Sends any unsent messages in history to the underlying message dispatcher.