Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dismiss notifications #5687

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui/tray/ActivityItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/gui/tray/notificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down
40 changes: 39 additions & 1 deletion test/testactivitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class FakeRemoteActivityStorage
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"));
Expand Down Expand Up @@ -263,6 +263,34 @@ class FakeRemoteActivityStorage
_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--;
}

Expand Down Expand Up @@ -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>());

Expand Down Expand Up @@ -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"))) {

Expand Down