Merge pull request #4985 from nextcloud/bugfix/primary-buttons

Fix 'Reply' primay property.
This commit is contained in:
Camila 2022-09-29 18:34:01 +02:00 committed by GitHub
commit 31478bbd63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 28 deletions

View File

@ -15,7 +15,6 @@ ItemDelegate {
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)

View File

@ -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;

View File

@ -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);
}
QUrl link(json.value("link").toString());

View File

@ -236,20 +236,20 @@ public:
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"),
@ -660,7 +660,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),
@ -674,13 +674,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")
@ -703,7 +708,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"));