diff --git a/irc/client.go b/irc/client.go index 44d25ea8..087d5608 100644 --- a/irc/client.go +++ b/irc/client.go @@ -20,7 +20,6 @@ import ( "github.com/ergochat/irc-go/ircfmt" "github.com/ergochat/irc-go/ircmsg" "github.com/ergochat/irc-go/ircreader" - "github.com/soroushj/menge" "github.com/xdg-go/scram" "github.com/ergochat/ergo/irc/caps" @@ -176,7 +175,7 @@ type Session struct { capVersion caps.Version stateMutex sync.RWMutex // tier 1 - subscribedMetadataKeys menge.StringSet + subscribedMetadataKeys utils.StringSet registrationMessages int @@ -363,7 +362,7 @@ func (server *Server) RunClient(conn IRCConn) { proxiedIP: proxiedIP, isTor: wConn.Config.Tor, hideSTS: wConn.Config.Tor || wConn.Config.HideSTS, - subscribedMetadataKeys: menge.NewStringSet(), + subscribedMetadataKeys: make(utils.StringSet), } client.sessions = []*Session{session} diff --git a/irc/handlers.go b/irc/handlers.go index afb5956a..38bf3eb5 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -1737,7 +1737,7 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res continue } - if len(rb.session.subscribedMetadataKeys)+len(addedKeys) > config.MaxSubs { + if rb.session.subscribedMetadataKeys.Size() > config.MaxSubs { rb.Add(nil, server.name, ERR_METADATATOOMANYSUBS, client.nick, key) break } @@ -1754,8 +1754,8 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res } addedKeys = append(addedKeys, key) + rb.session.subscribedMetadataKeys.Add(key) } - rb.session.subscribedMetadataKeys.Add(addedKeys...) if len(addedKeys) > 0 { rb.Add(nil, server.name, RPL_METADATASUBOK, client.nick, strings.Join(addedKeys, " ")) @@ -1779,8 +1779,8 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res } removedKeys = append(removedKeys, key) + rb.session.subscribedMetadataKeys.Remove(key) } - rb.session.subscribedMetadataKeys.Remove(removedKeys...) if len(removedKeys) > 0 { rb.Add(nil, server.name, RPL_METADATAUNSUBOK, client.nick, strings.Join(removedKeys, " ")) @@ -1792,7 +1792,7 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res defer rb.session.stateMutex.RUnlock() if rb.session.subscribedMetadataKeys.Size() > 0 { //TODO: loop and return subscriptions with multiple numerics if we need to - rb.Add(nil, server.name, RPL_METADATASUBS, client.nick, strings.Join(rb.session.subscribedMetadataKeys.AsSlice(), " ")) + rb.Add(nil, server.name, RPL_METADATASUBS, client.nick, strings.Join(rb.session.subscribedMetadataKeys.Keys(), " ")) } rb.Add(nil, server.name, RPL_METADATAEND, client.nick, "end of metadata") } diff --git a/irc/utils/types.go b/irc/utils/types.go index 249b486e..bcb20153 100644 --- a/irc/utils/types.go +++ b/irc/utils/types.go @@ -15,3 +15,22 @@ func (s StringSet) Has(str string) bool { func (s StringSet) Add(str string) { s[str] = empty{} } + +func (s StringSet) Remove(str string) { + _, ok := s[str] + if ok { + delete(s, str) + } +} + +func (s StringSet) Size() int { + return len(s) +} + +func (s StringSet) Keys() (keys []string) { + for key := range s { + keys = append(keys, key) + } + + return keys +}