X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcorebacklogmanager.cpp;h=1c3fae98b5604592b6626db83e12c8f2b8605c95;hp=7c79cb7d7b03092814aaf4c6e824193567e4da1d;hb=b64a1e62e2168dc21e350fccc6c42b0d0d5e2a35;hpb=8ec76e512d20ce5d1dc76de556bb98a06b75d695 diff --git a/src/core/corebacklogmanager.cpp b/src/core/corebacklogmanager.cpp index 7c79cb7d..1c3fae98 100644 --- a/src/core/corebacklogmanager.cpp +++ b/src/core/corebacklogmanager.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -24,16 +24,17 @@ #include +INIT_SYNCABLE_OBJECT(CoreBacklogManager) CoreBacklogManager::CoreBacklogManager(CoreSession *coreSession) : BacklogManager(coreSession), _coreSession(coreSession) { } -QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, int lastMsgs, int offset) { +QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, int additional) { QVariantList backlog; QList msgList; - msgList = Core::requestMsgs(coreSession()->user(), bufferId, lastMsgs, offset); + msgList = Core::requestMsgs(coreSession()->user(), bufferId, first, last, limit); QList::const_iterator msgIter = msgList.constBegin(); QList::const_iterator msgListEnd = msgList.constEnd(); @@ -41,5 +42,70 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, int lastMsgs, backlog << qVariantFromValue(*msgIter); msgIter++; } + + if(additional) { + MsgId oldestMessage; + 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::requestMsgs(coreSession()->user(), bufferId, -1, last, additional); + 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; + QList msgList; + msgList = Core::requestAllMsgs(coreSession()->user(), first, last, limit); + + 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::requestAllMsgs(coreSession()->user(), -1, last, additional); + msgIter = msgList.constBegin(); + msgListEnd = msgList.constEnd(); + while(msgIter != msgListEnd) { + backlog << qVariantFromValue(*msgIter); + msgIter++; + } + } + return backlog; }