Add read support for m.file messages (#24)

This commit is contained in:
Konstantinos Sideris 2017-11-28 02:01:37 +02:00
parent f1eb0bbac0
commit b21942a3e3
16 changed files with 457 additions and 4 deletions

View file

@ -586,6 +586,32 @@ MatrixClient::downloadImage(const QString &event_id, const QUrl &url)
});
}
void
MatrixClient::downloadFile(const QString &event_id, const QUrl &url)
{
QNetworkRequest fileRequest(url);
auto reply = get(fileRequest);
connect(reply, &QNetworkReply::finished, this, [this, reply, event_id]() {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (status == 0 || status >= 400) {
// TODO: Handle error
qWarning() << reply->errorString();
return;
}
auto data = reply->readAll();
if (data.size() == 0)
return;
emit fileDownloaded(event_id, data);
});
}
void
MatrixClient::fetchOwnAvatar(const QUrl &avatar_url)
{