You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

708 lines
28 KiB

  1. // Copyright 2022, 2023 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(".org.matrix.msc3952.is_user_mentioned"),
  126. priority_class: 5,
  127. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::IsUserMention)]),
  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.contains_display_name"),
  134. priority_class: 5,
  135. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::ContainsDisplayName)]),
  136. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  137. default: true,
  138. default_enabled: true,
  139. },
  140. PushRule {
  141. rule_id: Cow::Borrowed(".org.matrix.msc3952.is_room_mentioned"),
  142. priority_class: 5,
  143. conditions: Cow::Borrowed(&[
  144. Condition::Known(KnownCondition::IsRoomMention),
  145. Condition::Known(KnownCondition::SenderNotificationPermission {
  146. key: Cow::Borrowed("room"),
  147. }),
  148. ]),
  149. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  150. default: true,
  151. default_enabled: true,
  152. },
  153. PushRule {
  154. rule_id: Cow::Borrowed("global/override/.m.rule.roomnotif"),
  155. priority_class: 5,
  156. conditions: Cow::Borrowed(&[
  157. Condition::Known(KnownCondition::SenderNotificationPermission {
  158. key: Cow::Borrowed("room"),
  159. }),
  160. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  161. key: Cow::Borrowed("content.body"),
  162. pattern: Some(Cow::Borrowed("@room")),
  163. pattern_type: None,
  164. })),
  165. ]),
  166. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  167. default: true,
  168. default_enabled: true,
  169. },
  170. PushRule {
  171. rule_id: Cow::Borrowed("global/override/.m.rule.tombstone"),
  172. priority_class: 5,
  173. conditions: Cow::Borrowed(&[
  174. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  175. key: Cow::Borrowed("type"),
  176. pattern: Some(Cow::Borrowed("m.room.tombstone")),
  177. pattern_type: None,
  178. })),
  179. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  180. key: Cow::Borrowed("state_key"),
  181. pattern: Some(Cow::Borrowed("")),
  182. pattern_type: None,
  183. })),
  184. ]),
  185. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  186. default: true,
  187. default_enabled: true,
  188. },
  189. PushRule {
  190. rule_id: Cow::Borrowed("global/override/.m.rule.reaction"),
  191. priority_class: 5,
  192. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  193. EventMatchCondition {
  194. key: Cow::Borrowed("type"),
  195. pattern: Some(Cow::Borrowed("m.reaction")),
  196. pattern_type: None,
  197. },
  198. ))]),
  199. actions: Cow::Borrowed(&[Action::DontNotify]),
  200. default: true,
  201. default_enabled: true,
  202. },
  203. PushRule {
  204. rule_id: Cow::Borrowed("global/override/.m.rule.room.server_acl"),
  205. priority_class: 5,
  206. conditions: Cow::Borrowed(&[
  207. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  208. key: Cow::Borrowed("type"),
  209. pattern: Some(Cow::Borrowed("m.room.server_acl")),
  210. pattern_type: None,
  211. })),
  212. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  213. key: Cow::Borrowed("state_key"),
  214. pattern: Some(Cow::Borrowed("")),
  215. pattern_type: None,
  216. })),
  217. ]),
  218. actions: Cow::Borrowed(&[]),
  219. default: true,
  220. default_enabled: true,
  221. },
  222. PushRule {
  223. rule_id: Cow::Borrowed("global/override/.org.matrix.msc3930.rule.poll_response"),
  224. priority_class: 5,
  225. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  226. EventMatchCondition {
  227. key: Cow::Borrowed("type"),
  228. pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.response")),
  229. pattern_type: None,
  230. },
  231. ))]),
  232. actions: Cow::Borrowed(&[]),
  233. default: true,
  234. default_enabled: true,
  235. },
  236. ];
  237. pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
  238. rule_id: Cow::Borrowed("global/content/.m.rule.contains_user_name"),
  239. priority_class: 4,
  240. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  241. EventMatchCondition {
  242. key: Cow::Borrowed("content.body"),
  243. pattern: None,
  244. pattern_type: Some(Cow::Borrowed("user_localpart")),
  245. },
  246. ))]),
  247. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  248. default: true,
  249. default_enabled: true,
  250. }];
  251. pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
  252. PushRule {
  253. rule_id: Cow::Borrowed("global/underride/.m.rule.call"),
  254. priority_class: 1,
  255. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  256. EventMatchCondition {
  257. key: Cow::Borrowed("type"),
  258. pattern: Some(Cow::Borrowed("m.call.invite")),
  259. pattern_type: None,
  260. },
  261. ))]),
  262. actions: Cow::Borrowed(&[Action::Notify, RING_ACTION, HIGHLIGHT_FALSE_ACTION]),
  263. default: true,
  264. default_enabled: true,
  265. },
  266. PushRule {
  267. rule_id: Cow::Borrowed("global/underride/.m.rule.room_one_to_one"),
  268. priority_class: 1,
  269. conditions: Cow::Borrowed(&[
  270. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  271. key: Cow::Borrowed("type"),
  272. pattern: Some(Cow::Borrowed("m.room.message")),
  273. pattern_type: None,
  274. })),
  275. Condition::Known(KnownCondition::RoomMemberCount {
  276. is: Some(Cow::Borrowed("2")),
  277. }),
  278. ]),
  279. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  280. default: true,
  281. default_enabled: true,
  282. },
  283. PushRule {
  284. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted_room_one_to_one"),
  285. priority_class: 1,
  286. conditions: Cow::Borrowed(&[
  287. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  288. key: Cow::Borrowed("type"),
  289. pattern: Some(Cow::Borrowed("m.room.encrypted")),
  290. pattern_type: None,
  291. })),
  292. Condition::Known(KnownCondition::RoomMemberCount {
  293. is: Some(Cow::Borrowed("2")),
  294. }),
  295. ]),
  296. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  297. default: true,
  298. default_enabled: true,
  299. },
  300. PushRule {
  301. rule_id: Cow::Borrowed(
  302. "global/underride/.org.matrix.msc3933.rule.extensible.encrypted_room_one_to_one",
  303. ),
  304. priority_class: 1,
  305. conditions: Cow::Borrowed(&[
  306. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  307. key: Cow::Borrowed("type"),
  308. // MSC3933: Type changed from template rule - see MSC.
  309. pattern: Some(Cow::Borrowed("org.matrix.msc1767.encrypted")),
  310. pattern_type: None,
  311. })),
  312. Condition::Known(KnownCondition::RoomMemberCount {
  313. is: Some(Cow::Borrowed("2")),
  314. }),
  315. // MSC3933: Add condition on top of template rule - see MSC.
  316. Condition::Known(KnownCondition::RoomVersionSupports {
  317. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  318. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  319. }),
  320. ]),
  321. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  322. default: true,
  323. default_enabled: true,
  324. },
  325. PushRule {
  326. rule_id: Cow::Borrowed(
  327. "global/underride/.org.matrix.msc3933.rule.extensible.message.room_one_to_one",
  328. ),
  329. priority_class: 1,
  330. conditions: Cow::Borrowed(&[
  331. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  332. key: Cow::Borrowed("type"),
  333. // MSC3933: Type changed from template rule - see MSC.
  334. pattern: Some(Cow::Borrowed("org.matrix.msc1767.message")),
  335. pattern_type: None,
  336. })),
  337. Condition::Known(KnownCondition::RoomMemberCount {
  338. is: Some(Cow::Borrowed("2")),
  339. }),
  340. // MSC3933: Add condition on top of template rule - see MSC.
  341. Condition::Known(KnownCondition::RoomVersionSupports {
  342. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  343. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  344. }),
  345. ]),
  346. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  347. default: true,
  348. default_enabled: true,
  349. },
  350. PushRule {
  351. rule_id: Cow::Borrowed(
  352. "global/underride/.org.matrix.msc3933.rule.extensible.file.room_one_to_one",
  353. ),
  354. priority_class: 1,
  355. conditions: Cow::Borrowed(&[
  356. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  357. key: Cow::Borrowed("type"),
  358. // MSC3933: Type changed from template rule - see MSC.
  359. pattern: Some(Cow::Borrowed("org.matrix.msc1767.file")),
  360. pattern_type: None,
  361. })),
  362. Condition::Known(KnownCondition::RoomMemberCount {
  363. is: Some(Cow::Borrowed("2")),
  364. }),
  365. // MSC3933: Add condition on top of template rule - see MSC.
  366. Condition::Known(KnownCondition::RoomVersionSupports {
  367. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  368. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  369. }),
  370. ]),
  371. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  372. default: true,
  373. default_enabled: true,
  374. },
  375. PushRule {
  376. rule_id: Cow::Borrowed(
  377. "global/underride/.org.matrix.msc3933.rule.extensible.image.room_one_to_one",
  378. ),
  379. priority_class: 1,
  380. conditions: Cow::Borrowed(&[
  381. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  382. key: Cow::Borrowed("type"),
  383. // MSC3933: Type changed from template rule - see MSC.
  384. pattern: Some(Cow::Borrowed("org.matrix.msc1767.image")),
  385. pattern_type: None,
  386. })),
  387. Condition::Known(KnownCondition::RoomMemberCount {
  388. is: Some(Cow::Borrowed("2")),
  389. }),
  390. // MSC3933: Add condition on top of template rule - see MSC.
  391. Condition::Known(KnownCondition::RoomVersionSupports {
  392. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  393. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  394. }),
  395. ]),
  396. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  397. default: true,
  398. default_enabled: true,
  399. },
  400. PushRule {
  401. rule_id: Cow::Borrowed(
  402. "global/underride/.org.matrix.msc3933.rule.extensible.video.room_one_to_one",
  403. ),
  404. priority_class: 1,
  405. conditions: Cow::Borrowed(&[
  406. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  407. key: Cow::Borrowed("type"),
  408. // MSC3933: Type changed from template rule - see MSC.
  409. pattern: Some(Cow::Borrowed("org.matrix.msc1767.video")),
  410. pattern_type: None,
  411. })),
  412. Condition::Known(KnownCondition::RoomMemberCount {
  413. is: Some(Cow::Borrowed("2")),
  414. }),
  415. // MSC3933: Add condition on top of template rule - see MSC.
  416. Condition::Known(KnownCondition::RoomVersionSupports {
  417. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  418. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  419. }),
  420. ]),
  421. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  422. default: true,
  423. default_enabled: true,
  424. },
  425. PushRule {
  426. rule_id: Cow::Borrowed(
  427. "global/underride/.org.matrix.msc3933.rule.extensible.audio.room_one_to_one",
  428. ),
  429. priority_class: 1,
  430. conditions: Cow::Borrowed(&[
  431. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  432. key: Cow::Borrowed("type"),
  433. // MSC3933: Type changed from template rule - see MSC.
  434. pattern: Some(Cow::Borrowed("org.matrix.msc1767.audio")),
  435. pattern_type: None,
  436. })),
  437. Condition::Known(KnownCondition::RoomMemberCount {
  438. is: Some(Cow::Borrowed("2")),
  439. }),
  440. // MSC3933: Add condition on top of template rule - see MSC.
  441. Condition::Known(KnownCondition::RoomVersionSupports {
  442. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  443. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  444. }),
  445. ]),
  446. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  447. default: true,
  448. default_enabled: true,
  449. },
  450. PushRule {
  451. rule_id: Cow::Borrowed("global/underride/.m.rule.message"),
  452. priority_class: 1,
  453. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  454. EventMatchCondition {
  455. key: Cow::Borrowed("type"),
  456. pattern: Some(Cow::Borrowed("m.room.message")),
  457. pattern_type: None,
  458. },
  459. ))]),
  460. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  461. default: true,
  462. default_enabled: true,
  463. },
  464. PushRule {
  465. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted"),
  466. priority_class: 1,
  467. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  468. EventMatchCondition {
  469. key: Cow::Borrowed("type"),
  470. pattern: Some(Cow::Borrowed("m.room.encrypted")),
  471. pattern_type: None,
  472. },
  473. ))]),
  474. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  475. default: true,
  476. default_enabled: true,
  477. },
  478. PushRule {
  479. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.encrypted"),
  480. priority_class: 1,
  481. conditions: Cow::Borrowed(&[
  482. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  483. key: Cow::Borrowed("type"),
  484. // MSC3933: Type changed from template rule - see MSC.
  485. pattern: Some(Cow::Borrowed("m.encrypted")),
  486. pattern_type: None,
  487. })),
  488. // MSC3933: Add condition on top of template rule - see MSC.
  489. Condition::Known(KnownCondition::RoomVersionSupports {
  490. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  491. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  492. }),
  493. ]),
  494. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  495. default: true,
  496. default_enabled: true,
  497. },
  498. PushRule {
  499. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.message"),
  500. priority_class: 1,
  501. conditions: Cow::Borrowed(&[
  502. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  503. key: Cow::Borrowed("type"),
  504. // MSC3933: Type changed from template rule - see MSC.
  505. pattern: Some(Cow::Borrowed("m.message")),
  506. pattern_type: None,
  507. })),
  508. // MSC3933: Add condition on top of template rule - see MSC.
  509. Condition::Known(KnownCondition::RoomVersionSupports {
  510. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  511. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  512. }),
  513. ]),
  514. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  515. default: true,
  516. default_enabled: true,
  517. },
  518. PushRule {
  519. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.file"),
  520. priority_class: 1,
  521. conditions: Cow::Borrowed(&[
  522. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  523. key: Cow::Borrowed("type"),
  524. // MSC3933: Type changed from template rule - see MSC.
  525. pattern: Some(Cow::Borrowed("m.file")),
  526. pattern_type: None,
  527. })),
  528. // MSC3933: Add condition on top of template rule - see MSC.
  529. Condition::Known(KnownCondition::RoomVersionSupports {
  530. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  531. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  532. }),
  533. ]),
  534. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  535. default: true,
  536. default_enabled: true,
  537. },
  538. PushRule {
  539. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.image"),
  540. priority_class: 1,
  541. conditions: Cow::Borrowed(&[
  542. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  543. key: Cow::Borrowed("type"),
  544. // MSC3933: Type changed from template rule - see MSC.
  545. pattern: Some(Cow::Borrowed("m.image")),
  546. pattern_type: None,
  547. })),
  548. // MSC3933: Add condition on top of template rule - see MSC.
  549. Condition::Known(KnownCondition::RoomVersionSupports {
  550. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  551. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  552. }),
  553. ]),
  554. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  555. default: true,
  556. default_enabled: true,
  557. },
  558. PushRule {
  559. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.video"),
  560. priority_class: 1,
  561. conditions: Cow::Borrowed(&[
  562. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  563. key: Cow::Borrowed("type"),
  564. // MSC3933: Type changed from template rule - see MSC.
  565. pattern: Some(Cow::Borrowed("m.video")),
  566. pattern_type: None,
  567. })),
  568. // MSC3933: Add condition on top of template rule - see MSC.
  569. Condition::Known(KnownCondition::RoomVersionSupports {
  570. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  571. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  572. }),
  573. ]),
  574. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  575. default: true,
  576. default_enabled: true,
  577. },
  578. PushRule {
  579. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.audio"),
  580. priority_class: 1,
  581. conditions: Cow::Borrowed(&[
  582. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  583. key: Cow::Borrowed("type"),
  584. // MSC3933: Type changed from template rule - see MSC.
  585. pattern: Some(Cow::Borrowed("m.audio")),
  586. pattern_type: None,
  587. })),
  588. // MSC3933: Add condition on top of template rule - see MSC.
  589. Condition::Known(KnownCondition::RoomVersionSupports {
  590. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  591. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  592. }),
  593. ]),
  594. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  595. default: true,
  596. default_enabled: true,
  597. },
  598. PushRule {
  599. rule_id: Cow::Borrowed("global/underride/.im.vector.jitsi"),
  600. priority_class: 1,
  601. conditions: Cow::Borrowed(&[
  602. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  603. key: Cow::Borrowed("type"),
  604. pattern: Some(Cow::Borrowed("im.vector.modular.widgets")),
  605. pattern_type: None,
  606. })),
  607. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  608. key: Cow::Borrowed("content.type"),
  609. pattern: Some(Cow::Borrowed("jitsi")),
  610. pattern_type: None,
  611. })),
  612. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  613. key: Cow::Borrowed("state_key"),
  614. pattern: Some(Cow::Borrowed("*")),
  615. pattern_type: None,
  616. })),
  617. ]),
  618. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  619. default: true,
  620. default_enabled: true,
  621. },
  622. PushRule {
  623. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one"),
  624. priority_class: 1,
  625. conditions: Cow::Borrowed(&[
  626. Condition::Known(KnownCondition::RoomMemberCount {
  627. is: Some(Cow::Borrowed("2")),
  628. }),
  629. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  630. key: Cow::Borrowed("type"),
  631. pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.start")),
  632. pattern_type: None,
  633. })),
  634. ]),
  635. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]),
  636. default: true,
  637. default_enabled: true,
  638. },
  639. PushRule {
  640. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start"),
  641. priority_class: 1,
  642. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  643. EventMatchCondition {
  644. key: Cow::Borrowed("type"),
  645. pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.start")),
  646. pattern_type: None,
  647. },
  648. ))]),
  649. actions: Cow::Borrowed(&[Action::Notify]),
  650. default: true,
  651. default_enabled: true,
  652. },
  653. PushRule {
  654. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end_one_to_one"),
  655. priority_class: 1,
  656. conditions: Cow::Borrowed(&[
  657. Condition::Known(KnownCondition::RoomMemberCount {
  658. is: Some(Cow::Borrowed("2")),
  659. }),
  660. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  661. key: Cow::Borrowed("type"),
  662. pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.end")),
  663. pattern_type: None,
  664. })),
  665. ]),
  666. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]),
  667. default: true,
  668. default_enabled: true,
  669. },
  670. PushRule {
  671. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end"),
  672. priority_class: 1,
  673. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  674. EventMatchCondition {
  675. key: Cow::Borrowed("type"),
  676. pattern: Some(Cow::Borrowed("org.matrix.msc3381.poll.end")),
  677. pattern_type: None,
  678. },
  679. ))]),
  680. actions: Cow::Borrowed(&[Action::Notify]),
  681. default: true,
  682. default_enabled: true,
  683. },
  684. ];
  685. lazy_static! {
  686. pub static ref BASE_RULES_BY_ID: HashMap<&'static str, &'static PushRule> =
  687. BASE_PREPEND_OVERRIDE_RULES
  688. .iter()
  689. .chain(BASE_APPEND_OVERRIDE_RULES.iter())
  690. .chain(BASE_APPEND_CONTENT_RULES.iter())
  691. .chain(BASE_APPEND_UNDERRIDE_RULES.iter())
  692. .map(|rule| { (&*rule.rule_id, rule) })
  693. .collect();
  694. }