Upgrade Ruma after removal of legacy mention push rules
The legacy mention push rules were removed, and the `contains_display_name` condition was deprecated. Some tests check for backwards-compatibility with legacy mentions, so we need to add them back for those tests. A test with an encrypted event was relying on the legacy mentions, so the encrypted event was replaced with another one with an intentional mention. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Andy Balaam
parent
a72c19a240
commit
cb3d281f8f
Generated
+9
-9
@@ -4820,7 +4820,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma"
|
||||
version = "0.13.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"assign",
|
||||
"js_int",
|
||||
@@ -4837,7 +4837,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-client-api"
|
||||
version = "0.21.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"assign",
|
||||
@@ -4860,7 +4860,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-common"
|
||||
version = "0.16.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"base64",
|
||||
@@ -4893,7 +4893,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-events"
|
||||
version = "0.31.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"indexmap",
|
||||
@@ -4919,7 +4919,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-federation-api"
|
||||
version = "0.12.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"headers",
|
||||
"http",
|
||||
@@ -4939,7 +4939,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-html"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"as_variant",
|
||||
"html5ever",
|
||||
@@ -4950,7 +4950,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-identifiers-validation"
|
||||
version = "0.11.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"js_int",
|
||||
"thiserror 2.0.16",
|
||||
@@ -4959,7 +4959,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-macros"
|
||||
version = "0.16.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"proc-macro-crate",
|
||||
@@ -4974,7 +4974,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ruma-signatures"
|
||||
version = "0.18.0"
|
||||
source = "git+https://github.com/ruma/ruma?rev=cb6a83c6142de810e225cde9b3097c44f2f8d75a#cb6a83c6142de810e225cde9b3097c44f2f8d75a"
|
||||
source = "git+https://github.com/ruma/ruma?rev=c441eccb92a36467217ff929cd71462fbeeeaf1a#c441eccb92a36467217ff929cd71462fbeeeaf1a"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"ed25519-dalek",
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ rand = "0.8.5"
|
||||
regex = "1.11.2"
|
||||
reqwest = { version = "0.12.23", default-features = false }
|
||||
rmp-serde = "1.3.0"
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "cb6a83c6142de810e225cde9b3097c44f2f8d75a", features = [
|
||||
ruma = { git = "https://github.com/ruma/ruma", rev = "c441eccb92a36467217ff929cd71462fbeeeaf1a", features = [
|
||||
"client-api-c",
|
||||
"compat-upload-signatures",
|
||||
"compat-arbitrary-length-ids",
|
||||
|
||||
@@ -168,6 +168,7 @@ impl TryFrom<SdkPushCondition> for PushCondition {
|
||||
fn try_from(value: SdkPushCondition) -> Result<Self, Self::Error> {
|
||||
Ok(match value {
|
||||
SdkPushCondition::EventMatch { key, pattern } => Self::EventMatch { key, pattern },
|
||||
#[allow(deprecated)]
|
||||
SdkPushCondition::ContainsDisplayName => Self::ContainsDisplayName,
|
||||
SdkPushCondition::RoomMemberCount { is } => {
|
||||
Self::RoomMemberCount { prefix: is.prefix.into(), count: is.count.into() }
|
||||
@@ -190,6 +191,7 @@ impl From<PushCondition> for SdkPushCondition {
|
||||
fn from(value: PushCondition) -> Self {
|
||||
match value {
|
||||
PushCondition::EventMatch { key, pattern } => Self::EventMatch { key, pattern },
|
||||
#[allow(deprecated)]
|
||||
PushCondition::ContainsDisplayName => Self::ContainsDisplayName,
|
||||
PushCondition::RoomMemberCount { prefix, count } => Self::RoomMemberCount {
|
||||
is: RoomMemberCountIs {
|
||||
|
||||
@@ -41,7 +41,7 @@ use ruma::{
|
||||
EncryptedEventScheme, MegolmV1AesSha2ContentInit, Relation, Replacement,
|
||||
RoomEncryptedEventContent,
|
||||
},
|
||||
owned_device_id, room_id,
|
||||
owned_device_id, owned_user_id, room_id,
|
||||
serde::Raw,
|
||||
user_id,
|
||||
};
|
||||
@@ -530,29 +530,28 @@ async fn test_retry_edit_and_more() {
|
||||
|
||||
#[async_test]
|
||||
async fn test_retry_message_decryption_highlighted() {
|
||||
const SESSION_ID: &str = "C25PoE+4MlNidQD0YU5ibZqHawV0zZ/up7R8vYJBYTY";
|
||||
const SESSION_ID: &str = "iLmOdBBComUwueq8mKVU1Om5xXzfP3As0T5W6JnmzcU";
|
||||
const SESSION_KEY: &[u8] = b"\
|
||||
-----BEGIN MEGOLM SESSION DATA-----\n\
|
||||
AUBvCG7VHqpYOpNJoIVxsTS1Qyu83w6xFDw67qDe1edSAAAACrnzwQzFMw//BB9iNKTviUfGPEKD9XlL9f8N\
|
||||
svGCe971WnKLqWJjtrc42UfyDXH0fz4HXeCN1b104GlzWVFp0r+9RuQpPsP3IZ1DxWPm/xsotr3N4BY3pdgK\
|
||||
wpbCq3oD9bQ0jcYqajrWfmEagSInobo9jd6CPyj6kz7mU/SXwva+aoYB8fVJptdYbIXQbvD8t9vS5SC6ZGlP\
|
||||
CpcJBscXIq79HpWgDjnfvUNZiITlazFcgPB8zI78MwISm4FX/4KAwxjWf0eGNwKPiTP8fjXpxKurgnMQEET/\
|
||||
nVb/r4yIO1Z8rM6vmzoTcQvUc5pXmAGhcLGWN6Q06D3hBuWw0etCKRW5bqcMRit5wmawvBV6j+QNKSPKy7xQ\
|
||||
zQhzx9TFfgGZ7rRsl9EPxn0FB/EJNHOkbqYqOmKix9jbh820jRG9i4vD+x+U6iXGpRPyb2S8w+1f9n3uH3yI\
|
||||
0XWypoX/eEh7cJv9YChq4Wst4UkP2l6ztP8H/dWXfDYHddkMMKnveeb3sjWRjJep7Ih3W5PyMmxfge85DryB\
|
||||
Sgvx6TKvtiC4zOKp1VStbXNgrpipWixhXP2F8BkDmJJvDYO1idWU2NbDJZY6AkKockUscnovpmV1yhovm83Y\
|
||||
sAZRyV3W2MlFpA5qAgdXWlBA4WZ/jus/Mey0dqFZtvDS6fC1S4cx5p6hXBwADLRjIiqq2dpn49+aUwqPMn/b\
|
||||
FM8H2PpVkKgrA+tx8LNQD+FWDfp6MyhmEJEvk9r5vU9LtTXtZl4toYvNY0UHUBbZj2xF9U9Z9A\n\
|
||||
AX24HyDDbSft4ogbfNZNOIfDW77PkIX/pFxHBgMMkU8FAAAAClcahP9R2+HkWpo8ME4+C7BKJlZAhqEZsvfjoqdQVo8\
|
||||
1vMJkdINNuG9jdl4DWd3GxpgiJLTmNqfZewG4Fca1RG6X67KNv7XFwreIn38+wjtqaPa6ODnx2C9ia0nyjKw88x1I4m\
|
||||
MYeRj8NgMvPmBFk5gQXlUeWw9b0LGUzUwn7JtRjvpygmbTJTerLXvAbBJo2CiFVjTlbG+4w2N++PoqtaWHNBmqqEJNF\
|
||||
c2EKnyqkOmHvNkMLAWAkEkbmqSOTjwBYq28PHqY3UTgGafRGkdX+mp0PsexVLEgzNL0SQFNAVaTlnr0WBxnWMGyS88/\
|
||||
n9BeI31YTUjb837ZDDKVgXvu0vybchM5MNActoyxzcOYQ/bqK9Cd7l6O3MvJ8iqgbbMkkKJDO1OY3RByaNmDHXRRQhL\
|
||||
vLIiPqjLqw6NLZYMTb9Qi5cGKnhehEWafKepSDTB29J6szAlzaWdX3m5abgOhi629IPmshKX5AXrfpGP6O6h3BeOpSb\
|
||||
UzcXmEuJJbyi4TbtbTmL4E9kJGWsvs7pobmmp6ndkR2xjHwWdZh9JDzjJvCF4Se61wkmq2tUUQaANch/ORWLxx/Sf3E\
|
||||
NFEAmaDU3PAWsce2AR1LweCTCtgqg2veJ/irKn816SZd8p9E4ujwBPtiwHYXVBaKmja2/BnFEKbU3vzBU8R5RIr4VEd\
|
||||
C1r72yL/zIx+P220q3gPvLEqglUsES5Hwo5+7y/CKLa5ZvLPby+DUyVJxn9lLdvCvoxcBWzKGMrwEmwnClWPxrUFqaP\
|
||||
R36ruSneNIpFsVqemSCVF2irnHWgtYHvH8EUOAbsK8KLMHiCg8HxlkLd5GL1lpBwwR+c\n\
|
||||
-----END MEGOLM SESSION DATA-----";
|
||||
|
||||
let own_user_id = user_id!("@example:matrix.org");
|
||||
let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await;
|
||||
let own_user_id = owned_user_id!("@willow:matrix.local");
|
||||
let olm_machine = OlmMachine::new(&own_user_id, "SomeDeviceId".into()).await;
|
||||
|
||||
let timeline = TestTimelineBuilder::new()
|
||||
.provider(TestRoomDataProvider::default().with_decryptor(TestDecryptor::new(
|
||||
room_id!("!rYtFvMGENJleNQVJzb:matrix.org"),
|
||||
&olm_machine,
|
||||
)))
|
||||
.provider(TestRoomDataProvider::default().with_own_user_id(own_user_id).with_decryptor(
|
||||
TestDecryptor::new(room_id!("!TWUdbkXUixrqPXtWbN:matrix.local"), &olm_machine),
|
||||
))
|
||||
.build();
|
||||
|
||||
let f = &timeline.factory;
|
||||
@@ -564,14 +563,18 @@ async fn test_retry_message_decryption_highlighted() {
|
||||
EncryptedEventScheme::MegolmV1AesSha2(
|
||||
MegolmV1AesSha2ContentInit {
|
||||
ciphertext: "\
|
||||
AwgAEpABNOd7Rxpc/98gaaOanApQ/h40uNyYE/aiFd8PKeQPH65bwuxBy/glodmteryH\
|
||||
4t5d0cKSPjb+996yK90+A8YUevQKBuC+/+4iRF2CSqMNvArdOCnFHJdZBuCyRP6W82DZ\
|
||||
sR1w5X/tKGs/A9egJdxomLCzMRZarayTXUlgMT8Kj7E9zKOgyLEZGki6Y9IPybfrU3+S\
|
||||
b4VbF7RKY395/lIZFiLvJ5hUT+Ao1k13opeTE9GHtdOK0GzQPVFLnN61pRa3K/vV9Otk\
|
||||
D0QbVS/4mE3C29+yIC1lEkwA"
|
||||
AwgBEuAC3YC8wNxHOlnuXuyoBwRhtbwE+sVm1CMRZylzapX4uHEB/xP8QFoH6yN5KzGi34h\
|
||||
6QEb2b3Y+dwNHzHhuSHhtqGNOncJKT3KoPamXzlapmqpF3EjbfN07M9ZMuRNGC6EMF7cCRN\
|
||||
yy7h4S9erzXs73uRZV9t0dMpk5FJ9/vHFBfEic4p26eQjltnk7CCJ0sMukAsLzkZOPFOdoP\
|
||||
KLOAsvmPskcYCmtvNfMLIHG+e3YMDj/UzQ9mZl69cD8/r9dOdMiYzdhhullqIFgrXZq+e6J\
|
||||
SMiTNLdEk7uu8OgAf/GhVmC2h9vaN3MIPfGcu8Z7Yf9RQ8mfGrxFxESLc+NhRaEuCjX5Tc7\
|
||||
AzPamR41+JV5xHh7FsOFp7a1eLs9MTRHsq1Vfzv02ecQeiUdRtyIVH+IwKAkc336CLnItvy\
|
||||
CQhXEqcFWKqWLg9+LpTeg0IrUhVhRpQiztqN44vH8xfWpCHDOwbFhJ6DV9NTWQUzDkJjZVI\
|
||||
W6pEbevP8tyDbQtSDSfpdSHoEPor7WVV9rp9FFqznXZxH9G39dWxI7h40vKdNTiqKkfQNZc\
|
||||
dwAyDw"
|
||||
.to_owned(),
|
||||
sender_key: "peI8cfSKqZvTOAfY0Od2e7doDpJ1cxdBsOhSceTLU3E".to_owned(),
|
||||
device_id: "KDCTEHOVSS".into(),
|
||||
sender_key: "RfaXABigv2vPj0TciwpZTBU0uwWg7iSHvRHA2V2NFiM".to_owned(),
|
||||
device_id: "KFWPUYHXZA".into(),
|
||||
session_id: SESSION_ID.into(),
|
||||
}
|
||||
.into(),
|
||||
@@ -617,7 +620,7 @@ async fn test_retry_message_decryption_highlighted() {
|
||||
let event = item.as_event().unwrap();
|
||||
assert_matches!(event.encryption_info(), Some(_));
|
||||
assert_let!(Some(message) = event.content().as_message());
|
||||
assert_eq!(message.body(), "A secret to everybody but Alice");
|
||||
assert_eq!(message.body(), "A secret to everybody but Willow");
|
||||
assert!(event.is_highlighted());
|
||||
}
|
||||
|
||||
|
||||
@@ -217,24 +217,24 @@ impl RuleCommands {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use assert_matches::assert_matches;
|
||||
use matrix_sdk_test::async_test;
|
||||
use matrix_sdk_test::{
|
||||
async_test,
|
||||
notification_settings::{
|
||||
get_server_default_ruleset, server_default_ruleset_with_legacy_mentions,
|
||||
},
|
||||
};
|
||||
use ruma::{
|
||||
OwnedRoomId, RoomId, UserId,
|
||||
OwnedRoomId, RoomId,
|
||||
push::{
|
||||
Action, NewPushRule, NewSimplePushRule, PredefinedContentRuleId,
|
||||
PredefinedOverrideRuleId, PredefinedUnderrideRuleId, RemovePushRuleError, RuleKind,
|
||||
Ruleset, Tweak,
|
||||
Tweak,
|
||||
},
|
||||
};
|
||||
|
||||
use super::RuleCommands;
|
||||
use crate::{error::NotificationSettingsError, notification_settings::command::Command};
|
||||
|
||||
fn get_server_default_ruleset() -> Ruleset {
|
||||
let user_id = UserId::parse("@user:matrix.org").unwrap();
|
||||
Ruleset::server_default(&user_id)
|
||||
}
|
||||
|
||||
fn get_test_room_id() -> OwnedRoomId {
|
||||
RoomId::parse("!AAAaAAAAAaaAAaaaaa:matrix.org").unwrap()
|
||||
}
|
||||
@@ -390,7 +390,7 @@ mod tests {
|
||||
|
||||
#[async_test]
|
||||
async fn test_set_rule_enabled_user_mention() {
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
let mut rule_commands = RuleCommands::new(ruleset.clone());
|
||||
|
||||
ruleset
|
||||
@@ -479,7 +479,7 @@ mod tests {
|
||||
|
||||
#[async_test]
|
||||
async fn test_set_rule_enabled_room_mention() {
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
let mut rule_commands = RuleCommands::new(ruleset.clone());
|
||||
|
||||
ruleset
|
||||
|
||||
@@ -316,7 +316,9 @@ pub(crate) mod tests {
|
||||
use imbl::HashSet;
|
||||
use matrix_sdk_test::{
|
||||
async_test,
|
||||
notification_settings::{build_ruleset, get_server_default_ruleset},
|
||||
notification_settings::{
|
||||
build_ruleset, get_server_default_ruleset, server_default_ruleset_with_legacy_mentions,
|
||||
},
|
||||
};
|
||||
use ruma::{
|
||||
OwnedRoomId, RoomId,
|
||||
@@ -488,7 +490,7 @@ pub(crate) mod tests {
|
||||
async fn test_is_user_mention_enabled() {
|
||||
// If `IsUserMention` is enable, then is_user_mention_enabled() should return
|
||||
// `true` even if the deprecated rules are disabled
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
ruleset
|
||||
.set_enabled(RuleKind::Override, PredefinedOverrideRuleId::IsUserMention, true)
|
||||
.unwrap();
|
||||
@@ -513,7 +515,7 @@ pub(crate) mod tests {
|
||||
|
||||
// If `IsUserMention` is disabled, then is_user_mention_enabled() should return
|
||||
// `false` even if the deprecated rules are enabled
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
ruleset
|
||||
.set_enabled(RuleKind::Override, PredefinedOverrideRuleId::IsUserMention, false)
|
||||
.unwrap();
|
||||
@@ -549,7 +551,7 @@ pub(crate) mod tests {
|
||||
async fn test_is_room_mention_enabled() {
|
||||
// If `IsRoomMention` is present and enabled then is_room_mention_enabled()
|
||||
// should return `true` even if the deprecated rule is disabled
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
ruleset
|
||||
.set_enabled(RuleKind::Override, PredefinedOverrideRuleId::IsRoomMention, true)
|
||||
.unwrap();
|
||||
@@ -570,7 +572,7 @@ pub(crate) mod tests {
|
||||
|
||||
// If `IsRoomMention` is present and disabled then is_room_mention_enabled()
|
||||
// should return `false` even if the deprecated rule is enabled
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
let mut ruleset = server_default_ruleset_with_legacy_mentions();
|
||||
ruleset
|
||||
.set_enabled(RuleKind::Override, PredefinedOverrideRuleId::IsRoomMention, false)
|
||||
.unwrap();
|
||||
|
||||
@@ -8,7 +8,7 @@ use matrix_sdk_test::{
|
||||
event_factory::EventFactory,
|
||||
};
|
||||
use ruma::{
|
||||
push::{Action, ConditionalPushRule, NewSimplePushRule, PatternedPushRule, Ruleset, Tweak},
|
||||
push::{Action, ConditionalPushRule, NewSimplePushRule, Ruleset, Tweak},
|
||||
room_id,
|
||||
};
|
||||
use serde_json::json;
|
||||
@@ -36,8 +36,6 @@ async fn test_get_notification_mode() {
|
||||
let f = EventFactory::new();
|
||||
|
||||
let mut ruleset = Ruleset::default();
|
||||
#[allow(deprecated)]
|
||||
ruleset.content.insert(PatternedPushRule::contains_user_name(client.user_id().unwrap()));
|
||||
ruleset.override_ =
|
||||
[ConditionalPushRule::master(), ConditionalPushRule::suppress_notices()].into();
|
||||
ruleset.room.insert(
|
||||
@@ -49,8 +47,6 @@ async fn test_get_notification_mode() {
|
||||
);
|
||||
ruleset.underride = [
|
||||
ConditionalPushRule::call(),
|
||||
#[allow(deprecated)]
|
||||
ConditionalPushRule::contains_display_name(),
|
||||
ConditionalPushRule::room_one_to_one(),
|
||||
ConditionalPushRule::invite_for_me(client.user_id().unwrap()),
|
||||
ConditionalPushRule::member_event(),
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use ruma::{
|
||||
RoomId, UserId,
|
||||
power_levels::NotificationPowerLevelsKey,
|
||||
push::{
|
||||
Action, NewConditionalPushRule, NewPushRule, NewSimplePushRule, PushCondition, RuleKind,
|
||||
Ruleset, Tweak,
|
||||
Action, ConditionalPushRule, ConditionalPushRuleInit, NewConditionalPushRule, NewPushRule,
|
||||
NewSimplePushRule, PatternedPushRule, PatternedPushRuleInit, PredefinedContentRuleId,
|
||||
PredefinedOverrideRuleId, PushCondition, RuleKind, Ruleset, Tweak,
|
||||
},
|
||||
user_id,
|
||||
};
|
||||
|
||||
fn user_id() -> &'static UserId {
|
||||
user_id!("@user:matrix.org")
|
||||
}
|
||||
|
||||
/// The ruleset containing the default spec push rules for the user
|
||||
/// `@user:matrix.org`.
|
||||
pub fn get_server_default_ruleset() -> Ruleset {
|
||||
let user_id = UserId::parse("@user:matrix.org").unwrap();
|
||||
Ruleset::server_default(&user_id)
|
||||
Ruleset::server_default(user_id())
|
||||
}
|
||||
|
||||
/// Build a new ruleset based on the server's default ruleset, by inserting a
|
||||
@@ -47,3 +55,59 @@ pub fn build_ruleset(rule_list: Vec<(RuleKind, &RoomId, bool)>) -> Ruleset {
|
||||
|
||||
ruleset
|
||||
}
|
||||
|
||||
/// The ruleset containing the default spec push rules and the legacy mention
|
||||
/// rules for the user `@user:matrix.org`.
|
||||
pub fn server_default_ruleset_with_legacy_mentions() -> Ruleset {
|
||||
let mut ruleset = get_server_default_ruleset();
|
||||
|
||||
// In the tests we don't care about the order, so we just add them to the end of
|
||||
// the lists.
|
||||
ruleset.content.insert(contains_user_name_push_rule());
|
||||
ruleset.override_.insert(contains_display_name_push_rule());
|
||||
ruleset.override_.insert(room_notif_push_rule());
|
||||
|
||||
ruleset
|
||||
}
|
||||
|
||||
/// Room mention rule that was removed from the spec.
|
||||
fn room_notif_push_rule() -> ConditionalPushRule {
|
||||
#[allow(deprecated)]
|
||||
ConditionalPushRuleInit {
|
||||
rule_id: PredefinedOverrideRuleId::RoomNotif.to_string(),
|
||||
default: true,
|
||||
enabled: true,
|
||||
conditions: vec![
|
||||
PushCondition::EventMatch { key: "content.body".into(), pattern: "@room".into() },
|
||||
PushCondition::SenderNotificationPermission { key: NotificationPowerLevelsKey::Room },
|
||||
],
|
||||
actions: vec![Action::Notify],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// User mention rule that was removed from the spec.
|
||||
fn contains_user_name_push_rule() -> PatternedPushRule {
|
||||
#[allow(deprecated)]
|
||||
PatternedPushRuleInit {
|
||||
rule_id: PredefinedContentRuleId::ContainsUserName.to_string(),
|
||||
default: true,
|
||||
enabled: true,
|
||||
pattern: user_id().localpart().into(),
|
||||
actions: vec![Action::Notify],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// User mention rule that was removed from the spec.
|
||||
fn contains_display_name_push_rule() -> ConditionalPushRule {
|
||||
#[allow(deprecated)]
|
||||
ConditionalPushRuleInit {
|
||||
rule_id: PredefinedOverrideRuleId::ContainsDisplayName.to_string(),
|
||||
default: true,
|
||||
enabled: true,
|
||||
conditions: vec![PushCondition::ContainsDisplayName],
|
||||
actions: vec![Action::Notify],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user