base_rules.rs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. // Copyright 2022 The Matrix.org Foundation C.I.C.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //! Contains the definitions of the "base" push rules.
  15. use std::borrow::Cow;
  16. use std::collections::HashMap;
  17. use lazy_static::lazy_static;
  18. use serde_json::Value;
  19. use super::KnownCondition;
  20. use crate::push::Action;
  21. use crate::push::Condition;
  22. use crate::push::EventMatchCondition;
  23. use crate::push::PushRule;
  24. use crate::push::RelatedEventMatchCondition;
  25. use crate::push::SetTweak;
  26. use crate::push::TweakValue;
  27. const HIGHLIGHT_ACTION: Action = Action::SetTweak(SetTweak {
  28. set_tweak: Cow::Borrowed("highlight"),
  29. value: None,
  30. other_keys: Value::Null,
  31. });
  32. const HIGHLIGHT_FALSE_ACTION: Action = Action::SetTweak(SetTweak {
  33. set_tweak: Cow::Borrowed("highlight"),
  34. value: Some(TweakValue::Other(Value::Bool(false))),
  35. other_keys: Value::Null,
  36. });
  37. const SOUND_ACTION: Action = Action::SetTweak(SetTweak {
  38. set_tweak: Cow::Borrowed("sound"),
  39. value: Some(TweakValue::String(Cow::Borrowed("default"))),
  40. other_keys: Value::Null,
  41. });
  42. const RING_ACTION: Action = Action::SetTweak(SetTweak {
  43. set_tweak: Cow::Borrowed("sound"),
  44. value: Some(TweakValue::String(Cow::Borrowed("ring"))),
  45. other_keys: Value::Null,
  46. });
  47. pub const BASE_PREPEND_OVERRIDE_RULES: &[PushRule] = &[PushRule {
  48. rule_id: Cow::Borrowed("global/override/.m.rule.master"),
  49. priority_class: 5,
  50. conditions: Cow::Borrowed(&[]),
  51. actions: Cow::Borrowed(&[Action::DontNotify]),
  52. default: true,
  53. default_enabled: false,
  54. }];
  55. pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
  56. PushRule {
  57. rule_id: Cow::Borrowed("global/override/.m.rule.suppress_notices"),
  58. priority_class: 5,
  59. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  60. EventMatchCondition {
  61. key: Cow::Borrowed("content.msgtype"),
  62. pattern: Some(Cow::Borrowed("m.notice")),
  63. pattern_type: None,
  64. },
  65. ))]),
  66. actions: Cow::Borrowed(&[Action::DontNotify]),
  67. default: true,
  68. default_enabled: true,
  69. },
  70. PushRule {
  71. rule_id: Cow::Borrowed("global/override/.m.rule.invite_for_me"),
  72. priority_class: 5,
  73. conditions: Cow::Borrowed(&[
  74. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  75. key: Cow::Borrowed("type"),
  76. pattern: Some(Cow::Borrowed("m.room.member")),
  77. pattern_type: None,
  78. })),
  79. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  80. key: Cow::Borrowed("content.membership"),
  81. pattern: Some(Cow::Borrowed("invite")),
  82. pattern_type: None,
  83. })),
  84. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  85. key: Cow::Borrowed("state_key"),
  86. pattern: None,
  87. pattern_type: Some(Cow::Borrowed("user_id")),
  88. })),
  89. ]),
  90. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION, SOUND_ACTION]),
  91. default: true,
  92. default_enabled: true,
  93. },
  94. PushRule {
  95. rule_id: Cow::Borrowed("global/override/.m.rule.member_event"),
  96. priority_class: 5,
  97. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  98. EventMatchCondition {
  99. key: Cow::Borrowed("type"),
  100. pattern: Some(Cow::Borrowed("m.room.member")),
  101. pattern_type: None,
  102. },
  103. ))]),
  104. actions: Cow::Borrowed(&[Action::DontNotify]),
  105. default: true,
  106. default_enabled: true,
  107. },
  108. PushRule {
  109. rule_id: Cow::Borrowed("global/override/.im.nheko.msc3664.reply"),
  110. priority_class: 5,
  111. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::RelatedEventMatch(
  112. RelatedEventMatchCondition {
  113. key: Some(Cow::Borrowed("sender")),
  114. pattern: None,
  115. pattern_type: Some(Cow::Borrowed("user_id")),
  116. rel_type: Cow::Borrowed("m.in_reply_to"),
  117. include_fallbacks: None,
  118. },
  119. ))]),
  120. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  121. default: true,
  122. default_enabled: true,
  123. },
  124. PushRule {
  125. rule_id: Cow::Borrowed("global/override/.m.rule.contains_display_name"),
  126. priority_class: 5,
  127. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::ContainsDisplayName)]),
  128. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  129. default: true,
  130. default_enabled: true,
  131. },
  132. PushRule {
  133. rule_id: Cow::Borrowed("global/override/.m.rule.roomnotif"),
  134. priority_class: 5,
  135. conditions: Cow::Borrowed(&[
  136. Condition::Known(KnownCondition::SenderNotificationPermission {
  137. key: Cow::Borrowed("room"),
  138. }),
  139. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  140. key: Cow::Borrowed("content.body"),
  141. pattern: Some(Cow::Borrowed("@room")),
  142. pattern_type: None,
  143. })),
  144. ]),
  145. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  146. default: true,
  147. default_enabled: true,
  148. },
  149. PushRule {
  150. rule_id: Cow::Borrowed("global/override/.m.rule.tombstone"),
  151. priority_class: 5,
  152. conditions: Cow::Borrowed(&[
  153. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  154. key: Cow::Borrowed("type"),
  155. pattern: Some(Cow::Borrowed("m.room.tombstone")),
  156. pattern_type: None,
  157. })),
  158. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  159. key: Cow::Borrowed("state_key"),
  160. pattern: Some(Cow::Borrowed("")),
  161. pattern_type: None,
  162. })),
  163. ]),
  164. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  165. default: true,
  166. default_enabled: true,
  167. },
  168. PushRule {
  169. rule_id: Cow::Borrowed("global/override/.m.rule.reaction"),
  170. priority_class: 5,
  171. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  172. EventMatchCondition {
  173. key: Cow::Borrowed("type"),
  174. pattern: Some(Cow::Borrowed("m.reaction")),
  175. pattern_type: None,
  176. },
  177. ))]),
  178. actions: Cow::Borrowed(&[Action::DontNotify]),
  179. default: true,
  180. default_enabled: true,
  181. },
  182. PushRule {
  183. rule_id: Cow::Borrowed("global/override/.m.rule.room.server_acl"),
  184. priority_class: 5,
  185. conditions: Cow::Borrowed(&[
  186. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  187. key: Cow::Borrowed("type"),
  188. pattern: Some(Cow::Borrowed("m.room.server_acl")),
  189. pattern_type: None,
  190. })),
  191. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  192. key: Cow::Borrowed("state_key"),
  193. pattern: Some(Cow::Borrowed("")),
  194. pattern_type: None,
  195. })),
  196. ]),
  197. actions: Cow::Borrowed(&[]),
  198. default: true,
  199. default_enabled: true,
  200. },
  201. ];
  202. pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
  203. rule_id: Cow::Borrowed("global/content/.m.rule.contains_user_name"),
  204. priority_class: 4,
  205. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  206. EventMatchCondition {
  207. key: Cow::Borrowed("content.body"),
  208. pattern: None,
  209. pattern_type: Some(Cow::Borrowed("user_localpart")),
  210. },
  211. ))]),
  212. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  213. default: true,
  214. default_enabled: true,
  215. }];
  216. pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
  217. PushRule {
  218. rule_id: Cow::Borrowed("global/underride/.m.rule.call"),
  219. priority_class: 1,
  220. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  221. EventMatchCondition {
  222. key: Cow::Borrowed("type"),
  223. pattern: Some(Cow::Borrowed("m.call.invite")),
  224. pattern_type: None,
  225. },
  226. ))]),
  227. actions: Cow::Borrowed(&[Action::Notify, RING_ACTION, HIGHLIGHT_FALSE_ACTION]),
  228. default: true,
  229. default_enabled: true,
  230. },
  231. PushRule {
  232. rule_id: Cow::Borrowed("global/underride/.m.rule.room_one_to_one"),
  233. priority_class: 1,
  234. conditions: Cow::Borrowed(&[
  235. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  236. key: Cow::Borrowed("type"),
  237. pattern: Some(Cow::Borrowed("m.room.message")),
  238. pattern_type: None,
  239. })),
  240. Condition::Known(KnownCondition::RoomMemberCount {
  241. is: Some(Cow::Borrowed("2")),
  242. }),
  243. ]),
  244. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  245. default: true,
  246. default_enabled: true,
  247. },
  248. PushRule {
  249. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted_room_one_to_one"),
  250. priority_class: 1,
  251. conditions: Cow::Borrowed(&[
  252. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  253. key: Cow::Borrowed("type"),
  254. pattern: Some(Cow::Borrowed("m.room.encrypted")),
  255. pattern_type: None,
  256. })),
  257. Condition::Known(KnownCondition::RoomMemberCount {
  258. is: Some(Cow::Borrowed("2")),
  259. }),
  260. ]),
  261. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  262. default: true,
  263. default_enabled: true,
  264. },
  265. PushRule {
  266. rule_id: Cow::Borrowed(
  267. "global/underride/.org.matrix.msc3933.rule.extensible.encrypted_room_one_to_one",
  268. ),
  269. priority_class: 1,
  270. conditions: Cow::Borrowed(&[
  271. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  272. key: Cow::Borrowed("type"),
  273. // MSC3933: Type changed from template rule - see MSC.
  274. pattern: Some(Cow::Borrowed("org.matrix.msc1767.encrypted")),
  275. pattern_type: None,
  276. })),
  277. Condition::Known(KnownCondition::RoomMemberCount {
  278. is: Some(Cow::Borrowed("2")),
  279. }),
  280. // MSC3933: Add condition on top of template rule - see MSC.
  281. Condition::Known(KnownCondition::RoomVersionSupports {
  282. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  283. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  284. }),
  285. ]),
  286. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  287. default: true,
  288. default_enabled: true,
  289. },
  290. PushRule {
  291. rule_id: Cow::Borrowed(
  292. "global/underride/.org.matrix.msc3933.rule.extensible.message.room_one_to_one",
  293. ),
  294. priority_class: 1,
  295. conditions: Cow::Borrowed(&[
  296. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  297. key: Cow::Borrowed("type"),
  298. // MSC3933: Type changed from template rule - see MSC.
  299. pattern: Some(Cow::Borrowed("org.matrix.msc1767.message")),
  300. pattern_type: None,
  301. })),
  302. Condition::Known(KnownCondition::RoomMemberCount {
  303. is: Some(Cow::Borrowed("2")),
  304. }),
  305. // MSC3933: Add condition on top of template rule - see MSC.
  306. Condition::Known(KnownCondition::RoomVersionSupports {
  307. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  308. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  309. }),
  310. ]),
  311. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  312. default: true,
  313. default_enabled: true,
  314. },
  315. PushRule {
  316. rule_id: Cow::Borrowed(
  317. "global/underride/.org.matrix.msc3933.rule.extensible.file.room_one_to_one",
  318. ),
  319. priority_class: 1,
  320. conditions: Cow::Borrowed(&[
  321. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  322. key: Cow::Borrowed("type"),
  323. // MSC3933: Type changed from template rule - see MSC.
  324. pattern: Some(Cow::Borrowed("org.matrix.msc1767.file")),
  325. pattern_type: None,
  326. })),
  327. Condition::Known(KnownCondition::RoomMemberCount {
  328. is: Some(Cow::Borrowed("2")),
  329. }),
  330. // MSC3933: Add condition on top of template rule - see MSC.
  331. Condition::Known(KnownCondition::RoomVersionSupports {
  332. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  333. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  334. }),
  335. ]),
  336. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  337. default: true,
  338. default_enabled: true,
  339. },
  340. PushRule {
  341. rule_id: Cow::Borrowed(
  342. "global/underride/.org.matrix.msc3933.rule.extensible.image.room_one_to_one",
  343. ),
  344. priority_class: 1,
  345. conditions: Cow::Borrowed(&[
  346. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  347. key: Cow::Borrowed("type"),
  348. // MSC3933: Type changed from template rule - see MSC.
  349. pattern: Some(Cow::Borrowed("org.matrix.msc1767.image")),
  350. pattern_type: None,
  351. })),
  352. Condition::Known(KnownCondition::RoomMemberCount {
  353. is: Some(Cow::Borrowed("2")),
  354. }),
  355. // MSC3933: Add condition on top of template rule - see MSC.
  356. Condition::Known(KnownCondition::RoomVersionSupports {
  357. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  358. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  359. }),
  360. ]),
  361. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  362. default: true,
  363. default_enabled: true,
  364. },
  365. PushRule {
  366. rule_id: Cow::Borrowed(
  367. "global/underride/.org.matrix.msc3933.rule.extensible.video.room_one_to_one",
  368. ),
  369. priority_class: 1,
  370. conditions: Cow::Borrowed(&[
  371. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  372. key: Cow::Borrowed("type"),
  373. // MSC3933: Type changed from template rule - see MSC.
  374. pattern: Some(Cow::Borrowed("org.matrix.msc1767.video")),
  375. pattern_type: None,
  376. })),
  377. Condition::Known(KnownCondition::RoomMemberCount {
  378. is: Some(Cow::Borrowed("2")),
  379. }),
  380. // MSC3933: Add condition on top of template rule - see MSC.
  381. Condition::Known(KnownCondition::RoomVersionSupports {
  382. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  383. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  384. }),
  385. ]),
  386. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  387. default: true,
  388. default_enabled: true,
  389. },
  390. PushRule {
  391. rule_id: Cow::Borrowed(
  392. "global/underride/.org.matrix.msc3933.rule.extensible.audio.room_one_to_one",
  393. ),
  394. priority_class: 1,
  395. conditions: Cow::Borrowed(&[
  396. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  397. key: Cow::Borrowed("type"),
  398. // MSC3933: Type changed from template rule - see MSC.
  399. pattern: Some(Cow::Borrowed("org.matrix.msc1767.audio")),
  400. pattern_type: None,
  401. })),
  402. Condition::Known(KnownCondition::RoomMemberCount {
  403. is: Some(Cow::Borrowed("2")),
  404. }),
  405. // MSC3933: Add condition on top of template rule - see MSC.
  406. Condition::Known(KnownCondition::RoomVersionSupports {
  407. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  408. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  409. }),
  410. ]),
  411. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  412. default: true,
  413. default_enabled: true,
  414. },
  415. PushRule {
  416. rule_id: Cow::Borrowed("global/underride/.m.rule.message"),
  417. priority_class: 1,
  418. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  419. EventMatchCondition {
  420. key: Cow::Borrowed("type"),
  421. pattern: Some(Cow::Borrowed("m.room.message")),
  422. pattern_type: None,
  423. },
  424. ))]),
  425. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  426. default: true,
  427. default_enabled: true,
  428. },
  429. PushRule {
  430. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted"),
  431. priority_class: 1,
  432. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  433. EventMatchCondition {
  434. key: Cow::Borrowed("type"),
  435. pattern: Some(Cow::Borrowed("m.room.encrypted")),
  436. pattern_type: None,
  437. },
  438. ))]),
  439. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  440. default: true,
  441. default_enabled: true,
  442. },
  443. PushRule {
  444. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.encrypted"),
  445. priority_class: 1,
  446. conditions: Cow::Borrowed(&[
  447. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  448. key: Cow::Borrowed("type"),
  449. // MSC3933: Type changed from template rule - see MSC.
  450. pattern: Some(Cow::Borrowed("m.encrypted")),
  451. pattern_type: None,
  452. })),
  453. // MSC3933: Add condition on top of template rule - see MSC.
  454. Condition::Known(KnownCondition::RoomVersionSupports {
  455. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  456. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  457. }),
  458. ]),
  459. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  460. default: true,
  461. default_enabled: true,
  462. },
  463. PushRule {
  464. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.message"),
  465. priority_class: 1,
  466. conditions: Cow::Borrowed(&[
  467. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  468. key: Cow::Borrowed("type"),
  469. // MSC3933: Type changed from template rule - see MSC.
  470. pattern: Some(Cow::Borrowed("m.message")),
  471. pattern_type: None,
  472. })),
  473. // MSC3933: Add condition on top of template rule - see MSC.
  474. Condition::Known(KnownCondition::RoomVersionSupports {
  475. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  476. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  477. }),
  478. ]),
  479. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  480. default: true,
  481. default_enabled: true,
  482. },
  483. PushRule {
  484. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.file"),
  485. priority_class: 1,
  486. conditions: Cow::Borrowed(&[
  487. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  488. key: Cow::Borrowed("type"),
  489. // MSC3933: Type changed from template rule - see MSC.
  490. pattern: Some(Cow::Borrowed("m.file")),
  491. pattern_type: None,
  492. })),
  493. // MSC3933: Add condition on top of template rule - see MSC.
  494. Condition::Known(KnownCondition::RoomVersionSupports {
  495. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  496. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  497. }),
  498. ]),
  499. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  500. default: true,
  501. default_enabled: true,
  502. },
  503. PushRule {
  504. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.image"),
  505. priority_class: 1,
  506. conditions: Cow::Borrowed(&[
  507. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  508. key: Cow::Borrowed("type"),
  509. // MSC3933: Type changed from template rule - see MSC.
  510. pattern: Some(Cow::Borrowed("m.image")),
  511. pattern_type: None,
  512. })),
  513. // MSC3933: Add condition on top of template rule - see MSC.
  514. Condition::Known(KnownCondition::RoomVersionSupports {
  515. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  516. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  517. }),
  518. ]),
  519. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  520. default: true,
  521. default_enabled: true,
  522. },
  523. PushRule {
  524. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.video"),
  525. priority_class: 1,
  526. conditions: Cow::Borrowed(&[
  527. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  528. key: Cow::Borrowed("type"),
  529. // MSC3933: Type changed from template rule - see MSC.
  530. pattern: Some(Cow::Borrowed("m.video")),
  531. pattern_type: None,
  532. })),
  533. // MSC3933: Add condition on top of template rule - see MSC.
  534. Condition::Known(KnownCondition::RoomVersionSupports {
  535. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  536. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  537. }),
  538. ]),
  539. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  540. default: true,
  541. default_enabled: true,
  542. },
  543. PushRule {
  544. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.audio"),
  545. priority_class: 1,
  546. conditions: Cow::Borrowed(&[
  547. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  548. key: Cow::Borrowed("type"),
  549. // MSC3933: Type changed from template rule - see MSC.
  550. pattern: Some(Cow::Borrowed("m.audio")),
  551. pattern_type: None,
  552. })),
  553. // MSC3933: Add condition on top of template rule - see MSC.
  554. Condition::Known(KnownCondition::RoomVersionSupports {
  555. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  556. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  557. }),
  558. ]),
  559. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  560. default: true,
  561. default_enabled: true,
  562. },
  563. PushRule {
  564. rule_id: Cow::Borrowed("global/underride/.im.vector.jitsi"),
  565. priority_class: 1,
  566. conditions: Cow::Borrowed(&[
  567. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  568. key: Cow::Borrowed("type"),
  569. pattern: Some(Cow::Borrowed("im.vector.modular.widgets")),
  570. pattern_type: None,
  571. })),
  572. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  573. key: Cow::Borrowed("content.type"),
  574. pattern: Some(Cow::Borrowed("jitsi")),
  575. pattern_type: None,
  576. })),
  577. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  578. key: Cow::Borrowed("state_key"),
  579. pattern: Some(Cow::Borrowed("*")),
  580. pattern_type: None,
  581. })),
  582. ]),
  583. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  584. default: true,
  585. default_enabled: true,
  586. },
  587. ];
  588. lazy_static! {
  589. pub static ref BASE_RULES_BY_ID: HashMap<&'static str, &'static PushRule> =
  590. BASE_PREPEND_OVERRIDE_RULES
  591. .iter()
  592. .chain(BASE_APPEND_OVERRIDE_RULES.iter())
  593. .chain(BASE_APPEND_CONTENT_RULES.iter())
  594. .chain(BASE_APPEND_UNDERRIDE_RULES.iter())
  595. .map(|rule| { (&*rule.rule_id, rule) })
  596. .collect();
  597. }