summary refs log tree commit diff
path: root/src/MatrixClient.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-12-03 02:47:37 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-12-03 02:47:37 +0200
commit914bdecc0b8e57a3b4e75b218b02909172ada7e3 (patch)
tree115c7d85758e503921cd5443af9e007b07849625 /src/MatrixClient.cc
parentAdd basic support for m.video messages (diff)
downloadnheko-914bdecc0b8e57a3b4e75b218b02909172ada7e3.tar.xz
Initial integration with matrix-structs
Diffstat (limited to 'src/MatrixClient.cc')
-rw-r--r--src/MatrixClient.cc48
1 files changed, 18 insertions, 30 deletions
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc

index 3326a47f..1887eb95 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc
@@ -31,11 +31,11 @@ #include "Login.h" #include "MatrixClient.h" #include "MessageEvent.h" -#include "Profile.h" #include "Register.h" #include "RoomMessages.h" #include "Sync.h" -#include "Versions.h" + +#include "mtx.hpp" MatrixClient::MatrixClient(QString server, QObject *parent) : QNetworkAccessManager(parent) @@ -99,21 +99,18 @@ MatrixClient::login(const QString &username, const QString &password) noexcept return; } - auto data = reply->readAll(); - auto json = QJsonDocument::fromJson(data); - - LoginResponse response; - try { - response.deserialize(json); + mtx::responses::Login login = + nlohmann::json::parse(reply->readAll().data()); auto hostname = server_.host(); if (server_.port() > 0) hostname = QString("%1:%2").arg(server_.host()).arg(server_.port()); - emit loginSuccess( - response.getUserId(), hostname, response.getAccessToken()); + emit loginSuccess(QString::fromStdString(login.user_id.toString()), + hostname, + QString::fromStdString(login.access_token)); } catch (DeserializationException &e) { qWarning() << "Malformed JSON response" << e.what(); emit loginError(tr("Malformed response. Possibly not a Matrix server")); @@ -420,18 +417,12 @@ MatrixClient::versions() noexcept return; } - auto data = reply->readAll(); - auto json = QJsonDocument::fromJson(data); - - VersionsResponse response; - try { - response.deserialize(json); - if (!response.isVersionSupported(0, 2, 0)) - emit versionError("Server does not support required API version."); - else - emit versionSuccess(); - } catch (DeserializationException &e) { + mtx::responses::Versions versions = + nlohmann::json::parse(reply->readAll().data()); + + emit versionSuccess(); + } catch (std::exception &e) { emit versionError("Malformed response. Possibly not a Matrix server"); } }); @@ -465,16 +456,13 @@ MatrixClient::getOwnProfile() noexcept return; } - auto data = reply->readAll(); - auto json = QJsonDocument::fromJson(data); - - ProfileResponse response; - try { - response.deserialize(json); - emit getOwnProfileResponse(response.getAvatarUrl(), - response.getDisplayName()); - } catch (DeserializationException &e) { + mtx::responses::Profile profile = + nlohmann::json::parse(reply->readAll().data()); + + emit getOwnProfileResponse(QUrl(QString::fromStdString(profile.avatar_url)), + QString::fromStdString(profile.display_name)); + } catch (std::exception &e) { qWarning() << "Profile:" << e.what(); } });