Prevent duplicate users in ChannelStore
This commit is contained in:
parent
924bd8fdb1
commit
a3a934fff2
@ -51,6 +51,13 @@ func (c *ChannelStore) AddUser(user, server, channel string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if users, ok := c.users[server][channel]; ok {
|
if users, ok := c.users[server][channel]; ok {
|
||||||
|
for _, u := range users {
|
||||||
|
if u == user {
|
||||||
|
c.userLock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
c.users[server][channel] = append(users, user)
|
c.users[server][channel] = append(users, user)
|
||||||
} else {
|
} else {
|
||||||
c.users[server][channel] = []string{user}
|
c.users[server][channel] = []string{user}
|
||||||
|
@ -16,6 +16,8 @@ func TestGetSetUsers(t *testing.T) {
|
|||||||
func TestAddRemoveUser(t *testing.T) {
|
func TestAddRemoveUser(t *testing.T) {
|
||||||
channelStore := NewChannelStore()
|
channelStore := NewChannelStore()
|
||||||
channelStore.AddUser("user", "srv", "#chan")
|
channelStore.AddUser("user", "srv", "#chan")
|
||||||
|
channelStore.AddUser("user", "srv", "#chan")
|
||||||
|
assert.Len(t, channelStore.GetUsers("srv", "#chan"), 1)
|
||||||
channelStore.AddUser("user2", "srv", "#chan")
|
channelStore.AddUser("user2", "srv", "#chan")
|
||||||
assert.Equal(t, []string{"user", "user2"}, channelStore.GetUsers("srv", "#chan"))
|
assert.Equal(t, []string{"user", "user2"}, channelStore.GetUsers("srv", "#chan"))
|
||||||
channelStore.RemoveUser("user", "srv", "#chan")
|
channelStore.RemoveUser("user", "srv", "#chan")
|
||||||
|
Loading…
Reference in New Issue
Block a user