mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Ignore users in pushrules
Add passing tests
This commit is contained in:
parent
918576a96a
commit
7c23e51861
|
|
@ -22,7 +22,7 @@ type SyncRequest struct {
|
||||||
// Updated by the PDU stream.
|
// Updated by the PDU stream.
|
||||||
Rooms map[string]string
|
Rooms map[string]string
|
||||||
// Updated by the PDU stream.
|
// Updated by the PDU stream.
|
||||||
IgnoredUsers map[string]interface{}
|
IgnoredUsers map[string]interface{} `json:"ignored_users"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StreamProvider interface {
|
type StreamProvider interface {
|
||||||
|
|
|
||||||
|
|
@ -681,4 +681,7 @@ Cannot send tombstone event that points to the same room
|
||||||
Room summary counts change when membership changes
|
Room summary counts change when membership changes
|
||||||
/upgrade copies >100 power levels to the new room
|
/upgrade copies >100 power levels to the new room
|
||||||
Room state after a rejected message event is the same as before
|
Room state after a rejected message event is the same as before
|
||||||
Room state after a rejected state event is the same as before
|
Room state after a rejected state event is the same as before
|
||||||
|
Ignore user in existing room
|
||||||
|
Ignore invite in full sync
|
||||||
|
Ignore invite in incremental sync
|
||||||
|
|
@ -395,6 +395,10 @@ func (s *OutputStreamEventConsumer) notifyLocal(ctx context.Context, event *goma
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ignoredUsers struct {
|
||||||
|
List map[string]interface{} `json:"ignored_users"`
|
||||||
|
}
|
||||||
|
|
||||||
// evaluatePushRules fetches and evaluates the push rules of a local
|
// evaluatePushRules fetches and evaluates the push rules of a local
|
||||||
// user. Returns actions (including dont_notify).
|
// user. Returns actions (including dont_notify).
|
||||||
func (s *OutputStreamEventConsumer) evaluatePushRules(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
|
func (s *OutputStreamEventConsumer) evaluatePushRules(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
|
||||||
|
|
@ -404,8 +408,24 @@ func (s *OutputStreamEventConsumer) evaluatePushRules(ctx context.Context, event
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get accountdata to check if the event.Sender() is ignored by mem.LocalPart
|
||||||
|
data, err := s.db.GetAccountDataByType(ctx, mem.Localpart, "", "m.ignored_user_list")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if data != nil {
|
||||||
|
ignored := ignoredUsers{}
|
||||||
|
err = json.Unmarshal(data, &ignored)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sender := event.Sender()
|
||||||
|
if _, ok := ignored.List[sender]; ok {
|
||||||
|
return nil, fmt.Errorf("user %s is ignored", sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
var res api.QueryPushRulesResponse
|
var res api.QueryPushRulesResponse
|
||||||
if err := s.userAPI.QueryPushRules(ctx, &api.QueryPushRulesRequest{UserID: mem.UserID}, &res); err != nil {
|
if err = s.userAPI.QueryPushRules(ctx, &api.QueryPushRulesRequest{UserID: mem.UserID}, &res); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue