1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "corebacklogmanager.h"
26 #include "coresession.h"
28 CoreBacklogManager::CoreBacklogManager(CoreSession* coreSession)
29 : BacklogManager(coreSession)
30 , _coreSession(coreSession)
33 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();
62 // only fetch additional messages if they continue seemlessly
63 // that is, if the list of messages is not truncated by the limit
64 if (last == oldestMessage) {
65 msgList = Core::requestMsgs(coreSession()->user(), bufferId, -1, last, additional);
66 msgIter = msgList.constBegin();
67 msgListEnd = msgList.constEnd();
68 while (msgIter != msgListEnd) {
69 backlog << qVariantFromValue(*msgIter);
78 QVariantList CoreBacklogManager::requestBacklogFiltered(BufferId bufferId, MsgId first, MsgId last, int limit, int additional, int type, int flags)
81 QList<Message> msgList;
82 msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, first, last, limit, Message::Types{type}, Message::Flags{flags});
84 QList<Message>::const_iterator msgIter = msgList.constBegin();
85 QList<Message>::const_iterator msgListEnd = msgList.constEnd();
86 while (msgIter != msgListEnd) {
87 backlog << qVariantFromValue(*msgIter);
91 if (additional && limit != 0) {
92 MsgId oldestMessage = first;
93 if (!msgList.isEmpty()) {
94 if (msgList.first().msgId() < msgList.last().msgId())
95 oldestMessage = msgList.first().msgId();
97 oldestMessage = msgList.last().msgId();
104 last = oldestMessage;
107 // only fetch additional messages if they continue seemlessly
108 // that is, if the list of messages is not truncated by the limit
109 if (last == oldestMessage) {
110 msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, -1, last, additional, Message::Types{type}, Message::Flags{flags});
111 msgIter = msgList.constBegin();
112 msgListEnd = msgList.constEnd();
113 while (msgIter != msgListEnd) {
114 backlog << qVariantFromValue(*msgIter);
123 QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int limit, int additional)
125 QVariantList backlog;
126 QList<Message> msgList;
127 msgList = Core::requestAllMsgs(coreSession()->user(), first, last, limit);
129 QList<Message>::const_iterator msgIter = msgList.constBegin();
130 QList<Message>::const_iterator msgListEnd = msgList.constEnd();
131 while (msgIter != msgListEnd) {
132 backlog << qVariantFromValue(*msgIter);
142 if (!msgList.isEmpty()) {
143 if (msgList.first().msgId() < msgList.last().msgId())
144 last = msgList.first().msgId();
146 last = msgList.last().msgId();
149 msgList = Core::requestAllMsgs(coreSession()->user(), -1, last, additional);
150 msgIter = msgList.constBegin();
151 msgListEnd = msgList.constEnd();
152 while (msgIter != msgListEnd) {
153 backlog << qVariantFromValue(*msgIter);
161 QVariantList CoreBacklogManager::requestBacklogAllFiltered(MsgId first, MsgId last, int limit, int additional, int type, int flags)
163 QVariantList backlog;
164 QList<Message> msgList;
165 msgList = Core::requestAllMsgsFiltered(coreSession()->user(), first, last, limit, Message::Types{type}, Message::Flags{flags});
167 QList<Message>::const_iterator msgIter = msgList.constBegin();
168 QList<Message>::const_iterator msgListEnd = msgList.constEnd();
169 while (msgIter != msgListEnd) {
170 backlog << qVariantFromValue(*msgIter);
180 if (!msgList.isEmpty()) {
181 if (msgList.first().msgId() < msgList.last().msgId())
182 last = msgList.first().msgId();
184 last = msgList.last().msgId();
187 msgList = Core::requestAllMsgsFiltered(coreSession()->user(), -1, last, additional, Message::Types{type}, Message::Flags{flags});
188 msgIter = msgList.constBegin();
189 msgListEnd = msgList.constEnd();
190 while (msgIter != msgListEnd) {
191 backlog << qVariantFromValue(*msgIter);