From f490040811893523db446513b524457c70c0dffd Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 27 May 2017 01:29:45 +0300 Subject: [PATCH] Fetch avatar thumbnail instead of the original image closes #31 --- src/MatrixClient.cc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 015e9809..23cbbb5e 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -574,10 +574,17 @@ void MatrixClient::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url return; } - QString media_params = url_parts[1]; - QString media_url = QString("%1/_matrix/media/r0/download/%2").arg(getHomeServer().toString(), media_params); + QUrlQuery query; + query.addQueryItem("width", "512"); + query.addQueryItem("height", "512"); + query.addQueryItem("method", "crop"); - QNetworkRequest avatar_request(media_url); + QString media_url = QString("%1/_matrix/media/r0/thumbnail/%2").arg(getHomeServer().toString(), url_parts[1]); + + QUrl endpoint(media_url); + endpoint.setQuery(query); + + QNetworkRequest avatar_request(endpoint); QNetworkReply *reply = get(avatar_request); reply->setProperty("roomid", roomid); @@ -602,10 +609,17 @@ void MatrixClient::fetchOwnAvatar(const QUrl &avatar_url) return; } - QString media_params = url_parts[1]; - QString media_url = QString("%1/_matrix/media/r0/download/%2").arg(getHomeServer().toString(), media_params); + QUrlQuery query; + query.addQueryItem("width", "512"); + query.addQueryItem("height", "512"); + query.addQueryItem("method", "crop"); - QNetworkRequest avatar_request(media_url); + QString media_url = QString("%1/_matrix/media/r0/thumbnail/%2").arg(getHomeServer().toString(), url_parts[1]); + + QUrl endpoint(media_url); + endpoint.setQuery(query); + + QNetworkRequest avatar_request(endpoint); QNetworkReply *reply = get(avatar_request); reply->setProperty("endpoint", static_cast(Endpoint::GetOwnAvatar));