Fix parsing bugs

This commit is contained in:
tezlm 2023-10-09 23:44:36 -07:00
parent fd8da62a88
commit 7ec1ec2473
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
3 changed files with 9 additions and 20 deletions

View file

@ -13,7 +13,7 @@ to be faster and flexible-er than the current push rule system!
"enabled": true
},
"m.highlight": {
"rule": "(all @'m.unread' (any (in user_id event.content.'m.mentions'.user_ids)) (all (event.content.'m.mentions'.room) (can-send 'room')))",
"rule": "(all @'m.unread' (any (in user_id event.content.'m.mentions'.user_ids) (all event.content.'m.mentions'.room (can-notfy 'room'))))",
"actions": ["notify", "store", "mark"],
"enabled": true
},
@ -51,10 +51,10 @@ push rules.
The rules aren't mean to be machine-edited - make them read from account
data instead.
The implementation of p2 takes the config and compiles it to
stack-based bytecode, and lazy loads state events and account data. Is
it overengineered? Probably! Does it work? Definitely! Most of the code
is in a [single file](src/utils/p2.rs) currently.
This implementation of p2 takes the ruleset and precompiles it to
stack-based bytecode-ish intermediate representation, which is then
evaluated on all new events. It lazy loads state events and account
data. Most of the code is in a [single file](src/utils/p2.rs) currently.
### why?
@ -90,9 +90,6 @@ state, needing an extra db lookup for every event to check for marks.
This system requires `m.mentions` to be in plaintext, which some people
may not want.
This system might be harder to retrofit things into. With the json push
rules, it's as simple as adding a `do_some_specific_thing`.
### spec?
This is a custom system that exists outside of the official matrix

View file

@ -28,7 +28,7 @@ pub async fn set_global_account_data_route(
match event_type.as_str() {
"p2.rules" => {
P2Rules::compile_value(data.clone())?;
dbg!(P2Rules::compile_value(data.clone())?);
services().rooms.timeline.p2_uncache_rules(None, &sender_user)?;
}
"p2.counters" => {
@ -65,7 +65,7 @@ pub async fn set_room_account_data_route(
match event_type.as_str() {
"p2.rules" => {
P2Rules::compile_value(data.clone())?;
dbg!(P2Rules::compile_value(data.clone())?);
services().rooms.timeline.p2_uncache_rules(Some(&body.room_id), &sender_user)?;
}
"p2.counters" => {

View file

@ -292,7 +292,9 @@ impl P2Rule {
("lt", 2) => P2RuleOp::Lt,
("gte", 2) => P2RuleOp::Gte,
("lte", 2) => P2RuleOp::Lte,
("get", 1) => P2RuleOp::GetDyn,
// ("like", 2) => P2RuleOp::Like,
// ("match", 2) => P2RuleOp::Match,
("in", 2) => P2RuleOp::In,
("default", n) if n >= 1 => P2RuleOp::Coalesce(n),
("can-notify", 1) => P2RuleOp::CanNotify,
@ -333,16 +335,6 @@ impl P2Rule {
loop {
match tokens.peek() {
Some((P2TokenType::OpenBracket, None)) => {
tokens.next();
P2Rule::generate(tokens, ops, depends)?;
match tokens.next() {
Some((P2TokenType::CloseBracket, None)) => (),
Some((_, _)) => return Err(P2RuleError::InvalidToken),
None => return Err(P2RuleError::UnexpectedEOF),
};
ops.push(P2RuleOp::GetDyn);
}
Some((P2TokenType::Dot, None)) => {
tokens.next();
let path = match tokens.next() {