Skip to content

Commit

Permalink
MAM: rough draft (#73)
Browse files Browse the repository at this point in the history
* 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
mcneb10 and mcneb10 authored Sep 11, 2024
1 parent f57dd87 commit 5ab9c31
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/iris/xmpp_mammanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "xmpp/xmpp-im/xmpp_mammanager.h"
1 change: 1 addition & 0 deletions include/iris/xmpp_mamtask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "xmpp/xmpp-im/xmpp_mamtask.h"
4 changes: 4 additions & 0 deletions src/xmpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ set(XMPP_IM_HEADERS
xmpp-im/xmpp_bytestream.h
xmpp-im/xmpp_client.h
xmpp-im/xmpp_discoinfotask.h
xmpp-im/xmpp_mamtask.h
xmpp-im/xmpp_mammanager.h
xmpp-im/xmpp_ibb.h
xmpp-im/xmpp_serverinfomanager.h
xmpp-im/xmpp_task.h
Expand Down Expand Up @@ -129,6 +131,8 @@ target_sources(iris PRIVATE
xmpp-im/xmpp_hash.cpp
xmpp-im/xmpp_ibb.cpp
xmpp-im/xmpp_forwarding.cpp
xmpp-im/xmpp_mamtask.cpp
xmpp-im/xmpp_mammanager.cpp
xmpp-im/xmpp_reference.cpp
xmpp-im/xmpp_serverinfomanager.cpp
xmpp-im/xmpp_subsets.cpp
Expand Down
88 changes: 88 additions & 0 deletions src/xmpp/xmpp-im/xmpp_mammanager.cpp
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;
}
53 changes: 53 additions & 0 deletions src/xmpp/xmpp-im/xmpp_mammanager.h
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
Loading

0 comments on commit 5ab9c31

Please sign in to comment.