Add a dismiss link for notifications without it.
authorCamila <hello@camila.codes>
Fri, 12 May 2023 14:46:23 +0000 (16:46 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Tue, 16 May 2023 09:17:37 +0000 (11:17 +0200)
- Fix for #5606 and #5585.
- That is how it is done in the server and other clients.
- Update tests.

Signed-off-by: Camila <hello@camila.codes>
src/gui/tray/ActivityItem.qml
src/gui/tray/notificationhandler.cpp
test/testactivitylistmodel.cpp

index e4705562f5122e448673c7506ecd84a1587e2da5..453be56f80a1b90d41d3c21e79c021ca8c4c94fe 100644 (file)
@@ -74,7 +74,7 @@ ItemDelegate {
         ActivityItemActions {
             id: activityActions
 
-            visible: !root.isFileActivityList && model.linksForActionButtons.length > 0 && !isTalkReplyOptionVisible
+            visible: !root.isFileActivityList && model.linksForActionButtons.length > 1 && !isTalkReplyOptionVisible
 
             Layout.fillWidth: true
             Layout.leftMargin: Style.trayListItemIconSize + activityContent.spacing
index f87a717b77d5b7e043f2af241487f937b1d6a881..eb3e00da57f4f49ad1c891bc928d1e10ec891eef 100644 (file)
@@ -82,7 +82,6 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
     ActivityList list;
     ActivityList callList;
 
-
     foreach (auto element, notifies) {
         auto json = element.toObject();
         auto a = Activity::fromActivityJson(json, ai->account());
@@ -145,7 +144,15 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
             }
 
             a._links.insert(al._primary? 0 : a._links.size(), al);
-        } 
+        }
+
+        if (a._links.isEmpty()) {
+            ActivityLink dismissLink;
+            dismissLink._label = tr("Dismiss");
+            dismissLink._verb = "DELETE";
+            dismissLink._primary = false;
+            a._links.insert(0, dismissLink);
+        }
 
         QUrl link(json.value("link").toString());
         if (!link.isEmpty()) {
index fb72bce00b6bff69fb8b6fbe695e6421827a6382..8f60a8f604ccd8faca797d1114e342f2af8313f1 100644 (file)
@@ -234,7 +234,7 @@ public:
             activity.insert(QStringLiteral("activity_id"), _startingId);
             activity.insert(QStringLiteral("object_type"), "2fa_id");
             activity.insert(QStringLiteral("subject"), QStringLiteral("Login attempt from 127.0.0.1"));
-            activity.insert(QStringLiteral("message"), QStringLiteral("Please apporve or deny the login attempt."));
+            activity.insert(QStringLiteral("message"), QStringLiteral("Please approve or deny the login attempt."));
             activity.insert(QStringLiteral("object_name"), QStringLiteral(""));
             activity.insert(QStringLiteral("datetime"), QDateTime::currentDateTime().toString(Qt::ISODate));
             activity.insert(QStringLiteral("icon"), QStringLiteral("http://example.de/core/img/places/password.svg"));
@@ -263,6 +263,34 @@ public:
             _startingId++;
         }
 
+        // Insert notification data
+        for (quint32 i = 0; i < _numItemsToInsert; i++) {
+            QJsonObject activity;
+            activity.insert(QStringLiteral("activity_id"), _startingId);
+            activity.insert(QStringLiteral("object_type"), "create");
+            activity.insert(QStringLiteral("subject"), QStringLiteral("Generate backup codes"));
+            activity.insert(QStringLiteral("message"), QStringLiteral("You enabled two-factor authentication but did not generate backup codes yet. They are needed to restore access to your account in case you lose your second factor."));
+            activity.insert(QStringLiteral("object_name"), QStringLiteral(""));
+            activity.insert(QStringLiteral("datetime"), QDateTime::currentDateTime().toString(Qt::ISODate));
+            activity.insert(QStringLiteral("icon"), QStringLiteral("http://example.de/core/img/places/password.svg"));
+
+            QJsonArray actionsArray;
+
+            QJsonObject secondaryAction;
+            secondaryAction.insert(QStringLiteral("label"), QStringLiteral("Dismiss"));
+            secondaryAction.insert(QStringLiteral("link"),
+                                   QString(QStringLiteral("ocs/v2.php/apps/notifications/api/v2/notifications/19867")));
+            secondaryAction.insert(QStringLiteral("type"), QStringLiteral("DELETE"));
+            secondaryAction.insert(QStringLiteral("primary"), false);
+            actionsArray.push_back(secondaryAction);
+
+            activity.insert(QStringLiteral("actions"), actionsArray);
+
+            _activityData.push_back(activity);
+
+            _startingId++;
+        }
+
         _startingId--;
     }
 
@@ -619,6 +647,9 @@ private slots:
             QVERIFY(index.data(OCC::ActivityListModel::ActionTextRole).canConvert<QString>());
             QVERIFY(index.data(OCC::ActivityListModel::MessageRole).canConvert<QString>());
             QVERIFY(index.data(OCC::ActivityListModel::LinkRole).canConvert<QUrl>());
+
+            QVERIFY(index.data(OCC::ActivityListModel::ActionsLinksForActionButtonsRole).canConvert<QList<QVariant>>());
+
             QVERIFY(index.data(OCC::ActivityListModel::AccountConnectedRole).canConvert<bool>());
             QVERIFY(index.data(OCC::ActivityListModel::DisplayActions).canConvert<bool>());
 
@@ -677,6 +708,13 @@ private slots:
                         QVERIFY(actionsLinksContextMenu.isEmpty());
                     }
 
+                    // Generate 2FA backup codes notification
+                    if (objectType == QStringLiteral("create")) {
+                        QVERIFY(actionsLinks.size() == 1);
+                        QVERIFY(!actionsLinks[0].value<OCC::ActivityLink>()._primary);
+                        QVERIFY(actionsLinksContextMenu.isEmpty());
+                    }
+
                     if ((objectType == QStringLiteral("chat") || objectType == QStringLiteral("call")
                             || objectType == QStringLiteral("room"))) {