Fix nil pointer and goroutine safety in typing cache

Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
Cnly 2019-06-25 22:45:53 +08:00
parent 55a4e6061a
commit ba35a0a96d

View file

@ -62,11 +62,12 @@ func (t *TypingCache) GetTypingUsersIfUpdatedAfter(
roomID string, position int64,
) (users []string, updated bool) {
t.RLock()
defer t.RUnlock()
roomData, ok := t.data[roomID]
userSet := roomData.userSet
t.RUnlock()
if ok && roomData.syncPosition > position {
updated = true
userSet := roomData.userSet
users = make([]string, 0, len(userSet))
for userID := range userSet {
users = append(users, userID)