|
| 1 | +/* |
| 2 | + * xmpp_mammanager.cpp - XEP-0313 Message Archive Management |
| 3 | + * Copyright (C) 2024 mcneb10 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2.1 of the License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library 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 GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +#include "xmpp_mammanager.h" |
| 21 | + |
| 22 | +using namespace XMPP; |
| 23 | + |
| 24 | +class MAMManager::Private { |
| 25 | +public: |
| 26 | + int mamPageSize; |
| 27 | + int mamMaxMessages; |
| 28 | + bool flipPages; |
| 29 | + bool backwards; |
| 30 | + Client *client; |
| 31 | +}; |
| 32 | + |
| 33 | +MAMManager::MAMManager(Client *client, int mamPageSize, int mamMaxMessages, bool flipPages, bool backwards) |
| 34 | +{ |
| 35 | + d = new Private; |
| 36 | + |
| 37 | + d->client = client; |
| 38 | + d->mamPageSize = mamPageSize; |
| 39 | + d->mamMaxMessages = mamMaxMessages; |
| 40 | + d->flipPages = flipPages; |
| 41 | + d->backwards = backwards; |
| 42 | +} |
| 43 | + |
| 44 | +MAMManager::~MAMManager() { delete d; } |
| 45 | + |
| 46 | +// TODO: review the safety of these methods/object lifetimes |
| 47 | +MAMTask MAMManager::getFullArchive(const Jid &j, const bool allowMUCArchives) |
| 48 | +{ |
| 49 | + MAMTask task = new MAMTask(d->client->rootTask()); |
| 50 | + |
| 51 | + task.get(j, QString(), QString(), allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); |
| 52 | + return task; |
| 53 | +} |
| 54 | + |
| 55 | +MAMTask MAMManager::getArchiveByIDRange(const Jid &j, const QString &fromID, const QString &toID, |
| 56 | + const bool allowMUCArchives) |
| 57 | +{ |
| 58 | + MAMTask task = new MAMTask(d->client->rootTask()); |
| 59 | + |
| 60 | + task.get(j, fromID, toID, allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); |
| 61 | + return task; |
| 62 | +} |
| 63 | + |
| 64 | +MAMTask MAMManager::getArchiveByTimeRange(const Jid &j, const QDateTime &from, const QDateTime &to, |
| 65 | + const bool allowMUCArchives) |
| 66 | +{ |
| 67 | + MAMTask task = new MAMTask(d->client->rootTask()); |
| 68 | + |
| 69 | + task.get(j, from, to, allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); |
| 70 | + return task; |
| 71 | +} |
| 72 | + |
| 73 | +MAMTask MAMManager::getLatestMessagesFromArchive(const Jid &j, const QString &fromID, const bool allowMUCArchives, |
| 74 | + int amount) |
| 75 | +{ |
| 76 | + MAMTask task = new MAMTask(d->client->rootTask()); |
| 77 | + |
| 78 | + task.get(j, fromID, QString(), allowMUCArchives, d->mamPageSize, amount, true, true); |
| 79 | + return task; |
| 80 | +} |
| 81 | + |
| 82 | +MAMTask MAMManager::getMessagesBeforeID(const Jid &j, const QString &toID, const bool allowMUCArchives, int amount) |
| 83 | +{ |
| 84 | + MAMTask task = new MAMTask(d->client->rootTask()); |
| 85 | + |
| 86 | + task.get(j, QString(), toID, allowMUCArchives, d->mamPageSize, amount, true, true); |
| 87 | + return task; |
| 88 | +} |
0 commit comments