Skip to content

Commit 5ab9c31

Browse files
mcneb10mcneb10
and
mcneb10
authored
MAM: rough draft (#73)
* 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]>
1 parent f57dd87 commit 5ab9c31

11 files changed

+499
-0
lines changed

include/iris/xmpp_mammanager.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "xmpp/xmpp-im/xmpp_mammanager.h"

include/iris/xmpp_mamtask.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "xmpp/xmpp-im/xmpp_mamtask.h"

src/xmpp/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ set(XMPP_IM_HEADERS
7171
xmpp-im/xmpp_bytestream.h
7272
xmpp-im/xmpp_client.h
7373
xmpp-im/xmpp_discoinfotask.h
74+
xmpp-im/xmpp_mamtask.h
75+
xmpp-im/xmpp_mammanager.h
7476
xmpp-im/xmpp_ibb.h
7577
xmpp-im/xmpp_serverinfomanager.h
7678
xmpp-im/xmpp_task.h
@@ -129,6 +131,8 @@ target_sources(iris PRIVATE
129131
xmpp-im/xmpp_hash.cpp
130132
xmpp-im/xmpp_ibb.cpp
131133
xmpp-im/xmpp_forwarding.cpp
134+
xmpp-im/xmpp_mamtask.cpp
135+
xmpp-im/xmpp_mammanager.cpp
132136
xmpp-im/xmpp_reference.cpp
133137
xmpp-im/xmpp_serverinfomanager.cpp
134138
xmpp-im/xmpp_subsets.cpp

src/xmpp/xmpp-im/xmpp_mammanager.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

src/xmpp/xmpp-im/xmpp_mammanager.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* xmpp_mammanager.h - 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+
#ifndef XMPP_MAM_MANAGER_H
21+
#define XMPP_MAM_MANAGER_H
22+
23+
#include "xmpp_client.h"
24+
#include "xmpp_mamtask.h"
25+
26+
#include <QObject>
27+
#include <QString>
28+
29+
namespace XMPP {
30+
class MAMManager : public QObject {
31+
Q_OBJECT
32+
public:
33+
MAMManager(Client *client, int mamPageSize = 10, int mamMaxMessages = 0, bool flipPages = true,
34+
bool backwards = true);
35+
~MAMManager();
36+
37+
MAMTask getFullArchive(const Jid &j, const bool allowMUCArchives = true);
38+
MAMTask getArchiveByIDRange(const Jid &j, const QString &fromID, const QString &toID,
39+
const bool allowMUCArchives = true);
40+
MAMTask getArchiveByTimeRange(const Jid &j, const QDateTime &from, const QDateTime &to,
41+
const bool allowMUCArchives = true);
42+
MAMTask getLatestMessagesFromArchive(const Jid &j, const QString &fromID, const bool allowMUCArchives = true,
43+
int amount = 100);
44+
MAMTask getMessagesBeforeID(const Jid &j, const QString &toID, const bool allowMUCArchives = true,
45+
int amount = 100);
46+
47+
private:
48+
class Private;
49+
Private *d;
50+
};
51+
}
52+
53+
#endif

0 commit comments

Comments
 (0)