Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 1b124fe

Browse files
authored
Implement MSC3987, fix setting Element Android notifications (#3242)
Should fix #3183, since Element Android already implements [MSC3987](element-hq/element-android#8530) This is also part of #3225
1 parent c1d6b9a commit 1b124fe

File tree

9 files changed

+18
-29
lines changed

9 files changed

+18
-29
lines changed

clientapi/clientapi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ func TestPushRules(t *testing.T) {
14181418
validateFunc: func(t *testing.T, respBody *bytes.Buffer) {
14191419
actions := gjson.GetBytes(respBody.Bytes(), "actions").Array()
14201420
// only a basic check
1421-
assert.Equal(t, 1, len(actions))
1421+
assert.Equal(t, 0, len(actions))
14221422
},
14231423
},
14241424
{

internal/pushrules/action_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ func TestActionJSON(t *testing.T) {
1313
Want Action
1414
}{
1515
{Action{Kind: NotifyAction}},
16-
{Action{Kind: DontNotifyAction}},
17-
{Action{Kind: CoalesceAction}},
1816
{Action{Kind: SetTweakAction}},
1917

2018
{Action{Kind: SetTweakAction, Tweak: SoundTweak, Value: "default"}},

internal/pushrules/default_override.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func defaultOverrideRules(userID string) []*Rule {
1010
&mRuleRoomNotifDefinition,
1111
&mRuleTombstoneDefinition,
1212
&mRuleReactionDefinition,
13+
&mRuleACLsDefinition,
1314
}
1415
}
1516

@@ -30,7 +31,7 @@ var (
3031
RuleID: MRuleMaster,
3132
Default: true,
3233
Enabled: false,
33-
Actions: []*Action{{Kind: DontNotifyAction}},
34+
Actions: []*Action{},
3435
}
3536
mRuleSuppressNoticesDefinition = Rule{
3637
RuleID: MRuleSuppressNotices,
@@ -43,7 +44,7 @@ var (
4344
Pattern: pointer("m.notice"),
4445
},
4546
},
46-
Actions: []*Action{{Kind: DontNotifyAction}},
47+
Actions: []*Action{},
4748
}
4849
mRuleMemberEventDefinition = Rule{
4950
RuleID: MRuleMemberEvent,
@@ -56,7 +57,7 @@ var (
5657
Pattern: pointer("m.room.member"),
5758
},
5859
},
59-
Actions: []*Action{{Kind: DontNotifyAction}},
60+
Actions: []*Action{},
6061
}
6162
mRuleContainsDisplayNameDefinition = Rule{
6263
RuleID: MRuleContainsDisplayName,
@@ -152,9 +153,7 @@ var (
152153
Pattern: pointer("m.reaction"),
153154
},
154155
},
155-
Actions: []*Action{
156-
{Kind: DontNotifyAction},
157-
},
156+
Actions: []*Action{},
158157
}
159158
)
160159

