summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--include/MatrixClient.h1
-rw-r--r--src/ChatPage.cc4
-rw-r--r--src/MatrixClient.cc12
3 files changed, 12 insertions, 5 deletions
diff --git a/include/MatrixClient.h b/include/MatrixClient.h
index d9f5067a..03cd8669 100644
--- a/include/MatrixClient.h
+++ b/include/MatrixClient.h
@@ -111,6 +111,7 @@ signals:
                              const QString &homeserver,
                              const QString &token);
         void versionSuccess();
+        void uploadFailed(int statusCode, const QString &msg);
         void imageUploaded(const QString &roomid,
                            const QString &filename,
                            const QString &url,
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 9ec377e8..8899ffca 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -256,6 +256,10 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
         connect(
           client_.data(), &MatrixClient::roomCreationFailed, 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(),
                 &MatrixClient::imageUploaded,
                 this,
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index c915c74a..de9ce779 100644
--- a/src/MatrixClient.cc
+++ b/src/MatrixClient.cc
@@ -1209,26 +1209,28 @@ MatrixClient::getUploadReply(QNetworkReply *reply)
         int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
         if (status == 0 || status >= 400) {
-                emit syncFailed(reply->errorString());
+                emit uploadFailed(status,
+                                  QString("Media upload failed - %1").arg(reply->errorString()));
                 return object;
         }
 
         auto res_data = reply->readAll();
 
-        if (res_data.isEmpty())
+        if (res_data.isEmpty()) {
+                emit uploadFailed(status, "Media upload failed - Empty response");
                 return object;
+        }
 
         auto json = QJsonDocument::fromJson(res_data);
 
         if (!json.isObject()) {
-                qDebug() << "Media upload: Response is not a json object.";
+                emit uploadFailed(status, "Media upload failed - Invalid response");
                 return object;
         }
 
         object = json.object();
         if (!object.contains("content_uri")) {
-                qDebug() << "Media upload: Missing content_uri key";
-                qDebug() << object;
+                emit uploadFailed(status, "Media upload failed - Missing 'content_uri'");
                 return QJsonObject{};
         }