From d7bdf71bef84ada254b4bada9be12b325236395f Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Sun, 30 Aug 2020 17:56:44 +0300 Subject: [PATCH] make PeekingDeviceSet private --- syncapi/sync/notifier.go | 29 ++++++++++++++++++++++++----- syncapi/types/types.go | 18 ------------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/syncapi/sync/notifier.go b/syncapi/sync/notifier.go index e5de78f6b..f09c2b4d8 100644 --- a/syncapi/sync/notifier.go +++ b/syncapi/sync/notifier.go @@ -34,7 +34,7 @@ type Notifier struct { // A map of RoomID => Set : Must only be accessed by the OnNewEvent goroutine roomIDToJoinedUsers map[string]userIDSet // A map of RoomID => Set : Must only be accessed by the OnNewEvent goroutine - roomIDToPeekingDevices map[string]PeekingDeviceSet + roomIDToPeekingDevices map[string]peekingDeviceSet // Protects currPos and userStreams. streamLock *sync.Mutex // The latest sync position @@ -52,7 +52,7 @@ func NewNotifier(pos types.StreamingToken) *Notifier { return &Notifier{ currPos: pos, roomIDToJoinedUsers: make(map[string]userIDSet), - roomIDToPeekingDevices: make(map[string]PeekingDeviceSet), + roomIDToPeekingDevices: make(map[string]peekingDeviceSet), userDeviceStreams: make(map[string]map[string]*UserDeviceStream), streamLock: &sync.Mutex{}, } @@ -225,7 +225,7 @@ func (n *Notifier) setPeekingDevices(roomIDToPeekingDevices map[string][]Peeking // This is just the bulk form of addPeekingDevice for roomID, peekingDevices := range roomIDToPeekingDevices { if _, ok := n.roomIDToPeekingDevices[roomID]; !ok { - n.roomIDToPeekingDevices[roomID] = make(PeekingDeviceSet) + n.roomIDToPeekingDevices[roomID] = make(peekingDeviceSet) } for _, peekingDevice := range peekingDevices { n.roomIDToPeekingDevices[roomID].add(peekingDevice) @@ -335,7 +335,7 @@ func (n *Notifier) joinedUsers(roomID string) (userIDs []string) { // Not thread-safe: must be called on the OnNewEvent goroutine only func (n *Notifier) addPeekingDevice(roomID, userID, deviceID string) { if _, ok := n.roomIDToPeekingDevices[roomID]; !ok { - n.roomIDToPeekingDevices[roomID] = make(PeekingDeviceSet) + n.roomIDToPeekingDevices[roomID] = make(peekingDeviceSet) } n.roomIDToPeekingDevices[roomID].add(PeekingDevice{deviceID, userID}) } @@ -343,7 +343,7 @@ func (n *Notifier) addPeekingDevice(roomID, userID, deviceID string) { // Not thread-safe: must be called on the OnNewEvent goroutine only func (n *Notifier) removePeekingDevice(roomID, userID, deviceID string) { if _, ok := n.roomIDToPeekingDevices[roomID]; !ok { - n.roomIDToPeekingDevices[roomID] = make(PeekingDeviceSet) + n.roomIDToPeekingDevices[roomID] = make(peekingDeviceSet) } // XXX: is this going to work as a key? n.roomIDToPeekingDevices[roomID].remove(PeekingDevice{deviceID, userID}) @@ -404,3 +404,22 @@ func (s userIDSet) values() (vals []string) { } return } + +// A set of PeekingDevices, similar to userIDSet + +type peekingDeviceSet map[PeekingDevice]bool + +func (s peekingDeviceSet) add(d PeekingDevice) { + s[d] = true +} + +func (s peekingDeviceSet) remove(d PeekingDevice) { + delete(s, d) +} + +func (s peekingDeviceSet) values() (vals []PeekingDevice) { + for d := range s { + vals = append(vals, d) + } + return +} diff --git a/syncapi/types/types.go b/syncapi/types/types.go index 0d3be2eff..fd28892f0 100644 --- a/syncapi/types/types.go +++ b/syncapi/types/types.go @@ -508,26 +508,8 @@ type SendToDeviceEvent struct { SentByToken *StreamingToken } -// For tracking peeking devices - type PeekingDevice struct { ID string UserID string } -type PeekingDeviceSet map[PeekingDevice]bool - -func (s PeekingDeviceSet) add(d PeekingDevice) { - s[d] = true -} - -func (s PeekingDeviceSet) remove(d PeekingDevice) { - delete(s, d) -} - -func (s PeekingDeviceSet) values() (vals []PeekingDevice) { - for d := range s { - vals = append(vals, d) - } - return -}