Don't create fictitious presence entries (#2381)

* Don't create fictitious presence entries for users that don't have any

* Update whitelist, since that test probably shouldn't be passing

* Fix panics
This commit is contained in:
Neil Alexander 2022-04-27 11:25:07 +01:00 committed by GitHub
parent 6c5c6d73d7
commit 66b397b3c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 19 deletions

View file

@ -16,7 +16,6 @@ package streams
import (
"context"
"database/sql"
"encoding/json"
"sync"
@ -80,11 +79,10 @@ func (p *PresenceStreamProvider) IncrementalSync(
if _, ok := presences[roomUsers[i]]; ok {
continue
}
// Bear in mind that this might return nil, but at least populating
// a nil means that there's a map entry so we won't repeat this call.
presences[roomUsers[i]], err = p.DB.GetPresence(ctx, roomUsers[i])
if err != nil {
if err == sql.ErrNoRows {
continue
}
req.Log.WithError(err).Error("unable to query presence for user")
return from
}
@ -93,8 +91,10 @@ func (p *PresenceStreamProvider) IncrementalSync(
}
lastPos := to
for i := range presences {
presence := presences[i]
for _, presence := range presences {
if presence == nil {
continue
}
// Ignore users we don't share a room with
if req.Device.UserID != presence.UserID && !p.notifier.IsSharedUser(req.Device.UserID, presence.UserID) {
continue