summary refs log tree commit diff
path: root/src/MatrixClient.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-12 15:43:35 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-12 15:43:35 +0300
commit0368d854cfc5278df7bb29b0a75ee5db1c11a0d7 (patch)
tree80c35bf0537fb718d0842351e0bdd38f9b852061 /src/MatrixClient.cc
parentHighlight URLs in TimelineView (diff)
downloadnheko-0368d854cfc5278df7bb29b0a75ee5db1c11a0d7.tar.xz
Initial support for backwards pagination
Diffstat (limited to 'src/MatrixClient.cc')
-rw-r--r--src/MatrixClient.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc

index ac321d94..015e9809 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc
@@ -333,6 +333,32 @@ void MatrixClient::onImageResponse(QNetworkReply *reply) emit imageDownloaded(event_id, pixmap); } +void MatrixClient::onMessagesResponse(QNetworkReply *reply) +{ + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status == 0 || status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto data = reply->readAll(); + auto room_id = reply->property("room_id").toString(); + + RoomMessages msgs; + + try { + msgs.deserialize(QJsonDocument::fromJson(data)); + } catch (const DeserializationException &e) { + qWarning() << "Room messages from" << room_id << e.what(); + return; + } + + emit messagesRetrieved(room_id, msgs); +} + void MatrixClient::onResponse(QNetworkReply *reply) { switch (static_cast<Endpoint>(reply->property("endpoint").toInt())) { @@ -369,6 +395,9 @@ void MatrixClient::onResponse(QNetworkReply *reply) case Endpoint::GetOwnAvatar: onGetOwnAvatarResponse(reply); break; + case Endpoint::Messages: + onMessagesResponse(reply); + break; default: break; } @@ -581,3 +610,21 @@ void MatrixClient::fetchOwnAvatar(const QUrl &avatar_url) QNetworkReply *reply = get(avatar_request); reply->setProperty("endpoint", static_cast<int>(Endpoint::GetOwnAvatar)); } + +void MatrixClient::messages(const QString &room_id, const QString &from_token) noexcept +{ + QUrlQuery query; + query.addQueryItem("access_token", token_); + query.addQueryItem("from", from_token); + query.addQueryItem("dir", "b"); + + QUrl endpoint(server_); + endpoint.setPath(api_url_ + QString("/rooms/%1/messages").arg(room_id)); + endpoint.setQuery(query); + + QNetworkRequest request(QString(endpoint.toEncoded())); + + QNetworkReply *reply = get(request); + reply->setProperty("endpoint", static_cast<int>(Endpoint::Messages)); + reply->setProperty("room_id", room_id); +}