Changeset View
Changeset View
Standalone View
Standalone View
src/client/push-rules-desc.cpp
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | static bool isMemberCountIsValid(const json &is) | ||||
| auto isStr = is.template get<std::string>(); | auto isStr = is.template get<std::string>(); | ||||
| return is.is_string() && boost::regex_match(isStr, memberCountIsRegex); | return is.is_string() && boost::regex_match(isStr, memberCountIsRegex); | ||||
| } | } | ||||
| static std::function<bool(int)> parseMemberCountIs(const json &is) | static std::function<bool(int)> parseMemberCountIs(const json &is) | ||||
| { | { | ||||
| boost::smatch m; | boost::smatch m; | ||||
| auto isStr = is.template get<std::string>(); | auto isStr = is.template get<std::string>(); | ||||
| auto res = boost::regex_match(isStr, m, memberCountIsRegex); | boost::regex_match(isStr, m, memberCountIsRegex); | ||||
| auto targetStr = m[2].str(); | auto targetStr = m[2].str(); | ||||
| int target; | int target; | ||||
| std::from_chars(targetStr.data(), targetStr.data() + targetStr.size(), target); | std::from_chars(targetStr.data(), targetStr.data() + targetStr.size(), target); | ||||
| if (m[1] == "" || m[1] == "==") { | if (m[1] == "" || m[1] == "==") { | ||||
| return [target](auto memberCount) { return memberCount == target; }; | return [target](auto memberCount) { return memberCount == target; }; | ||||
| } else if (m[1] == ">") { | } else if (m[1] == ">") { | ||||
| return [target](auto memberCount) { return memberCount > target; }; | return [target](auto memberCount) { return memberCount > target; }; | ||||
| } else if (m[1] == "<") { | } else if (m[1] == "<") { | ||||
| ▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | bool PushRulesDescPrivate::matchP(std::string ruleSetName, const json &rule, const Event &e, const RoomModel &room) const | ||||
| return false; | return false; | ||||
| } | } | ||||
| ); | ); | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| PushAction PushRulesDescPrivate::handleRule(std::string ruleSetName, const json &rule, const Event &e, const RoomModel &room) const | PushAction PushRulesDescPrivate::handleRule([[maybe_unused]] std::string ruleSetName, const json &rule, [[maybe_unused]] const Event &e, [[maybe_unused]] const RoomModel &room) const | ||||
| { | { | ||||
| auto actions = rule.at("actions"); | auto actions = rule.at("actions"); | ||||
| auto res = PushAction{ | auto res = PushAction{ | ||||
| /* shouldNotify */ false, | /* shouldNotify */ false, | ||||
| /* sound */ std::nullopt, | /* sound */ std::nullopt, | ||||
| /* shouldHighlight */ false, | /* shouldHighlight */ false, | ||||
| }; | }; | ||||
| if (std::find(actions.begin(), actions.end(), "notify") != actions.end()) { | if (std::find(actions.begin(), actions.end(), "notify") != actions.end()) { | ||||
| Show All 39 Lines | namespace Kazv | ||||
| PushAction PushRulesDesc::handle(const Event &e, const RoomModel &room) const | PushAction PushRulesDesc::handle(const Event &e, const RoomModel &room) const | ||||
| { | { | ||||
| auto ruleOpt = m_d->matchRule(e, room); | auto ruleOpt = m_d->matchRule(e, room); | ||||
| if (ruleOpt.has_value()) { | if (ruleOpt.has_value()) { | ||||
| auto [ruleSetName, rule] = ruleOpt.value(); | auto [ruleSetName, rule] = ruleOpt.value(); | ||||
| return m_d->handleRule(ruleSetName, rule, e, room); | return m_d->handleRule(ruleSetName, rule, e, room); | ||||
| } | } | ||||
| return {false}; | return {false, std::nullopt, false}; | ||||
| } | } | ||||
| } | } | ||||