-
Notifications
You must be signed in to change notification settings - Fork 1
/
chatbskyconvogetmessages.cpp
69 lines (58 loc) · 2.4 KB
/
chatbskyconvogetmessages.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "chatbskyconvogetmessages.h"
#include "atprotocol/lexicons_func.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QUrlQuery>
namespace AtProtocolInterface {
ChatBskyConvoGetMessages::ChatBskyConvoGetMessages(QObject *parent)
: AccessAtProtocol { parent } { }
void ChatBskyConvoGetMessages::getMessages(const QString &convoId, const int limit,
const QString &cursor)
{
appendRawHeader("atproto-proxy", "did:web:api.bsky.chat#bsky_chat");
QUrlQuery url_query;
if (!convoId.isEmpty()) {
url_query.addQueryItem(QStringLiteral("convoId"), convoId);
}
if (limit > 0) {
url_query.addQueryItem(QStringLiteral("limit"), QString::number(limit));
}
if (!cursor.isEmpty()) {
url_query.addQueryItem(QStringLiteral("cursor"), cursor);
}
get(QStringLiteral("xrpc/chat.bsky.convo.getMessages"), url_query);
}
const QList<AtProtocolType::ChatBskyConvoDefs::MessageView> &
ChatBskyConvoGetMessages::messagesMessageViewList() const
{
return m_messagesMessageViewList;
}
const QList<AtProtocolType::ChatBskyConvoDefs::DeletedMessageView> &
ChatBskyConvoGetMessages::messagesDeletedMessageViewList() const
{
return m_messagesDeletedMessageViewList;
}
bool ChatBskyConvoGetMessages::parseJson(bool success, const QString reply_json)
{
QJsonDocument json_doc = QJsonDocument::fromJson(reply_json.toUtf8());
if (json_doc.isEmpty() || !json_doc.object().contains("messages")) {
success = false;
} else {
setCursor(json_doc.object().value("cursor").toString());
QString type;
for (const auto &value : json_doc.object().value("messages").toArray()) {
type = value.toObject().value("$type").toString();
if (type == QStringLiteral("chat.bsky.convo.defs#messageView")) {
AtProtocolType::ChatBskyConvoDefs::MessageView data;
AtProtocolType::ChatBskyConvoDefs::copyMessageView(value.toObject(), data);
m_messagesMessageViewList.append(data);
} else if (type == QStringLiteral("chat.bsky.convo.defs#deletedMessageView")) {
AtProtocolType::ChatBskyConvoDefs::DeletedMessageView data;
AtProtocolType::ChatBskyConvoDefs::copyDeletedMessageView(value.toObject(), data);
m_messagesDeletedMessageViewList.append(data);
}
}
}
return success;
}
}