Notify the user on upload failures

This commit is contained in:
Konstantinos Sideris 2018-02-19 00:17:54 +02:00
parent cd9d1a2ec6
commit a8e17b9c91
3 changed files with 12 additions and 5 deletions

View file

@ -111,6 +111,7 @@ signals:
const QString &homeserver, const QString &homeserver,
const QString &token); const QString &token);
void versionSuccess(); void versionSuccess();
void uploadFailed(int statusCode, const QString &msg);
void imageUploaded(const QString &roomid, void imageUploaded(const QString &roomid,
const QString &filename, const QString &filename,
const QString &url, const QString &url,

View file

@ -256,6 +256,10 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
connect( connect(
client_.data(), &MatrixClient::roomCreationFailed, this, &ChatPage::showNotification); client_.data(), &MatrixClient::roomCreationFailed, this, &ChatPage::showNotification);
connect(client_.data(), &MatrixClient::joinFailed, this, &ChatPage::showNotification); connect(client_.data(), &MatrixClient::joinFailed, this, &ChatPage::showNotification);
connect(client_.data(), &MatrixClient::uploadFailed, this, [=](int, const QString &msg) {
text_input_->hideUploadSpinner();
emit showNotification(msg);
});
connect(client_.data(), connect(client_.data(),
&MatrixClient::imageUploaded, &MatrixClient::imageUploaded,
this, this,

View file

@ -1209,26 +1209,28 @@ MatrixClient::getUploadReply(QNetworkReply *reply)
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (status == 0 || status >= 400) { if (status == 0 || status >= 400) {
emit syncFailed(reply->errorString()); emit uploadFailed(status,
QString("Media upload failed - %1").arg(reply->errorString()));
return object; return object;
} }
auto res_data = reply->readAll(); auto res_data = reply->readAll();
if (res_data.isEmpty()) if (res_data.isEmpty()) {
emit uploadFailed(status, "Media upload failed - Empty response");
return object; return object;
}
auto json = QJsonDocument::fromJson(res_data); auto json = QJsonDocument::fromJson(res_data);
if (!json.isObject()) { if (!json.isObject()) {
qDebug() << "Media upload: Response is not a json object."; emit uploadFailed(status, "Media upload failed - Invalid response");
return object; return object;
} }
object = json.object(); object = json.object();
if (!object.contains("content_uri")) { if (!object.contains("content_uri")) {
qDebug() << "Media upload: Missing content_uri key"; emit uploadFailed(status, "Media upload failed - Missing 'content_uri'");
qDebug() << object;
return QJsonObject{}; return QJsonObject{};
} }