X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fmessagemodel.cpp;h=76914bffec90c06e2652e4e7108930bde025cffc;hp=fd59ddb27460b253d246e08c9facc0e3fcc4c6a5;hb=HEAD;hpb=c1cf157116de7fc3da96203aa6f03c38c7ebb650 diff --git a/src/client/messagemodel.cpp b/src/client/messagemodel.cpp index fd59ddb2..6c93a7f6 100644 --- a/src/client/messagemodel.cpp +++ b/src/client/messagemodel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,8 @@ #include "messagemodel.h" +#include + #include #include "backlogsettings.h" @@ -105,13 +107,13 @@ void MessageModel::insertMessages(const QList& msglist) else { _messageBuffer = msglist.mid(processedMsgs); } - qSort(_messageBuffer); + std::sort(_messageBuffer.begin(), _messageBuffer.end()); QCoreApplication::postEvent(this, new ProcessBufferEvent()); } } else { _messageBuffer << msglist; - qSort(_messageBuffer); + std::sort(_messageBuffer.begin(), _messageBuffer.end()); } } @@ -125,7 +127,7 @@ void MessageModel::insertMessageGroup(const QList& msglist) Message dayChangeMsg; if (start > 0) { - // check if the preceeding msg is a daychange message and if so if + // check if the preceding msg is a daychange message and if so if // we have to drop or relocate it at the end of this chunk int prevIdx = start - 1; if (messageItemAt(prevIdx)->msgType() == Message::DayChange && messageItemAt(prevIdx)->timestamp() > msglist.at(0).timestamp()) { @@ -148,7 +150,7 @@ void MessageModel::insertMessageGroup(const QList& msglist) // check if we need to insert a daychange message at the end of the this group // if this assert triggers then indexForId() would have found a spot right before a DayChangeMsg - // this should never happen as daychange messages share the msgId with the preceeding message + // this should never happen as daychange messages share the msgId with the preceding message Q_ASSERT(messageItemAt(start)->msgType() != Message::DayChange); QDateTime nextTs = messageItemAt(start)->timestamp(); QDateTime prevTs = msglist.last().timestamp(); @@ -186,7 +188,7 @@ int MessageModel::insertMessagesGracefully(const QList& msglist) /* short description: * 1) first we check where the message with the highest msgId from msglist would be inserted * 2) check that position for dupe - * 3) determine the messageId of the preceeding msg + * 3) determine the messageId of the preceding msg * 4) insert as many msgs from msglist with with msgId larger then the just determined id * those messages are automatically less then the msg of the position we just determined in 1) */ @@ -202,7 +204,7 @@ int MessageModel::insertMessagesGracefully(const QList& msglist) QList::const_iterator iter; if (inOrder) { iter = msglist.constEnd(); - --iter; // this op is safe as we've allready passed an empty check + --iter; // this op is safe as we've already passed an empty check } else { iter = msglist.constBegin(); @@ -391,17 +393,35 @@ void MessageModel::requestBacklog(BufferId bufferId) BacklogSettings backlogSettings; int requestCount = backlogSettings.dynamicBacklogAmount(); + // Assume there's no available messages + MsgId oldestAvailableMsgId{-1}; + + // Try to find the oldest (lowest ID) message belonging to this buffer for (int i = 0; i < messageCount(); i++) { if (messageItemAt(i)->bufferId() == bufferId) { - _messagesWaiting[bufferId] = requestCount; - Client::backlogManager()->emitMessagesRequested(tr("Requesting %1 messages from backlog for buffer %2:%3") - .arg(requestCount) - .arg(Client::networkModel()->networkName(bufferId)) - .arg(Client::networkModel()->bufferName(bufferId))); - Client::backlogManager()->requestBacklog(bufferId, -1, messageItemAt(i)->msgId(), requestCount); - return; + // Match found, use this message ID for requesting more backlog + oldestAvailableMsgId = messageItemAt(i)->msgId(); + break; } } + + // Prepare to fetch messages + _messagesWaiting[bufferId] = requestCount; + Client::backlogManager()->emitMessagesRequested(tr("Requesting %1 messages from backlog for buffer %2:%3") + .arg(requestCount) + .arg(Client::networkModel()->networkName(bufferId)) + .arg(Client::networkModel()->bufferName(bufferId))); + + if (oldestAvailableMsgId.isValid()) { + // Request messages from backlog starting from this message ID, going into the past + Client::backlogManager()->requestBacklog(bufferId, -1, oldestAvailableMsgId, requestCount); + } + else { + // No existing messages could be found. Try to fetch the newest available messages instead. + // This may happen when initial backlog fetching is set to zero, or if no messages exist in + // a buffer. + Client::backlogManager()->requestBacklog(bufferId, -1, -1, requestCount); + } } void MessageModel::messagesReceived(BufferId bufferId, int count) @@ -437,11 +457,11 @@ QVariant MessageModelItem::data(int column, int role) const switch (role) { case MessageModel::MessageRole: - return QVariant::fromValue(message()); + return QVariant::fromValue(message()); case MessageModel::MsgIdRole: - return QVariant::fromValue(msgId()); + return QVariant::fromValue(msgId()); case MessageModel::BufferIdRole: - return QVariant::fromValue(bufferId()); + return QVariant::fromValue(bufferId()); case MessageModel::TypeRole: return msgType(); case MessageModel::FlagsRole: @@ -449,9 +469,9 @@ QVariant MessageModelItem::data(int column, int role) const case MessageModel::TimestampRole: return timestamp(); case MessageModel::RedirectedToRole: - return qVariantFromValue(_redirectedTo); + return QVariant::fromValue(_redirectedTo); default: - return QVariant(); + return {}; } }