UserAPI roomserver uses userIDs for push rules

This commit is contained in:
Devon Hudson 2023-06-06 10:38:44 -06:00
parent 1f043efccc
commit c7bdc2e7f4
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
2 changed files with 14 additions and 10 deletions

View file

@ -620,9 +620,9 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
// user. Returns actions (including dont_notify). // user. Returns actions (including dont_notify).
func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *rstypes.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) { func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *rstypes.HeaderedEvent, mem *localMembership, roomSize int) ([]*pushrules.Action, error) {
user := "" user := ""
userID, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID()) sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err == nil { if err == nil {
user = userID.String() user = sender.String()
} }
if user == mem.UserID { if user == mem.UserID {
// SPEC: Homeservers MUST NOT notify the Push Gateway for // SPEC: Homeservers MUST NOT notify the Push Gateway for
@ -641,9 +641,8 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
if err != nil { if err != nil {
return nil, err return nil, err
} }
sender := event.SenderID() if _, ok := ignored.List[sender.String()]; ok {
if _, ok := ignored.List[sender]; ok { return nil, fmt.Errorf("user %s is ignored", sender.String())
return nil, fmt.Errorf("user %s is ignored", sender)
} }
} }
ruleSets, err := s.db.QueryPushRules(ctx, mem.Localpart, mem.Domain) ruleSets, err := s.db.QueryPushRules(ctx, mem.Localpart, mem.Domain)
@ -767,6 +766,11 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
} }
default: default:
sender, err := s.rsAPI.QueryUserIDForSender(ctx, event.RoomID(), event.SenderID())
if err != nil {
logger.WithError(err).Errorf("Failed to get userID for sender %s", event.SenderID())
return nil, err
}
req = pushgateway.NotifyRequest{ req = pushgateway.NotifyRequest{
Notification: pushgateway.Notification{ Notification: pushgateway.Notification{
Content: event.Content(), Content: event.Content(),
@ -778,7 +782,7 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *rstypes
ID: event.EventID(), ID: event.EventID(),
RoomID: event.RoomID(), RoomID: event.RoomID(),
RoomName: roomName, RoomName: roomName,
Sender: event.SenderID(), // TODO: Should push use UserIDs? Sender: sender.String(),
Type: event.Type(), Type: event.Type(),
}, },
} }

View file

@ -68,13 +68,13 @@ func Test_evaluatePushRules(t *testing.T) {
}{ }{
{ {
name: "m.receipt doesn't notify", name: "m.receipt doesn't notify",
eventContent: `{"type":"m.receipt","sender":"@test:remotehost"}`, eventContent: `{"type":"m.receipt"}`,
wantAction: pushrules.UnknownAction, wantAction: pushrules.UnknownAction,
wantActions: nil, wantActions: nil,
}, },
{ {
name: "m.reaction doesn't notify", name: "m.reaction doesn't notify",
eventContent: `{"type":"m.reaction","sender":"@test:remotehost"}`, eventContent: `{"type":"m.reaction"}`,
wantAction: pushrules.DontNotifyAction, wantAction: pushrules.DontNotifyAction,
wantActions: []*pushrules.Action{ wantActions: []*pushrules.Action{
{ {
@ -84,7 +84,7 @@ func Test_evaluatePushRules(t *testing.T) {
}, },
{ {
name: "m.room.message notifies", name: "m.room.message notifies",
eventContent: `{"type":"m.room.message","sender":"@test:remotehost"}`, eventContent: `{"type":"m.room.message"}`,
wantNotify: true, wantNotify: true,
wantAction: pushrules.NotifyAction, wantAction: pushrules.NotifyAction,
wantActions: []*pushrules.Action{ wantActions: []*pushrules.Action{
@ -93,7 +93,7 @@ func Test_evaluatePushRules(t *testing.T) {
}, },
{ {
name: "m.room.message highlights", name: "m.room.message highlights",
eventContent: `{"type":"m.room.message", "content": {"body": "test"},"sender":"@test:remotehost" }`, eventContent: `{"type":"m.room.message", "content": {"body": "test"}}`,
wantNotify: true, wantNotify: true,
wantAction: pushrules.NotifyAction, wantAction: pushrules.NotifyAction,
wantActions: []*pushrules.Action{ wantActions: []*pushrules.Action{