X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorebacklogmanager.cpp;h=8a974a191afbec7d999120ba45b93173284954e5;hp=90004cafa741e1612c6cbd6c17cf98a07e6b5cd3;hb=c194ed5fb3d15e14b9364f9796d3521910dc72fe;hpb=52f0d47d0cb1932c9e86ebb75cdd4dd0d625dd6f diff --git a/src/core/corebacklogmanager.cpp b/src/core/corebacklogmanager.cpp index 90004caf..8a974a19 100644 --- a/src/core/corebacklogmanager.cpp +++ b/src/core/corebacklogmanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 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 * @@ -24,7 +24,6 @@ #include -INIT_SYNCABLE_OBJECT(CoreBacklogManager) CoreBacklogManager::CoreBacklogManager(CoreSession *coreSession) : BacklogManager(coreSession), _coreSession(coreSession) @@ -78,6 +77,52 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, } +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; + } + } + } + + return backlog; +} + + QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int limit, int additional) { QVariantList backlog; @@ -115,3 +160,43 @@ QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int 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; + } + } + + return backlog; +}