This commit is contained in:
Kegan Dougal 2017-05-15 15:17:06 +01:00
parent 2ff85d678d
commit 258f1a604f
2 changed files with 9 additions and 9 deletions

View file

@ -84,7 +84,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, pos types.StreamPosit
case "invite":
userIDs = append(userIDs, userID)
case "join":
n.userJoined(ev.RoomID(), userID)
n.addJoinedUser(ev.RoomID(), userID)
case "leave":
fallthrough
case "ban":
@ -131,14 +131,14 @@ func (n *Notifier) Load(db *storage.SyncServerDatabase) error {
if err != nil {
return err
}
n.usersJoinedToRooms(roomToUsers)
n.setUsersJoinedToRooms(roomToUsers)
return nil
}
// usersJoinedToRooms marks the given users as 'joined' to the given rooms, such that new events from
// setUsersJoinedToRooms marks the given users as 'joined' to the given rooms, such that new events from
// these rooms will wake the given users /sync requests. This should be called prior to ANY calls to
// OnNewEvent (eg on startup) to prevent racing.
func (n *Notifier) usersJoinedToRooms(roomIDToUserIDs map[string][]string) {
func (n *Notifier) setUsersJoinedToRooms(roomIDToUserIDs map[string][]string) {
// This is just the bulk form of userJoined where we only lock once.
n.roomIDToJoinedUsersMutex.Lock()
defer n.roomIDToJoinedUsersMutex.Unlock()
@ -180,7 +180,7 @@ func (n *Notifier) fetchUserStream(userID string, makeIfNotExists bool) *UserStr
return stream
}
func (n *Notifier) userJoined(roomID, userID string) {
func (n *Notifier) addJoinedUser(roomID, userID string) {
n.roomIDToJoinedUsersMutex.Lock()
defer n.roomIDToJoinedUsersMutex.Unlock()
if _, ok := n.roomIDToJoinedUsers[roomID]; !ok {

View file

@ -103,7 +103,7 @@ func TestImmediateNotification(t *testing.T) {
// Test that new events to a joined room unblocks the request.
func TestNewEventAndJoinedToRoom(t *testing.T) {
n := NewNotifier(streamPositionBefore)
n.usersJoinedToRooms(map[string][]string{
n.setUsersJoinedToRooms(map[string][]string{
roomID: []string{alice, bob},
})
@ -131,7 +131,7 @@ func TestNewEventAndJoinedToRoom(t *testing.T) {
// Test that an invite unblocks the request
func TestNewInviteEventForUser(t *testing.T) {
n := NewNotifier(streamPositionBefore)
n.usersJoinedToRooms(map[string][]string{
n.setUsersJoinedToRooms(map[string][]string{
roomID: []string{alice, bob},
})
@ -159,7 +159,7 @@ func TestNewInviteEventForUser(t *testing.T) {
// Test that all blocked requests get woken up on a new event.
func TestMultipleRequestWakeup(t *testing.T) {
n := NewNotifier(streamPositionBefore)
n.usersJoinedToRooms(map[string][]string{
n.setUsersJoinedToRooms(map[string][]string{
roomID: []string{alice, bob},
})
@ -197,7 +197,7 @@ func TestNewEventAndWasPreviouslyJoinedToRoom(t *testing.T) {
// listen as bob. Make bob leave room. Make alice send event to room.
// Make sure alice gets woken up only and not bob as well.
n := NewNotifier(streamPositionBefore)
n.usersJoinedToRooms(map[string][]string{
n.setUsersJoinedToRooms(map[string][]string{
roomID: []string{alice, bob},
})