Page MenuHomePhorge

D20.1731171544.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D20.1731171544.diff

diff --git a/src/client/push-rules-desc.hpp b/src/client/push-rules-desc.hpp
--- a/src/client/push-rules-desc.hpp
+++ b/src/client/push-rules-desc.hpp
@@ -8,6 +8,7 @@
#include <libkazv-config.hpp>
#include <memory>
+#include <optional>
#include <copy-helper.hpp>
@@ -25,6 +26,12 @@
{
/// Whether the client should notify about this event.
bool shouldNotify;
+ /// The sound of the notification as defined in the spec.
+ /// If the notification should not ring, it is set as
+ /// `std::nullopt`.
+ std::optional<std::string> sound;
+ /// Whether the client should highlight the event.
+ bool shouldHighlight;
};
class PushRulesDesc
diff --git a/src/client/push-rules-desc.cpp b/src/client/push-rules-desc.cpp
--- a/src/client/push-rules-desc.cpp
+++ b/src/client/push-rules-desc.cpp
@@ -131,8 +131,10 @@
} else if (act.is_object()) {
json validatedAct = json::object();
if (cast(validatedAct, act, "set_tweak", identValidate([](const auto &t) { return t == "sound"; }))) {
+ validatedAct["value"] = "default";
cast(validatedAct, act, "value", identValidate(&json::is_string));
} else if (cast(validatedAct, act, "set_tweak", identValidate([](const auto &t) { return t == "highlight"; }))) {
+ validatedAct["value"] = true;
cast(validatedAct, act, "value", identValidate(&json::is_boolean));
}
return {true, validatedAct};
@@ -277,10 +279,31 @@
PushAction PushRulesDescPrivate::handleRule(std::string ruleSetName, const json &rule, const Event &e, const RoomModel &room) const
{
auto actions = rule.at("actions");
+ auto res = PushAction{
+ /* shouldNotify */ false,
+ /* sound */ std::nullopt,
+ /* shouldHighlight */ false,
+ };
if (std::find(actions.begin(), actions.end(), "notify") != actions.end()) {
- return {true};
+ res.shouldNotify = true;
}
- return {false};
+ if (auto it = std::find_if(
+ actions.begin(), actions.end(), [](const auto &a) {
+ return a.is_object()
+ && a.contains("set_tweak")
+ && a["set_tweak"] == "sound";
+ }); it != actions.end()) {
+ res.sound = (*it)["value"].template get<std::string>();
+ }
+ if (auto it = std::find_if(
+ actions.begin(), actions.end(), [](const auto &a) {
+ return a.is_object()
+ && a.contains("set_tweak")
+ && a["set_tweak"] == "highlight";
+ }); it != actions.end()) {
+ res.shouldHighlight = (*it)["value"].template get<bool>();
+ }
+ return res;
}
PushRulesDesc::PushRulesDesc()
diff --git a/src/tests/client/push-rules-desc-test.cpp b/src/tests/client/push-rules-desc-test.cpp
--- a/src/tests/client/push-rules-desc-test.cpp
+++ b/src/tests/client/push-rules-desc-test.cpp
@@ -164,6 +164,44 @@
REQUIRE(validated.first);
REQUIRE(validated.second == rule);
}
+
+ SECTION("action set_tweak sound")
+ {
+ rule["actions"] = json::array({{
+ {"set_tweak", "sound"},
+ {"value", "default"},
+ }});
+
+ auto validated = validateRule("override", rule);
+ REQUIRE(validated.first);
+ REQUIRE(validated.second == rule);
+
+ auto ruleWithoutValue = rule;
+ ruleWithoutValue["actions"][0].erase("value");
+
+ validated = validateRule("override", ruleWithoutValue);
+ REQUIRE(validated.first);
+ REQUIRE(validated.second == rule);
+ }
+
+ SECTION("action set_tweak highlight")
+ {
+ rule["actions"] = json::array({{
+ {"set_tweak", "highlight"},
+ {"value", true},
+ }});
+
+ auto validated = validateRule("override", rule);
+ REQUIRE(validated.first);
+ REQUIRE(validated.second == rule);
+
+ auto ruleWithoutValue = rule;
+ ruleWithoutValue["actions"][0].erase("value");
+
+ validated = validateRule("override", ruleWithoutValue);
+ REQUIRE(validated.first);
+ REQUIRE(validated.second == rule);
+ }
}
TEST_CASE("validatePushRules()", "[client][push-rules]")
@@ -490,4 +528,26 @@
rulesContent["global"]["override"].push_back(rule);
REQUIRE(PushRulesDesc(makePushRulesEvent(rulesContent)).handle(makeEvent(), room).shouldNotify);
}
+
+ SECTION("action set_tweak sound")
+ {
+ auto rule = catchAllRule;
+ rule["actions"].push_back(json{
+ {"set_tweak", "sound"},
+ {"value", "some"},
+ });
+ rulesContent["global"]["override"].push_back(rule);
+ REQUIRE(PushRulesDesc(makePushRulesEvent(rulesContent)).handle(makeEvent(), room).sound == "some");
+ }
+
+ SECTION("action set_tweak highlight")
+ {
+ auto rule = catchAllRule;
+ rule["actions"].push_back(json{
+ {"set_tweak", "highlight"},
+ {"value", true},
+ });
+ rulesContent["global"]["override"].push_back(rule);
+ REQUIRE(PushRulesDesc(makePushRulesEvent(rulesContent)).handle(makeEvent(), room).shouldHighlight);
+ }
}
diff --git a/src/tests/client/push-rules-test-util.hpp b/src/tests/client/push-rules-test-util.hpp
--- a/src/tests/client/push-rules-test-util.hpp
+++ b/src/tests/client/push-rules-test-util.hpp
@@ -95,7 +95,8 @@
"value": "default"
},
{
- "set_tweak": "highlight"
+ "set_tweak": "highlight",
+ "value": true
}
]
})"_json;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 8:59 AM (21 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36752
Default Alt Text
D20.1731171544.diff (5 KB)

Event Timeline