Calculate correct room member count for push rule evaluation (#2894)
Fixes a bug where we would return only the local member count, which could result in wrongly calculated push rules.
This commit is contained in:
parent
ed497aa8b2
commit
ac5f3f025e
|
@ -385,7 +385,6 @@ func (s *OutputRoomEventConsumer) localRoomMembers(ctx context.Context, roomID s
|
||||||
req := &rsapi.QueryMembershipsForRoomRequest{
|
req := &rsapi.QueryMembershipsForRoomRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
JoinedOnly: true,
|
JoinedOnly: true,
|
||||||
LocalOnly: true,
|
|
||||||
}
|
}
|
||||||
var res rsapi.QueryMembershipsForRoomResponse
|
var res rsapi.QueryMembershipsForRoomResponse
|
||||||
|
|
||||||
|
@ -396,8 +395,23 @@ func (s *OutputRoomEventConsumer) localRoomMembers(ctx context.Context, roomID s
|
||||||
}
|
}
|
||||||
|
|
||||||
var members []*localMembership
|
var members []*localMembership
|
||||||
var ntotal int
|
|
||||||
for _, event := range res.JoinEvents {
|
for _, event := range res.JoinEvents {
|
||||||
|
// Filter out invalid join events
|
||||||
|
if event.StateKey == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if *event.StateKey == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_, serverName, err := gomatrixserverlib.SplitID('@', *event.StateKey)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to get servername from statekey")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Only get memberships for our server
|
||||||
|
if serverName != s.serverName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
member, err := newLocalMembership(&event)
|
member, err := newLocalMembership(&event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("Parsing MemberContent")
|
log.WithError(err).Errorf("Parsing MemberContent")
|
||||||
|
@ -410,11 +424,10 @@ func (s *OutputRoomEventConsumer) localRoomMembers(ctx context.Context, roomID s
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ntotal++
|
|
||||||
members = append(members, member)
|
members = append(members, member)
|
||||||
}
|
}
|
||||||
|
|
||||||
return members, ntotal, nil
|
return members, len(res.JoinEvents), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// roomName returns the name in the event (if type==m.room.name), or
|
// roomName returns the name in the event (if type==m.room.name), or
|
||||||
|
@ -641,7 +654,7 @@ func (s *OutputRoomEventConsumer) evaluatePushRules(ctx context.Context, event *
|
||||||
if rule == nil {
|
if rule == nil {
|
||||||
// SPEC: If no rules match an event, the homeserver MUST NOT
|
// SPEC: If no rules match an event, the homeserver MUST NOT
|
||||||
// notify the Push Gateway for that event.
|
// notify the Push Gateway for that event.
|
||||||
return nil, err
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
|
Loading…
Reference in a new issue