From ed9501023ae57e668a930e5d3accbb47ad3d7812 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 5 May 2018 16:38:41 +0300 Subject: Add support for retrieving the notification events (#33) --- src/MatrixClient.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/MatrixClient.cc') 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(); + } + }); +} -- cgit 1.5.1