[Pkg-owncloud-commits] [owncloud-client] 51/60: Notifications: Propagate "Dismiss" as DELETE to server #5922

Sandro Knauß hefee at debian.org
Sat Dec 16 10:38:15 UTC 2017


This is an automated email from the git hooks/post-receive script.

hefee pushed a commit to branch upstream
in repository owncloud-client.

commit 75676f883092426c7f669b65f96f01e36f0a1bc2
Author: Markus Goetz <markus at woboq.com>
Date:   Thu Aug 3 18:03:58 2017 +0200

    Notifications: Propagate "Dismiss" as DELETE to server #5922
    
    (cherry picked from commit e86416fff7c74174e699802cec46da8ca3c3aad5)
---
 src/gui/activitywidget.cpp            |  3 +--
 src/gui/notificationwidget.cpp        |  4 ++--
 src/gui/ocsjob.cpp                    |  1 +
 src/gui/ocsjob.h                      |  2 ++
 src/gui/servernotificationhandler.cpp | 14 +++++++++++++-
 5 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index b089fef..8a29d91 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -429,14 +429,13 @@ void ActivityWidget::slotNotifyServerFinished(const QString &reply, int replyCod
     }
 
     endNotificationRequest(job->widget(), replyCode);
-    // FIXME: remove the  widget after a couple of seconds
     qCInfo(lcActivity) << "Server Notification reply code" << replyCode << reply;
 
     // if the notification was successful start a timer that triggers
     // removal of the done widgets in a few seconds
     // Add 200 millisecs to the predefined value to make sure that the timer in
     // widget's method readyToClose() has elapsed.
-    if (replyCode == OCS_SUCCESS_STATUS_CODE) {
+    if (replyCode == OCS_SUCCESS_STATUS_CODE || replyCode == OCS_SUCCESS_STATUS_CODE_V2) {
         scheduleWidgetToRemove(job->widget());
     }
 }
diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp
index dbf8c18..cd87945 100644
--- a/src/gui/notificationwidget.cpp
+++ b/src/gui/notificationwidget.cpp
@@ -128,8 +128,8 @@ void NotificationWidget::slotNotificationRequestFinished(int statusCode)
 
     QString timeStr = locale.toString(QTime::currentTime());
 
-    // the ocs API returns stat code 100 if it succeeded.
-    if (statusCode != OCS_SUCCESS_STATUS_CODE) {
+    // the ocs API returns stat code 100 or 200 inside the xml if it succeeded.
+    if (statusCode != OCS_SUCCESS_STATUS_CODE && statusCode != OCS_SUCCESS_STATUS_CODE_V2) {
         qCWarning(lcNotifications) << "Notification Request to Server failed, leave button visible.";
         for (i = 0; i < _buttons.count(); i++) {
             _buttons.at(i)->setEnabled(true);
diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp
index cc1e0d9..7da6ba6 100644
--- a/src/gui/ocsjob.cpp
+++ b/src/gui/ocsjob.cpp
@@ -28,6 +28,7 @@ OcsJob::OcsJob(AccountPtr account)
     : AbstractNetworkJob(account, "")
 {
     _passStatusCodes.append(OCS_SUCCESS_STATUS_CODE);
+    _passStatusCodes.append(OCS_SUCCESS_STATUS_CODE_V2);
     setIgnoreCredentialFailure(true);
 }
 
diff --git a/src/gui/ocsjob.h b/src/gui/ocsjob.h
index 4560b3a..4de4d70 100644
--- a/src/gui/ocsjob.h
+++ b/src/gui/ocsjob.h
@@ -24,6 +24,8 @@
 #include <QUrl>
 
 #define OCS_SUCCESS_STATUS_CODE 100
+// Apparantly the v2.php URLs can return that
+#define OCS_SUCCESS_STATUS_CODE_V2 200
 
 class QJsonDocument;
 
diff --git a/src/gui/servernotificationhandler.cpp b/src/gui/servernotificationhandler.cpp
index 7c69bf5..72b65b2 100644
--- a/src/gui/servernotificationhandler.cpp
+++ b/src/gui/servernotificationhandler.cpp
@@ -24,6 +24,8 @@ namespace OCC {
 
 Q_LOGGING_CATEGORY(lcServerNotification, "gui.servernotification", QtInfoMsg)
 
+const QString notificationsPath = QLatin1String("ocs/v2.php/apps/notifications/api/v1/notifications");
+
 ServerNotificationHandler::ServerNotificationHandler(QObject *parent)
     : QObject(parent)
 {
@@ -47,7 +49,7 @@ void ServerNotificationHandler::slotFetchNotifications(AccountState *ptr)
     }
 
     // if the previous notification job has finished, start next.
-    _notificationJob = new JsonApiJob(ptr->account(), QLatin1String("ocs/v2.php/apps/notifications/api/v1/notifications"), this);
+    _notificationJob = new JsonApiJob(ptr->account(), notificationsPath, this);
     QObject::connect(_notificationJob.data(), &JsonApiJob::jsonReceived,
         this, &ServerNotificationHandler::slotNotificationsReceived);
     _notificationJob->setProperty("AccountStatePtr", QVariant::fromValue<AccountState *>(ptr));
@@ -94,6 +96,16 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
 
             a._links.append(al);
         }
+
+        // Add another action to dismiss notification on server
+        // https://github.com/owncloud/notifications/blob/master/docs/ocs-endpoint-v1.md#deleting-a-notification-for-a-user
+        ActivityLink al;
+        al._label = tr("Dismiss");
+        al._link  = Utility::concatUrlPath(ai->account()->url(), notificationsPath + "/" + json.value("notification_id").toString()).toString();
+        al._verb  = "DELETE";
+        al._isPrimary = false;
+        a._links.append(al);
+
         list.append(a);
     }
     emit newNotificationList(list);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list