1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(history): check history settings when getting initial chatlog idx

Checking if history pointer is valid is not sufficient, the setting must also
be checked. This caused asserts in history when history was disabled in
settings.
This commit is contained in:
Anthony Bilinski 2020-03-21 01:45:34 -07:00
parent b5785a1b0c
commit c906cdf57b
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 18 additions and 18 deletions

View File

@ -33,22 +33,6 @@ bool needsLoadFromHistory(ChatLogIdx idx, const SessionChatLog& sessionChatLog)
return idx < sessionChatLog.getFirstIdx();
}
/**
* @brief Gets the initial chat log index for a sessionChatLog with 0 items loaded from history.
* Needed to keep history indexes in sync with chat log indexes
* @param[in] history
* @param[in] f
* @return Initial chat log index
*/
ChatLogIdx getInitialChatLogIdx(History* history, Friend& f)
{
if (!history) {
return ChatLogIdx(0);
}
return ChatLogIdx(history->getNumMessagesForFriend(f.getPublicKey()));
}
/**
* @brief Finds the first item in sessionChatLog that contains a message
* @param[in] sessionChatLog
@ -90,9 +74,9 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co
const Settings& settings_, IMessageDispatcher& messageDispatcher)
: f(f_)
, history(history_)
, sessionChatLog(getInitialChatLogIdx(history, f), coreIdHandler)
, settings(settings_)
, coreIdHandler(coreIdHandler)
, sessionChatLog(getInitialChatLogIdx(), coreIdHandler)
{
connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this,
&ChatHistory::onMessageComplete);
@ -481,3 +465,18 @@ bool ChatHistory::canUseHistory() const
{
return history && settings.getEnableLogging();
}
/**
* @brief Gets the initial chat log index for a sessionChatLog with 0 items loaded from history.
* Needed to keep history indexes in sync with chat log indexes
* @param[in] history
* @param[in] f
* @return Initial chat log index
*/
ChatLogIdx ChatHistory::getInitialChatLogIdx() const
{
if (canUseHistory()) {
return ChatLogIdx(history->getNumMessagesForFriend(f.getPublicKey()));
}
return ChatLogIdx(0);
}

View File

@ -61,12 +61,13 @@ private:
void handleDispatchedMessage(DispatchedMessageId dispatchId, RowId historyId);
void completeMessage(DispatchedMessageId id);
bool canUseHistory() const;
ChatLogIdx getInitialChatLogIdx() const;
Friend& f;
History* history;
mutable SessionChatLog sessionChatLog;
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