mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 03:49:27 +01:00
Use our own stringset instead of menge's
This commit is contained in:
parent
060d06ba6a
commit
e6ee9e50e0
@ -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}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user