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.
 
 
 
 
 
 

706 lines
29 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::RelatedEventMatchTypeCondition;
  21. use crate::push::SetTweak;
  22. use crate::push::TweakValue;
  23. use crate::push::{Action, EventPropertyIsCondition, SimpleJsonValue};
  24. use crate::push::{Condition, EventMatchTypeCondition};
  25. use crate::push::{EventMatchCondition, EventMatchPatternType};
  26. use crate::push::{EventPropertyIsTypeCondition, PushRule};
  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(&[]),
  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/.org.matrix.msc4028.encrypted_event"),
  58. priority_class: 5,
  59. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  60. EventMatchCondition {
  61. key: Cow::Borrowed("type"),
  62. pattern: Cow::Borrowed("m.room.encrypted"),
  63. },
  64. ))]),
  65. actions: Cow::Borrowed(&[Action::Notify]),
  66. default: true,
  67. default_enabled: false,
  68. },
  69. PushRule {
  70. rule_id: Cow::Borrowed("global/override/.m.rule.suppress_notices"),
  71. priority_class: 5,
  72. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  73. EventMatchCondition {
  74. key: Cow::Borrowed("content.msgtype"),
  75. pattern: Cow::Borrowed("m.notice"),
  76. },
  77. ))]),
  78. actions: Cow::Borrowed(&[]),
  79. default: true,
  80. default_enabled: true,
  81. },
  82. PushRule {
  83. rule_id: Cow::Borrowed("global/override/.m.rule.invite_for_me"),
  84. priority_class: 5,
  85. conditions: Cow::Borrowed(&[
  86. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  87. key: Cow::Borrowed("type"),
  88. pattern: Cow::Borrowed("m.room.member"),
  89. })),
  90. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  91. key: Cow::Borrowed("content.membership"),
  92. pattern: Cow::Borrowed("invite"),
  93. })),
  94. Condition::Known(KnownCondition::EventMatchType(EventMatchTypeCondition {
  95. key: Cow::Borrowed("state_key"),
  96. pattern_type: Cow::Borrowed(&EventMatchPatternType::UserId),
  97. })),
  98. ]),
  99. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION, SOUND_ACTION]),
  100. default: true,
  101. default_enabled: true,
  102. },
  103. PushRule {
  104. rule_id: Cow::Borrowed("global/override/.m.rule.member_event"),
  105. priority_class: 5,
  106. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  107. EventMatchCondition {
  108. key: Cow::Borrowed("type"),
  109. pattern: Cow::Borrowed("m.room.member"),
  110. },
  111. ))]),
  112. actions: Cow::Borrowed(&[]),
  113. default: true,
  114. default_enabled: true,
  115. },
  116. PushRule {
  117. rule_id: Cow::Borrowed("global/override/.im.nheko.msc3664.reply"),
  118. priority_class: 5,
  119. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::RelatedEventMatchType(
  120. RelatedEventMatchTypeCondition {
  121. key: Cow::Borrowed("sender"),
  122. pattern_type: Cow::Borrowed(&EventMatchPatternType::UserId),
  123. rel_type: Cow::Borrowed("m.in_reply_to"),
  124. include_fallbacks: None,
  125. },
  126. ))]),
  127. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  128. default: true,
  129. default_enabled: true,
  130. },
  131. PushRule {
  132. rule_id: Cow::Borrowed("global/override/.m.rule.is_user_mention"),
  133. priority_class: 5,
  134. conditions: Cow::Borrowed(&[Condition::Known(
  135. KnownCondition::ExactEventPropertyContainsType(EventPropertyIsTypeCondition {
  136. key: Cow::Borrowed(r"content.m\.mentions.user_ids"),
  137. value_type: Cow::Borrowed(&EventMatchPatternType::UserId),
  138. }),
  139. )]),
  140. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  141. default: true,
  142. default_enabled: true,
  143. },
  144. PushRule {
  145. rule_id: Cow::Borrowed("global/override/.m.rule.contains_display_name"),
  146. priority_class: 5,
  147. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::ContainsDisplayName)]),
  148. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  149. default: true,
  150. default_enabled: true,
  151. },
  152. PushRule {
  153. rule_id: Cow::Borrowed("global/override/.m.rule.is_room_mention"),
  154. priority_class: 5,
  155. conditions: Cow::Borrowed(&[
  156. Condition::Known(KnownCondition::EventPropertyIs(EventPropertyIsCondition {
  157. key: Cow::Borrowed(r"content.m\.mentions.room"),
  158. value: Cow::Owned(SimpleJsonValue::Bool(true)),
  159. })),
  160. Condition::Known(KnownCondition::SenderNotificationPermission {
  161. key: Cow::Borrowed("room"),
  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.roomnotif"),
  170. priority_class: 5,
  171. conditions: Cow::Borrowed(&[
  172. Condition::Known(KnownCondition::SenderNotificationPermission {
  173. key: Cow::Borrowed("room"),
  174. }),
  175. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  176. key: Cow::Borrowed("content.body"),
  177. pattern: Cow::Borrowed("@room"),
  178. })),
  179. ]),
  180. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  181. default: true,
  182. default_enabled: true,
  183. },
  184. PushRule {
  185. rule_id: Cow::Borrowed("global/override/.m.rule.tombstone"),
  186. priority_class: 5,
  187. conditions: Cow::Borrowed(&[
  188. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  189. key: Cow::Borrowed("type"),
  190. pattern: Cow::Borrowed("m.room.tombstone"),
  191. })),
  192. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  193. key: Cow::Borrowed("state_key"),
  194. pattern: Cow::Borrowed(""),
  195. })),
  196. ]),
  197. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION]),
  198. default: true,
  199. default_enabled: true,
  200. },
  201. PushRule {
  202. rule_id: Cow::Borrowed("global/override/.m.rule.reaction"),
  203. priority_class: 5,
  204. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  205. EventMatchCondition {
  206. key: Cow::Borrowed("type"),
  207. pattern: Cow::Borrowed("m.reaction"),
  208. },
  209. ))]),
  210. actions: Cow::Borrowed(&[]),
  211. default: true,
  212. default_enabled: true,
  213. },
  214. PushRule {
  215. rule_id: Cow::Borrowed("global/override/.m.rule.room.server_acl"),
  216. priority_class: 5,
  217. conditions: Cow::Borrowed(&[
  218. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  219. key: Cow::Borrowed("type"),
  220. pattern: Cow::Borrowed("m.room.server_acl"),
  221. })),
  222. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  223. key: Cow::Borrowed("state_key"),
  224. pattern: Cow::Borrowed(""),
  225. })),
  226. ]),
  227. actions: Cow::Borrowed(&[]),
  228. default: true,
  229. default_enabled: true,
  230. },
  231. // We don't want to notify on edits *unless* the edit directly mentions a
  232. // user, which is handled above.
  233. PushRule {
  234. rule_id: Cow::Borrowed("global/override/.m.rule.suppress_edits"),
  235. priority_class: 5,
  236. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventPropertyIs(
  237. EventPropertyIsCondition {
  238. key: Cow::Borrowed(r"content.m\.relates_to.rel_type"),
  239. value: Cow::Owned(SimpleJsonValue::Str(Cow::Borrowed("m.replace"))),
  240. },
  241. ))]),
  242. actions: Cow::Borrowed(&[]),
  243. default: true,
  244. default_enabled: true,
  245. },
  246. PushRule {
  247. rule_id: Cow::Borrowed("global/override/.org.matrix.msc3930.rule.poll_response"),
  248. priority_class: 5,
  249. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  250. EventMatchCondition {
  251. key: Cow::Borrowed("type"),
  252. pattern: Cow::Borrowed("org.matrix.msc3381.poll.response"),
  253. },
  254. ))]),
  255. actions: Cow::Borrowed(&[]),
  256. default: true,
  257. default_enabled: true,
  258. },
  259. ];
  260. pub const BASE_APPEND_CONTENT_RULES: &[PushRule] = &[PushRule {
  261. rule_id: Cow::Borrowed("global/content/.m.rule.contains_user_name"),
  262. priority_class: 4,
  263. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatchType(
  264. EventMatchTypeCondition {
  265. key: Cow::Borrowed("content.body"),
  266. pattern_type: Cow::Borrowed(&EventMatchPatternType::UserLocalpart),
  267. },
  268. ))]),
  269. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_ACTION, SOUND_ACTION]),
  270. default: true,
  271. default_enabled: true,
  272. }];
  273. pub const BASE_APPEND_UNDERRIDE_RULES: &[PushRule] = &[
  274. PushRule {
  275. rule_id: Cow::Borrowed("global/underride/.m.rule.call"),
  276. priority_class: 1,
  277. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  278. EventMatchCondition {
  279. key: Cow::Borrowed("type"),
  280. pattern: Cow::Borrowed("m.call.invite"),
  281. },
  282. ))]),
  283. actions: Cow::Borrowed(&[Action::Notify, RING_ACTION, HIGHLIGHT_FALSE_ACTION]),
  284. default: true,
  285. default_enabled: true,
  286. },
  287. PushRule {
  288. rule_id: Cow::Borrowed("global/underride/.m.rule.room_one_to_one"),
  289. priority_class: 1,
  290. conditions: Cow::Borrowed(&[
  291. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  292. key: Cow::Borrowed("type"),
  293. pattern: Cow::Borrowed("m.room.message"),
  294. })),
  295. Condition::Known(KnownCondition::RoomMemberCount {
  296. is: Some(Cow::Borrowed("2")),
  297. }),
  298. ]),
  299. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  300. default: true,
  301. default_enabled: true,
  302. },
  303. PushRule {
  304. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted_room_one_to_one"),
  305. priority_class: 1,
  306. conditions: Cow::Borrowed(&[
  307. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  308. key: Cow::Borrowed("type"),
  309. pattern: Cow::Borrowed("m.room.encrypted"),
  310. })),
  311. Condition::Known(KnownCondition::RoomMemberCount {
  312. is: Some(Cow::Borrowed("2")),
  313. }),
  314. ]),
  315. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  316. default: true,
  317. default_enabled: true,
  318. },
  319. PushRule {
  320. rule_id: Cow::Borrowed(
  321. "global/underride/.org.matrix.msc3933.rule.extensible.encrypted_room_one_to_one",
  322. ),
  323. priority_class: 1,
  324. conditions: Cow::Borrowed(&[
  325. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  326. key: Cow::Borrowed("type"),
  327. // MSC3933: Type changed from template rule - see MSC.
  328. pattern: Cow::Borrowed("org.matrix.msc1767.encrypted"),
  329. })),
  330. Condition::Known(KnownCondition::RoomMemberCount {
  331. is: Some(Cow::Borrowed("2")),
  332. }),
  333. // MSC3933: Add condition on top of template rule - see MSC.
  334. Condition::Known(KnownCondition::RoomVersionSupports {
  335. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  336. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  337. }),
  338. ]),
  339. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  340. default: true,
  341. default_enabled: true,
  342. },
  343. PushRule {
  344. rule_id: Cow::Borrowed(
  345. "global/underride/.org.matrix.msc3933.rule.extensible.message.room_one_to_one",
  346. ),
  347. priority_class: 1,
  348. conditions: Cow::Borrowed(&[
  349. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  350. key: Cow::Borrowed("type"),
  351. // MSC3933: Type changed from template rule - see MSC.
  352. pattern: Cow::Borrowed("org.matrix.msc1767.message"),
  353. })),
  354. Condition::Known(KnownCondition::RoomMemberCount {
  355. is: Some(Cow::Borrowed("2")),
  356. }),
  357. // MSC3933: Add condition on top of template rule - see MSC.
  358. Condition::Known(KnownCondition::RoomVersionSupports {
  359. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  360. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  361. }),
  362. ]),
  363. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  364. default: true,
  365. default_enabled: true,
  366. },
  367. PushRule {
  368. rule_id: Cow::Borrowed(
  369. "global/underride/.org.matrix.msc3933.rule.extensible.file.room_one_to_one",
  370. ),
  371. priority_class: 1,
  372. conditions: Cow::Borrowed(&[
  373. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  374. key: Cow::Borrowed("type"),
  375. // MSC3933: Type changed from template rule - see MSC.
  376. pattern: Cow::Borrowed("org.matrix.msc1767.file"),
  377. })),
  378. Condition::Known(KnownCondition::RoomMemberCount {
  379. is: Some(Cow::Borrowed("2")),
  380. }),
  381. // MSC3933: Add condition on top of template rule - see MSC.
  382. Condition::Known(KnownCondition::RoomVersionSupports {
  383. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  384. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  385. }),
  386. ]),
  387. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  388. default: true,
  389. default_enabled: true,
  390. },
  391. PushRule {
  392. rule_id: Cow::Borrowed(
  393. "global/underride/.org.matrix.msc3933.rule.extensible.image.room_one_to_one",
  394. ),
  395. priority_class: 1,
  396. conditions: Cow::Borrowed(&[
  397. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  398. key: Cow::Borrowed("type"),
  399. // MSC3933: Type changed from template rule - see MSC.
  400. pattern: Cow::Borrowed("org.matrix.msc1767.image"),
  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(
  417. "global/underride/.org.matrix.msc3933.rule.extensible.video.room_one_to_one",
  418. ),
  419. priority_class: 1,
  420. conditions: Cow::Borrowed(&[
  421. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  422. key: Cow::Borrowed("type"),
  423. // MSC3933: Type changed from template rule - see MSC.
  424. pattern: Cow::Borrowed("org.matrix.msc1767.video"),
  425. })),
  426. Condition::Known(KnownCondition::RoomMemberCount {
  427. is: Some(Cow::Borrowed("2")),
  428. }),
  429. // MSC3933: Add condition on top of template rule - see MSC.
  430. Condition::Known(KnownCondition::RoomVersionSupports {
  431. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  432. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  433. }),
  434. ]),
  435. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  436. default: true,
  437. default_enabled: true,
  438. },
  439. PushRule {
  440. rule_id: Cow::Borrowed(
  441. "global/underride/.org.matrix.msc3933.rule.extensible.audio.room_one_to_one",
  442. ),
  443. priority_class: 1,
  444. conditions: Cow::Borrowed(&[
  445. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  446. key: Cow::Borrowed("type"),
  447. // MSC3933: Type changed from template rule - see MSC.
  448. pattern: Cow::Borrowed("org.matrix.msc1767.audio"),
  449. })),
  450. Condition::Known(KnownCondition::RoomMemberCount {
  451. is: Some(Cow::Borrowed("2")),
  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, SOUND_ACTION, HIGHLIGHT_FALSE_ACTION]),
  460. default: true,
  461. default_enabled: true,
  462. },
  463. PushRule {
  464. rule_id: Cow::Borrowed("global/underride/.m.rule.message"),
  465. priority_class: 1,
  466. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  467. EventMatchCondition {
  468. key: Cow::Borrowed("type"),
  469. pattern: Cow::Borrowed("m.room.message"),
  470. },
  471. ))]),
  472. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  473. default: true,
  474. default_enabled: true,
  475. },
  476. PushRule {
  477. rule_id: Cow::Borrowed("global/underride/.m.rule.encrypted"),
  478. priority_class: 1,
  479. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  480. EventMatchCondition {
  481. key: Cow::Borrowed("type"),
  482. pattern: Cow::Borrowed("m.room.encrypted"),
  483. },
  484. ))]),
  485. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  486. default: true,
  487. default_enabled: true,
  488. },
  489. PushRule {
  490. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.encrypted"),
  491. priority_class: 1,
  492. conditions: Cow::Borrowed(&[
  493. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  494. key: Cow::Borrowed("type"),
  495. // MSC3933: Type changed from template rule - see MSC.
  496. pattern: Cow::Borrowed("m.encrypted"),
  497. })),
  498. // MSC3933: Add condition on top of template rule - see MSC.
  499. Condition::Known(KnownCondition::RoomVersionSupports {
  500. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  501. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  502. }),
  503. ]),
  504. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  505. default: true,
  506. default_enabled: true,
  507. },
  508. PushRule {
  509. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.message"),
  510. priority_class: 1,
  511. conditions: Cow::Borrowed(&[
  512. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  513. key: Cow::Borrowed("type"),
  514. // MSC3933: Type changed from template rule - see MSC.
  515. pattern: Cow::Borrowed("m.message"),
  516. })),
  517. // MSC3933: Add condition on top of template rule - see MSC.
  518. Condition::Known(KnownCondition::RoomVersionSupports {
  519. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  520. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  521. }),
  522. ]),
  523. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  524. default: true,
  525. default_enabled: true,
  526. },
  527. PushRule {
  528. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.file"),
  529. priority_class: 1,
  530. conditions: Cow::Borrowed(&[
  531. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  532. key: Cow::Borrowed("type"),
  533. // MSC3933: Type changed from template rule - see MSC.
  534. pattern: Cow::Borrowed("m.file"),
  535. })),
  536. // MSC3933: Add condition on top of template rule - see MSC.
  537. Condition::Known(KnownCondition::RoomVersionSupports {
  538. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  539. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  540. }),
  541. ]),
  542. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  543. default: true,
  544. default_enabled: true,
  545. },
  546. PushRule {
  547. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.image"),
  548. priority_class: 1,
  549. conditions: Cow::Borrowed(&[
  550. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  551. key: Cow::Borrowed("type"),
  552. // MSC3933: Type changed from template rule - see MSC.
  553. pattern: Cow::Borrowed("m.image"),
  554. })),
  555. // MSC3933: Add condition on top of template rule - see MSC.
  556. Condition::Known(KnownCondition::RoomVersionSupports {
  557. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  558. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  559. }),
  560. ]),
  561. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  562. default: true,
  563. default_enabled: true,
  564. },
  565. PushRule {
  566. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.video"),
  567. priority_class: 1,
  568. conditions: Cow::Borrowed(&[
  569. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  570. key: Cow::Borrowed("type"),
  571. // MSC3933: Type changed from template rule - see MSC.
  572. pattern: Cow::Borrowed("m.video"),
  573. })),
  574. // MSC3933: Add condition on top of template rule - see MSC.
  575. Condition::Known(KnownCondition::RoomVersionSupports {
  576. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  577. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  578. }),
  579. ]),
  580. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  581. default: true,
  582. default_enabled: true,
  583. },
  584. PushRule {
  585. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc1767.rule.extensible.audio"),
  586. priority_class: 1,
  587. conditions: Cow::Borrowed(&[
  588. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  589. key: Cow::Borrowed("type"),
  590. // MSC3933: Type changed from template rule - see MSC.
  591. pattern: Cow::Borrowed("m.audio"),
  592. })),
  593. // MSC3933: Add condition on top of template rule - see MSC.
  594. Condition::Known(KnownCondition::RoomVersionSupports {
  595. // RoomVersionFeatures::ExtensibleEvents.as_str(), ideally
  596. feature: Cow::Borrowed("org.matrix.msc3932.extensible_events"),
  597. }),
  598. ]),
  599. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  600. default: true,
  601. default_enabled: true,
  602. },
  603. PushRule {
  604. rule_id: Cow::Borrowed("global/underride/.im.vector.jitsi"),
  605. priority_class: 1,
  606. conditions: Cow::Borrowed(&[
  607. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  608. key: Cow::Borrowed("type"),
  609. pattern: Cow::Borrowed("im.vector.modular.widgets"),
  610. })),
  611. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  612. key: Cow::Borrowed("content.type"),
  613. pattern: Cow::Borrowed("jitsi"),
  614. })),
  615. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  616. key: Cow::Borrowed("state_key"),
  617. pattern: Cow::Borrowed("*"),
  618. })),
  619. ]),
  620. actions: Cow::Borrowed(&[Action::Notify, HIGHLIGHT_FALSE_ACTION]),
  621. default: true,
  622. default_enabled: true,
  623. },
  624. PushRule {
  625. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start_one_to_one"),
  626. priority_class: 1,
  627. conditions: Cow::Borrowed(&[
  628. Condition::Known(KnownCondition::RoomMemberCount {
  629. is: Some(Cow::Borrowed("2")),
  630. }),
  631. Condition::Known(KnownCondition::EventMatch(EventMatchCondition {
  632. key: Cow::Borrowed("type"),
  633. pattern: Cow::Borrowed("org.matrix.msc3381.poll.start"),
  634. })),
  635. ]),
  636. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]),
  637. default: true,
  638. default_enabled: true,
  639. },
  640. PushRule {
  641. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_start"),
  642. priority_class: 1,
  643. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  644. EventMatchCondition {
  645. key: Cow::Borrowed("type"),
  646. pattern: Cow::Borrowed("org.matrix.msc3381.poll.start"),
  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: Cow::Borrowed("org.matrix.msc3381.poll.end"),
  663. })),
  664. ]),
  665. actions: Cow::Borrowed(&[Action::Notify, SOUND_ACTION]),
  666. default: true,
  667. default_enabled: true,
  668. },
  669. PushRule {
  670. rule_id: Cow::Borrowed("global/underride/.org.matrix.msc3930.rule.poll_end"),
  671. priority_class: 1,
  672. conditions: Cow::Borrowed(&[Condition::Known(KnownCondition::EventMatch(
  673. EventMatchCondition {
  674. key: Cow::Borrowed("type"),
  675. pattern: Cow::Borrowed("org.matrix.msc3381.poll.end"),
  676. },
  677. ))]),
  678. actions: Cow::Borrowed(&[Action::Notify]),
  679. default: true,
  680. default_enabled: true,
  681. },
  682. ];
  683. lazy_static! {
  684. pub static ref BASE_RULES_BY_ID: HashMap<&'static str, &'static PushRule> =
  685. BASE_PREPEND_OVERRIDE_RULES
  686. .iter()
  687. .chain(BASE_APPEND_OVERRIDE_RULES.iter())
  688. .chain(BASE_APPEND_CONTENT_RULES.iter())
  689. .chain(BASE_APPEND_UNDERRIDE_RULES.iter())
  690. .map(|rule| { (&*rule.rule_id, rule) })
  691. .collect();
  692. }