X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorebacklogmanager.cpp;h=73e180558ebacb4557b8eb75a52eafe0e916b371;hp=371ae60224fb8f37ec89d26dbdf48811370ef17a;hb=b9169a652a6854b3fa85aee8f833cb9e18a8d510;hpb=4a5065255e652dd0c301bac0db41b7afb777ef49 diff --git a/src/core/corebacklogmanager.cpp b/src/core/corebacklogmanager.cpp index 371ae602..73e18055 100644 --- a/src/core/corebacklogmanager.cpp +++ b/src/core/corebacklogmanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -42,7 +42,7 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, QList::const_iterator msgListEnd = msgList.constEnd(); while (msgIter != msgListEnd) { backlog << qVariantFromValue(*msgIter); - msgIter++; + ++msgIter; } if (additional && limit != 0) { @@ -69,7 +69,53 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, msgListEnd = msgList.constEnd(); while (msgIter != msgListEnd) { backlog << qVariantFromValue(*msgIter); - msgIter++; + ++msgIter; + } + } + } + + return backlog; +} + + +QVariantList CoreBacklogManager::requestBacklogFiltered(BufferId bufferId, MsgId first, MsgId last, int limit, int additional, int type, int flags) +{ + QVariantList backlog; + QList msgList; + msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, first, last, limit, Message::Types{type}, Message::Flags{flags}); + + QList::const_iterator msgIter = msgList.constBegin(); + QList::const_iterator msgListEnd = msgList.constEnd(); + while (msgIter != msgListEnd) { + backlog << qVariantFromValue(*msgIter); + ++msgIter; + } + + if (additional && limit != 0) { + MsgId oldestMessage = first; + if (!msgList.isEmpty()) { + if (msgList.first().msgId() < msgList.last().msgId()) + oldestMessage = msgList.first().msgId(); + else + oldestMessage = msgList.last().msgId(); + } + + if (first != -1) { + last = first; + } + else { + last = oldestMessage; + } + + // only fetch additional messages if they continue seemlessly + // that is, if the list of messages is not truncated by the limit + if (last == oldestMessage) { + msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, -1, last, additional, Message::Types{type}, Message::Flags{flags}); + msgIter = msgList.constBegin(); + msgListEnd = msgList.constEnd(); + while (msgIter != msgListEnd) { + backlog << qVariantFromValue(*msgIter); + ++msgIter; } } } @@ -88,7 +134,7 @@ QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int QList::const_iterator msgListEnd = msgList.constEnd(); while (msgIter != msgListEnd) { backlog << qVariantFromValue(*msgIter); - msgIter++; + ++msgIter; } if (additional) { @@ -109,7 +155,47 @@ QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int msgListEnd = msgList.constEnd(); while (msgIter != msgListEnd) { backlog << qVariantFromValue(*msgIter); - msgIter++; + ++msgIter; + } + } + + return backlog; +} + + +QVariantList CoreBacklogManager::requestBacklogAllFiltered(MsgId first, MsgId last, int limit, int additional, int type, + int flags) +{ + QVariantList backlog; + QList msgList; + msgList = Core::requestAllMsgsFiltered(coreSession()->user(), first, last, limit, Message::Types{type}, Message::Flags{flags}); + + QList::const_iterator msgIter = msgList.constBegin(); + QList::const_iterator msgListEnd = msgList.constEnd(); + while (msgIter != msgListEnd) { + backlog << qVariantFromValue(*msgIter); + ++msgIter; + } + + if (additional) { + if (first != -1) { + last = first; + } + else { + last = -1; + if (!msgList.isEmpty()) { + if (msgList.first().msgId() < msgList.last().msgId()) + last = msgList.first().msgId(); + else + last = msgList.last().msgId(); + } + } + msgList = Core::requestAllMsgsFiltered(coreSession()->user(), -1, last, additional, Message::Types{type}, Message::Flags{flags}); + msgIter = msgList.constBegin(); + msgListEnd = msgList.constEnd(); + while (msgIter != msgListEnd) { + backlog << qVariantFromValue(*msgIter); + ++msgIter; } }