1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "corebacklogmanager.h"
23 #include "coresession.h"
27 INIT_SYNCABLE_OBJECT(CoreBacklogManager)
28 CoreBacklogManager::CoreBacklogManager(CoreSession *coreSession)
29 : BacklogManager(coreSession),
30 _coreSession(coreSession)
34 QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, int additional) {
36 QList<Message> msgList;
37 msgList = Core::requestMsgs(coreSession()->user(), bufferId, first, last, limit);
39 QList<Message>::const_iterator msgIter = msgList.constBegin();
40 QList<Message>::const_iterator msgListEnd = msgList.constEnd();
41 while(msgIter != msgListEnd) {
42 backlog << qVariantFromValue(*msgIter);
46 if(additional && limit != 0) {
47 MsgId oldestMessage = first;
48 if(!msgList.isEmpty()) {
49 if(msgList.first().msgId() < msgList.last().msgId())
50 oldestMessage = msgList.first().msgId();
52 oldestMessage = msgList.last().msgId();
61 // only fetch additional messages if they continue seemlessly
62 // that is, if the list of messages is not truncated by the limit
63 if(last == oldestMessage) {
64 msgList = Core::requestMsgs(coreSession()->user(), bufferId, -1, last, additional);
65 msgIter = msgList.constBegin();
66 msgListEnd = msgList.constEnd();
67 while(msgIter != msgListEnd) {
68 backlog << qVariantFromValue(*msgIter);
77 QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int limit, int additional) {
79 QList<Message> msgList;
80 msgList = Core::requestAllMsgs(coreSession()->user(), first, last, limit);
82 QList<Message>::const_iterator msgIter = msgList.constBegin();
83 QList<Message>::const_iterator msgListEnd = msgList.constEnd();
84 while(msgIter != msgListEnd) {
85 backlog << qVariantFromValue(*msgIter);
94 if(!msgList.isEmpty()) {
95 if(msgList.first().msgId() < msgList.last().msgId())
96 last = msgList.first().msgId();
98 last = msgList.last().msgId();
101 msgList = Core::requestAllMsgs(coreSession()->user(), -1, last, additional);
102 msgIter = msgList.constBegin();
103 msgListEnd = msgList.constEnd();
104 while(msgIter != msgListEnd) {
105 backlog << qVariantFromValue(*msgIter);