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

[stable-3.6] Fix 'Reply' primary property. #5006

Merged
merged 3 commits into from
Oct 5, 2022
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
1 change: 0 additions & 1 deletion src/gui/tray/ActivityItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MouseArea {
readonly property bool isChatActivity: model.objectType === "chat" || model.objectType === "room" || model.objectType === "call"
readonly property bool isTalkReplyPossible: model.conversationToken !== ""
property bool isTalkReplyOptionVisible: model.messageSent !== ""
readonly property bool isCallActivity: model.objectType === "call"

property color adjustedHeaderColor: Theme.darkMode ? Qt.lighter(UserModel.currentUser.headerColor, 2)
: Qt.darker(UserModel.currentUser.headerColor, 1.5)
Expand Down
6 changes: 1 addition & 5 deletions src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,7 @@ QVariantList ActivityListModel::convertLinksToActionButtons(const Activity &acti
}

for (const auto &activityLink : activity._links) {
if (activityLink._primary
|| activityLink._verb == QStringLiteral("DELETE")
|| activityLink._verb == QStringLiteral("WEB")) {
customList << ActivityListModel::convertLinkToActionButton(activityLink);
}
customList << ActivityListModel::convertLinkToActionButton(activityLink);
}

return customList;
Expand Down
23 changes: 16 additions & 7 deletions src/gui/tray/notificationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,36 @@ void ServerNotificationHandler::slotNotificationsReceived(const QJsonDocument &j
if (a._objectType == "chat" || a._objectType == "call" || a._objectType == "room") {
const auto objectId = json.value("object_id").toString();
const auto objectIdData = objectId.split("/");

ActivityLink al;
al._label = tr("Reply");
al._verb = "REPLY";
al._primary = true;

a._talkNotificationData.conversationToken = objectIdData.first();

if (a._objectType == "chat" && objectIdData.size() > 1) {
a._talkNotificationData.messageId = objectIdData.last();
} else {
qCInfo(lcServerNotification) << "Replying directly to Talk conversation" << a._talkNotificationData.conversationToken << "will not be possible because the notification doesn't contain the message ID.";
}

ActivityLink al;
al._label = tr("Reply");
al._verb = "REPLY";
al._primary = true;
a._links.insert(0, al);
if (a._subjectRichParameters.contains("user")) {

// callback then it is the primary action
if (a._objectType == "call") {
al._primary = false;
}

if(a._subjectRichParameters.contains("user")) {
a._talkNotificationData.userAvatar = ai->account()->url().toString() + QStringLiteral("/index.php/avatar/") + a._subjectRichParameters["user"].id + QStringLiteral("/128");
}

// We want to serve incoming call dialogs to the user for calls that
if(a._objectType == "call" && a._dateTime.secsTo(QDateTime::currentDateTime()) < 120) {
if (a._objectType == "call" && a._dateTime.secsTo(QDateTime::currentDateTime()) < 120) {
callList.append(a);
}

a._links.insert(al._primary? 0 : a._links.size(), al);
}

a._status = 0;
Expand Down
35 changes: 20 additions & 15 deletions test/testactivitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,20 @@ class FakeRemoteActivityStorage

QJsonArray actionsArray;

QJsonObject replyAction;
replyAction.insert(QStringLiteral("label"), QStringLiteral("Reply"));
replyAction.insert(QStringLiteral("link"), QStringLiteral(""));
replyAction.insert(QStringLiteral("type"), QStringLiteral("REPLY"));
replyAction.insert(QStringLiteral("primary"), true);
actionsArray.push_back(replyAction);

QJsonObject primaryAction;
primaryAction.insert(QStringLiteral("label"), QStringLiteral("Call back"));
primaryAction.insert(QStringLiteral("link"), QStringLiteral("http://cloud.example.de/call/9p4vjdzd"));
primaryAction.insert(QStringLiteral("type"), QStringLiteral("WEB"));
primaryAction.insert(QStringLiteral("primary"), false);
primaryAction.insert(QStringLiteral("primary"), true);
actionsArray.push_back(primaryAction);

QJsonObject replyAction;
replyAction.insert(QStringLiteral("label"), QStringLiteral("Reply"));
replyAction.insert(QStringLiteral("link"), QStringLiteral(""));
replyAction.insert(QStringLiteral("type"), QStringLiteral("REPLY"));
replyAction.insert(QStringLiteral("primary"), false);
actionsArray.push_back(replyAction);

QJsonObject secondaryAction;
secondaryAction.insert(QStringLiteral("label"), QStringLiteral("Dismiss"));
secondaryAction.insert(QStringLiteral("link"),
Expand Down Expand Up @@ -669,7 +669,7 @@ private slots:
index.data(OCC::ActivityListModel::ActionsLinksContextMenuRole).toList();

// context menu must be shorter than total action links
QVERIFY(actionsLinks.isEmpty() || actionsLinksContextMenu.size() < actionsLinks.size());
QVERIFY(actionsLinksContextMenu.isEmpty() || actionsLinksContextMenu.size() < actionsLinks.size());

// context menu must not contain the primary action
QVERIFY(std::find_if(std::begin(actionsLinksContextMenu), std::end(actionsLinksContextMenu),
Expand All @@ -683,13 +683,18 @@ private slots:
const auto actionButtonsLinks =
index.data(OCC::ActivityListModel::ActionsLinksForActionButtonsRole).toList();

// both action links and buttons must contain a "REPLY" verb element at the beginning
QVERIFY(actionsLinks[0].value<OCC::ActivityLink>()._verb == QStringLiteral("REPLY"));
QVERIFY(actionButtonsLinks[0].value<OCC::ActivityLink>()._verb == QStringLiteral("REPLY"));
auto replyActionPos = 0;
if (objectType == QStringLiteral("call")) {
replyActionPos = 1;
}

// both action links and buttons must contain a "REPLY" verb element as secondary action
QVERIFY(actionsLinks[replyActionPos].value<OCC::ActivityLink>()._verb == QStringLiteral("REPLY"));
QVERIFY(actionButtonsLinks[replyActionPos].value<OCC::ActivityLink>()._verb == QStringLiteral("REPLY"));

// the first action button for chat must have image set
QVERIFY(!actionButtonsLinks[0].value<OCC::ActivityLink>()._imageSource.isEmpty());
QVERIFY(!actionButtonsLinks[0].value<OCC::ActivityLink>()._imageSourceHovered.isEmpty());
QVERIFY(!actionButtonsLinks[replyActionPos].value<OCC::ActivityLink>()._imageSource.isEmpty());
QVERIFY(!actionButtonsLinks[replyActionPos].value<OCC::ActivityLink>()._imageSourceHovered.isEmpty());

// logic for "chat" and other types of activities with multiple actions
if ((objectType == QStringLiteral("chat")
Expand All @@ -712,7 +717,7 @@ private slots:
}
} else if ((objectType == QStringLiteral("call"))) {
QVERIFY(
actionButtonsLinks[1].value<OCC::ActivityLink>()._label == QStringLiteral("Call back"));
actionButtonsLinks[0].value<OCC::ActivityLink>()._label == QStringLiteral("Call back"));
}
} else {
QVERIFY(actionsLinks[0].value<OCC::ActivityLink>()._label == QStringLiteral("Dismiss"));
Expand Down