From 0624bec007a14e229e65f2ff4cd4f9a0d7cfcc9b Mon Sep 17 00:00:00 2001 From: Camila Date: Thu, 29 Sep 2022 21:26:20 +0200 Subject: Fix the dismiss button: display it whenever possible. Signed-off-by: Camila --- src/gui/tray/ActivityItem.qml | 4 ++-- src/gui/tray/activitylistmodel.cpp | 23 +++-------------------- src/gui/tray/notificationhandler.cpp | 16 ---------------- 3 files changed, 5 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/gui/tray/ActivityItem.qml b/src/gui/tray/ActivityItem.qml index b067ce8a8..9b67f1e57 100644 --- a/src/gui/tray/ActivityItem.qml +++ b/src/gui/tray/ActivityItem.qml @@ -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 } } diff --git a/src/gui/tray/activitylistmodel.cpp b/src/gui/tray/activitylistmodel.cpp index fc6df208f..8ebdcfef5 100644 --- a/src/gui/tray/activitylistmodel.cpp +++ b/src/gui/tray/activitylistmodel.cpp @@ -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(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 diff --git a/src/gui/tray/notificationhandler.cpp b/src/gui/tray/notificationhandler.cpp index 02105bf93..4137cb361 100644 --- a/src/gui/tray/notificationhandler.cpp +++ b/src/gui/tray/notificationhandler.cpp @@ -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); -- cgit v1.2.3