Fix the dismiss button: display it whenever possible.
authorCamila <hello@camila.codes>
Thu, 29 Sep 2022 19:26:20 +0000 (21:26 +0200)
committerCamila (Rebase PR Action) <hello@camila.codes>
Mon, 17 Oct 2022 11:29:23 +0000 (11:29 +0000)
Signed-off-by: Camila <hello@camila.codes>
src/gui/tray/ActivityItem.qml
src/gui/tray/activitylistmodel.cpp
src/gui/tray/notificationhandler.cpp

index b067ce8a8da6190f0b70381c92199129630f13d3..9b67f1e57fb7d7cd8bf0862479270dd85b377f78 100644 (file)
@@ -46,7 +46,7 @@ ItemDelegate {
             Layout.fillWidth: true
             Layout.minimumHeight: Style.minActivityHeight
 
-            showDismissButton: model.links.length > 0 && model.linksForActionButtons.length === 0
+            showDismissButton: model.links.length > 0
 
             activityData: model
 
@@ -94,7 +94,7 @@ ItemDelegate {
 
             adjustedHeaderColor: root.adjustedHeaderColor
 
-            onTriggerAction: activityModel.slotTriggerAction(model.index, actionIndex)
+            onTriggerAction: activityModel.slotTriggerAction(model.activityIndex, actionIndex)
             onShowReplyField: root.isTalkReplyOptionVisible = true
         }
     }
index fc6df208f5118701b0b73a1aa4eeae7750b4a7d7..8ebdcfef573fd31ab9841c80c7a39eeea01b4185 100644 (file)
@@ -740,27 +740,10 @@ void ActivityListModel::slotTriggerDismiss(const int activityIndex)
         return;
     }
 
-    const auto activityLinks = _finalList[activityIndex]._links;
-
-    const auto foundActivityLinkIt = std::find_if(std::cbegin(activityLinks), std::cend(activityLinks), [](const ActivityLink &link) {
-        return link._verb == QStringLiteral("DELETE");
-    });
-
-    if (foundActivityLinkIt == std::cend(activityLinks)) {
-        qCWarning(lcActivity) << "Couldn't find dismiss action in activity at index" << activityIndex
-                              << " links.size() " << activityLinks.size();
-        return;
-    }
-
-    const auto actionIndex = static_cast<int>(std::distance(activityLinks.begin(), foundActivityLinkIt));
-
-    if (actionIndex < 0 || actionIndex > activityLinks.size()) {
-        qCWarning(lcActivity) << "Couldn't find dismiss action in activity at index" << activityIndex
-                              << " actionIndex found " << actionIndex;
-        return;
-    }
+    constexpr auto deleteVerb = "DELETE";
+    const auto activity = _finalList[activityIndex];
 
-    slotTriggerAction(activityIndex, actionIndex);
+    emit sendNotificationRequest(activity._accName, Utility::concatUrlPath(accountState()->account()->url(), "ocs/v2.php/apps/notifications/api/v2/notifications/" + QString::number(activity._id)).toString(), deleteVerb, activityIndex);
 }
 
 AccountState *ActivityListModel::accountState() const
index 02105bf934feedaadc2cfa97f930f8382feffca5..4137cb3619689d363912af0def43a9b53edcb8e3 100644 (file)
@@ -154,22 +154,6 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
         }
         a._link = link;
 
-        // 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
-        constexpr auto deleteVerb = "DELETE";
-        const auto itLink = std::find_if(std::cbegin(a._links), std::cend(a._links), [deleteVerb](const ActivityLink& link) {
-            Q_UNUSED(deleteVerb)
-            return link._verb == deleteVerb;
-        });
-        if (itLink == std::cend(a._links)) {
-            ActivityLink al;
-            al._label = tr("Dismiss");
-            al._link = Utility::concatUrlPath(ai->account()->url(), notificationsPath + "/" + QString::number(a._id)).toString();
-            al._verb = deleteVerb;
-            al._primary = false;
-            a._links.append(al);
-        }
-
         list.append(a);
     }
     emit newNotificationList(list);