summary refs log tree commit diff
path: root/src/MatrixClient.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-05-05 16:38:41 +0300
commited9501023ae57e668a930e5d3accbb47ad3d7812 (patch)
tree11d0150f0bd3bae0013e67cbd3e184b778e9946b /src/MatrixClient.cc
parentAdd compile option for address sanitizers (diff)
downloadnheko-ed9501023ae57e668a930e5d3accbb47ad3d7812.tar.xz
Add support for retrieving the notification events (#33)
Diffstat (limited to 'src/MatrixClient.cc')
-rw-r--r--src/MatrixClient.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc

index de930fc3..54756c7c 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc
@@ -1310,3 +1310,41 @@ MatrixClient::redactEvent(const QString &room_id, const QString &event_id) } }); } + +void +MatrixClient::getNotifications() noexcept +{ + QUrlQuery query; + query.addQueryItem("limit", "5"); + + QUrl endpoint(server_); + endpoint.setQuery(query); + endpoint.setPath(clientApiUrl_ + "/notifications"); + + QNetworkRequest request(QString(endpoint.toEncoded())); + setupAuth(request); + + auto reply = get(request); + connect(reply, &QNetworkReply::finished, this, [reply, this]() { + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + auto data = reply->readAll(); + + if (status == 0 || status >= 400) { + try { + mtx::errors::Error res = nlohmann::json::parse(data); + std::cout << nlohmann::json::parse(data).dump(2) << '\n'; + // TODO: Response with an error signal + return; + } catch (const std::exception &) { + } + } + + try { + emit notificationsRetrieved(nlohmann::json::parse(data)); + } catch (const std::exception &e) { + qWarning() << "failed to parse /notifications response" << e.what(); + } + }); +}