-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move here from the mam branch, fix filtering, semantics, logic, etc * add id filter * actually add the id filtering logic * some code cleanup * add better error handling * add `xmpp_mamtask` to cmake and fix compilation errors * add mam manager (untested, compiles) * add ability to get last messages from archive, fix some naming * add ability to get messages before id * make the manager just return the activated MAM task instead of handling the result * fix archive behavior and return value for mam manager --------- Co-authored-by: mcneb10 <[email protected]>
- Loading branch information
Showing
11 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "xmpp/xmpp-im/xmpp_mammanager.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "xmpp/xmpp-im/xmpp_mamtask.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* xmpp_mammanager.cpp - XEP-0313 Message Archive Management | ||
* Copyright (C) 2024 mcneb10 | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "xmpp_mammanager.h" | ||
|
||
using namespace XMPP; | ||
|
||
class MAMManager::Private { | ||
public: | ||
int mamPageSize; | ||
int mamMaxMessages; | ||
bool flipPages; | ||
bool backwards; | ||
Client *client; | ||
}; | ||
|
||
MAMManager::MAMManager(Client *client, int mamPageSize, int mamMaxMessages, bool flipPages, bool backwards) | ||
{ | ||
d = new Private; | ||
|
||
d->client = client; | ||
d->mamPageSize = mamPageSize; | ||
d->mamMaxMessages = mamMaxMessages; | ||
d->flipPages = flipPages; | ||
d->backwards = backwards; | ||
} | ||
|
||
MAMManager::~MAMManager() { delete d; } | ||
|
||
// TODO: review the safety of these methods/object lifetimes | ||
MAMTask MAMManager::getFullArchive(const Jid &j, const bool allowMUCArchives) | ||
{ | ||
MAMTask task = new MAMTask(d->client->rootTask()); | ||
|
||
task.get(j, QString(), QString(), allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); | ||
return task; | ||
} | ||
|
||
MAMTask MAMManager::getArchiveByIDRange(const Jid &j, const QString &fromID, const QString &toID, | ||
const bool allowMUCArchives) | ||
{ | ||
MAMTask task = new MAMTask(d->client->rootTask()); | ||
|
||
task.get(j, fromID, toID, allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); | ||
return task; | ||
} | ||
|
||
MAMTask MAMManager::getArchiveByTimeRange(const Jid &j, const QDateTime &from, const QDateTime &to, | ||
const bool allowMUCArchives) | ||
{ | ||
MAMTask task = new MAMTask(d->client->rootTask()); | ||
|
||
task.get(j, from, to, allowMUCArchives, d->mamPageSize, d->mamMaxMessages, d->flipPages, d->backwards); | ||
return task; | ||
} | ||
|
||
MAMTask MAMManager::getLatestMessagesFromArchive(const Jid &j, const QString &fromID, const bool allowMUCArchives, | ||
int amount) | ||
{ | ||
MAMTask task = new MAMTask(d->client->rootTask()); | ||
|
||
task.get(j, fromID, QString(), allowMUCArchives, d->mamPageSize, amount, true, true); | ||
return task; | ||
} | ||
|
||
MAMTask MAMManager::getMessagesBeforeID(const Jid &j, const QString &toID, const bool allowMUCArchives, int amount) | ||
{ | ||
MAMTask task = new MAMTask(d->client->rootTask()); | ||
|
||
task.get(j, QString(), toID, allowMUCArchives, d->mamPageSize, amount, true, true); | ||
return task; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* xmpp_mammanager.h - XEP-0313 Message Archive Management | ||
* Copyright (C) 2024 mcneb10 | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef XMPP_MAM_MANAGER_H | ||
#define XMPP_MAM_MANAGER_H | ||
|
||
#include "xmpp_client.h" | ||
#include "xmpp_mamtask.h" | ||
|
||
#include <QObject> | ||
#include <QString> | ||
|
||
namespace XMPP { | ||
class MAMManager : public QObject { | ||
Q_OBJECT | ||
public: | ||
MAMManager(Client *client, int mamPageSize = 10, int mamMaxMessages = 0, bool flipPages = true, | ||
bool backwards = true); | ||
~MAMManager(); | ||
|
||
MAMTask getFullArchive(const Jid &j, const bool allowMUCArchives = true); | ||
MAMTask getArchiveByIDRange(const Jid &j, const QString &fromID, const QString &toID, | ||
const bool allowMUCArchives = true); | ||
MAMTask getArchiveByTimeRange(const Jid &j, const QDateTime &from, const QDateTime &to, | ||
const bool allowMUCArchives = true); | ||
MAMTask getLatestMessagesFromArchive(const Jid &j, const QString &fromID, const bool allowMUCArchives = true, | ||
int amount = 100); | ||
MAMTask getMessagesBeforeID(const Jid &j, const QString &toID, const bool allowMUCArchives = true, | ||
int amount = 100); | ||
|
||
private: | ||
class Private; | ||
Private *d; | ||
}; | ||
} | ||
|
||
#endif |
Oops, something went wrong.