internal/pushrules/default_pushrules_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ func TestDefaultRules(t *testing.T) {
2121
// Default override rules
2222
{
2323
name: ".m.rule.master",
24-
inputBytes: []byte(`{"rule_id":".m.rule.master","default":true,"enabled":false,"actions":["dont_notify"]}`),
24+
inputBytes: []byte(`{"rule_id":".m.rule.master","default":true,"enabled":false,"actions":[]}`),
2525
want: mRuleMasterDefinition,
2626
},
2727
{
2828
name: ".m.rule.suppress_notices",
29-
inputBytes: []byte(`{"rule_id":".m.rule.suppress_notices","default":true,"enabled":true,"conditions":[{"kind":"event_match","key":"content.msgtype","pattern":"m.notice"}],"actions":["dont_notify"]}`),
29+
inputBytes: []byte(`{"rule_id":".m.rule.suppress_notices","default":true,"enabled":true,"conditions":[{"kind":"event_match","key":"content.msgtype","pattern":"m.notice"}],"actions":[]}`),
3030
want: mRuleSuppressNoticesDefinition,
3131
},
3232
{
@@ -36,7 +36,7 @@ func TestDefaultRules(t *testing.T) {
3636
},
3737
{
3838
name: ".m.rule.member_event",
39-
inputBytes: []byte(`{"rule_id":".m.rule.member_event","default":true,"enabled":true,"conditions":[{"kind":"event_match","key":"type","pattern":"m.room.member"}],"actions":["dont_notify"]}`),
39+
inputBytes: []byte(`{"rule_id":".m.rule.member_event","default":true,"enabled":true,"conditions":[{"kind":"event_match","key":"type","pattern":"m.room.member"}],"actions":[]}`),
4040
want: mRuleMemberEventDefinition,
4141
},
4242
{

internal/pushrules/util.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ func ActionsToTweaks(as []*Action) (ActionKind, map[string]interface{}, error) {
1616

1717
for _, a := range as {
1818
switch a.Kind {
19-
case DontNotifyAction:
20-
// Don't bother processing any further
21-
return DontNotifyAction, nil, nil
22-
19+
case DontNotifyAction: // Ignored
2320
case SetTweakAction:
2421
if tweaks == nil {
2522
tweaks = map[string]interface{}{}

internal/pushrules/util_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ func TestActionsToTweaks(t *testing.T) {
1717
{"empty", nil, UnknownAction, nil},
1818
{"zero", []*Action{{}}, UnknownAction, nil},
1919
{"onlyPrimary", []*Action{{Kind: NotifyAction}}, NotifyAction, nil},
20-
{"onlyPrimaryDontNotify", []*Action{{Kind: DontNotifyAction}}, DontNotifyAction, nil},
20+
{"onlyPrimaryDontNotify", []*Action{}, UnknownAction, nil},
2121
{"onlyTweak", []*Action{{Kind: SetTweakAction, Tweak: HighlightTweak}}, UnknownAction, map[string]interface{}{"highlight": nil}},
2222
{"onlyTweakWithValue", []*Action{{Kind: SetTweakAction, Tweak: SoundTweak, Value: "default"}}, UnknownAction, map[string]interface{}{"sound": "default"}},
2323
{
2424
"all",
2525
[]*Action{
26-
{Kind: CoalesceAction},
2726
{Kind: SetTweakAction, Tweak: HighlightTweak},
2827
{Kind: SetTweakAction, Tweak: SoundTweak, Value: "default"},
2928
},
30-
CoalesceAction,
29+
UnknownAction,
3130
map[string]interface{}{"highlight": nil, "sound": "default"},
3231
},
3332
}

internal/pushrules/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func ValidateRule(kind Kind, rule *Rule) []error {
1818
errs = append(errs, fmt.Errorf("invalid rule ID: %s", rule.RuleID))
1919
}
2020

21-
if len(rule.Actions) == 0 {
21+
if rule.Actions == nil {
2222
errs = append(errs, fmt.Errorf("missing actions"))
2323
}
2424
for _, action := range rule.Actions {

userapi/consumers/roomserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
538538
if err != nil {
539539
return fmt.Errorf("pushrules.ActionsToTweaks: %w", err)
540540
}
541-
// TODO: support coalescing.
542-
if a != pushrules.NotifyAction && a != pushrules.CoalesceAction {
541+
542+
if a != pushrules.NotifyAction {
543543
log.WithFields(log.Fields{
544544
"event_id": event.EventID(),
545545
"room_id": event.RoomID().String(),

userapi/consumers/roomserver_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ func Test_evaluatePushRules(t *testing.T) {
8181
{
8282
name: "m.reaction doesn't notify",
8383
eventContent: `{"type":"m.reaction","room_id":"!room:example.com"}`,
84-
wantAction: pushrules.DontNotifyAction,
85-
wantActions: []*pushrules.Action{
86-
{
87-
Kind: pushrules.DontNotifyAction,
88-
},
89-
},
84+
wantAction: pushrules.UnknownAction,
85+
wantActions: []*pushrules.Action{},
9086
},
9187
{
9288
name: "m.room.message notifies",
@@ -136,7 +132,7 @@ func Test_evaluatePushRules(t *testing.T) {
136132
t.Fatalf("expected action to be '%s', got '%s'", tc.wantAction, gotAction)
137133
}
138134
// this is taken from `notifyLocal`
139-
if tc.wantNotify && gotAction != pushrules.NotifyAction && gotAction != pushrules.CoalesceAction {
135+
if tc.wantNotify && gotAction != pushrules.NotifyAction {
140136
t.Fatalf("expected to notify but didn't")
141137
}
142138
})

0 commit comments

Comments
 (0)