mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 11:13:12 -06:00
Refactor SharedUsers
This commit is contained in:
parent
31fa33cbde
commit
4d2d79b4da
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -253,15 +252,25 @@ func (n *Notifier) OnNewPresence(
|
||||||
n.wakeupUsers(sharedUsers, nil, n.currPos)
|
n.wakeupUsers(sharedUsers, nil, n.currPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) SharedUsers(userID string) (sharedUsers []string) {
|
func (n *Notifier) SharedUsers(userID string) []string {
|
||||||
n.mapLock.RLock()
|
n.mapLock.RLock()
|
||||||
defer n.mapLock.RUnlock()
|
defer n.mapLock.RUnlock()
|
||||||
|
sharedMap := map[string]struct{}{
|
||||||
|
userID: {},
|
||||||
|
}
|
||||||
for roomID, users := range n.roomIDToJoinedUsers {
|
for roomID, users := range n.roomIDToJoinedUsers {
|
||||||
if _, ok := users[userID]; ok {
|
if _, ok := users[userID]; !ok {
|
||||||
sharedUsers = append(sharedUsers, n.JoinedUsers(roomID)...)
|
continue
|
||||||
|
}
|
||||||
|
for _, userID := range n.JoinedUsers(roomID) {
|
||||||
|
sharedMap[userID] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return util.UniqueStrings(sharedUsers)
|
sharedUsers := make([]string, 0, len(sharedMap))
|
||||||
|
for userID := range sharedMap {
|
||||||
|
sharedUsers = append(sharedUsers, userID)
|
||||||
|
}
|
||||||
|
return sharedUsers
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) IsSharedUser(userA, userB string) bool {
|
func (n *Notifier) IsSharedUser(userA, userB string) bool {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue