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"
29 #include "coresession.h"
31 CoreBacklogManager::CoreBacklogManager(CoreSession* coreSession)
32 : BacklogManager(coreSession)
33 , _coreSession(coreSession)
36 QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, int additional)
39 auto msgList = Core::requestMsgs(coreSession()->user(), bufferId, first, last, limit);
41 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
42 return QVariant::fromValue(msg);
45 if (additional && limit != 0) {
46 MsgId oldestMessage = first;
47 if (!msgList.empty()) {
48 if (msgList.front().msgId() < msgList.back().msgId())
49 oldestMessage = msgList.front().msgId();
51 oldestMessage = msgList.back().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 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
66 return QVariant::fromValue(msg);
74 QVariantList CoreBacklogManager::requestBacklogFiltered(BufferId bufferId, MsgId first, MsgId last, int limit, int additional, int type, int flags)
77 auto msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, first, last, limit, Message::Types{type}, Message::Flags{flags});
79 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
80 return QVariant::fromValue(msg);
83 if (additional && limit != 0) {
84 MsgId oldestMessage = first;
85 if (!msgList.empty()) {
86 if (msgList.front().msgId() < msgList.back().msgId())
87 oldestMessage = msgList.front().msgId();
89 oldestMessage = msgList.back().msgId();
99 // only fetch additional messages if they continue seemlessly
100 // that is, if the list of messages is not truncated by the limit
101 if (last == oldestMessage) {
102 msgList = Core::requestMsgsFiltered(coreSession()->user(), bufferId, -1, last, additional, Message::Types{type}, Message::Flags{flags});
103 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
104 return QVariant::fromValue(msg);
112 QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int limit, int additional)
114 QVariantList backlog;
115 auto msgList = Core::requestAllMsgs(coreSession()->user(), first, last, limit);
117 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
118 return QVariant::fromValue(msg);
127 if (!msgList.empty()) {
128 if (msgList.front().msgId() < msgList.back().msgId())
129 last = msgList.front().msgId();
131 last = msgList.back().msgId();
134 msgList = Core::requestAllMsgs(coreSession()->user(), -1, last, additional);
135 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
136 return QVariant::fromValue(msg);
143 QVariantList CoreBacklogManager::requestBacklogAllFiltered(MsgId first, MsgId last, int limit, int additional, int type, int flags)
145 QVariantList backlog;
146 auto msgList = Core::requestAllMsgsFiltered(coreSession()->user(), first, last, limit, Message::Types{type}, Message::Flags{flags});
148 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
149 return QVariant::fromValue(msg);
158 if (!msgList.empty()) {
159 if (msgList.front().msgId() < msgList.back().msgId())
160 last = msgList.front().msgId();
162 last = msgList.back().msgId();
165 msgList = Core::requestAllMsgsFiltered(coreSession()->user(), -1, last, additional, Message::Types{type}, Message::Flags{flags});
166 std::transform(msgList.cbegin(), msgList.cend(), std::back_inserter(backlog), [](auto&& msg) {
167 return QVariant::fromValue(msg);