浏览代码

Use our own stringset instead of menge's

metadata
Daniel Oaks 2 年前
父节点
当前提交
e6ee9e50e0
共有 3 个文件被更改,包括 25 次插入7 次删除
  1. 2
    3
      irc/client.go
  2. 4
    4
      irc/handlers.go
  3. 19
    0
      irc/utils/types.go

+ 2
- 3
irc/client.go 查看文件

@@ -20,7 +20,6 @@ import (
20 20
 	"github.com/ergochat/irc-go/ircfmt"
21 21
 	"github.com/ergochat/irc-go/ircmsg"
22 22
 	"github.com/ergochat/irc-go/ircreader"
23
-	"github.com/soroushj/menge"
24 23
 	"github.com/xdg-go/scram"
25 24
 
26 25
 	"github.com/ergochat/ergo/irc/caps"
@@ -176,7 +175,7 @@ type Session struct {
176 175
 	capVersion   caps.Version
177 176
 
178 177
 	stateMutex             sync.RWMutex // tier 1
179
-	subscribedMetadataKeys menge.StringSet
178
+	subscribedMetadataKeys utils.StringSet
180 179
 
181 180
 	registrationMessages int
182 181
 
@@ -363,7 +362,7 @@ func (server *Server) RunClient(conn IRCConn) {
363 362
 		proxiedIP:              proxiedIP,
364 363
 		isTor:                  wConn.Config.Tor,
365 364
 		hideSTS:                wConn.Config.Tor || wConn.Config.HideSTS,
366
-		subscribedMetadataKeys: menge.NewStringSet(),
365
+		subscribedMetadataKeys: make(utils.StringSet),
367 366
 	}
368 367
 	client.sessions = []*Session{session}
369 368
 

+ 4
- 4
irc/handlers.go 查看文件

@@ -1737,7 +1737,7 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
1737 1737
 				continue
1738 1738
 			}
1739 1739
 
1740
-			if len(rb.session.subscribedMetadataKeys)+len(addedKeys) > config.MaxSubs {
1740
+			if rb.session.subscribedMetadataKeys.Size() > config.MaxSubs {
1741 1741
 				rb.Add(nil, server.name, ERR_METADATATOOMANYSUBS, client.nick, key)
1742 1742
 				break
1743 1743
 			}
@@ -1754,8 +1754,8 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
1754 1754
 			}
1755 1755
 
1756 1756
 			addedKeys = append(addedKeys, key)
1757
+			rb.session.subscribedMetadataKeys.Add(key)
1757 1758
 		}
1758
-		rb.session.subscribedMetadataKeys.Add(addedKeys...)
1759 1759
 
1760 1760
 		if len(addedKeys) > 0 {
1761 1761
 			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
1779 1779
 			}
1780 1780
 
1781 1781
 			removedKeys = append(removedKeys, key)
1782
+			rb.session.subscribedMetadataKeys.Remove(key)
1782 1783
 		}
1783
-		rb.session.subscribedMetadataKeys.Remove(removedKeys...)
1784 1784
 
1785 1785
 		if len(removedKeys) > 0 {
1786 1786
 			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
1792 1792
 		defer rb.session.stateMutex.RUnlock()
1793 1793
 		if rb.session.subscribedMetadataKeys.Size() > 0 {
1794 1794
 			//TODO: loop and return subscriptions with multiple numerics if we need to
1795
-			rb.Add(nil, server.name, RPL_METADATASUBS, client.nick, strings.Join(rb.session.subscribedMetadataKeys.AsSlice(), " "))
1795
+			rb.Add(nil, server.name, RPL_METADATASUBS, client.nick, strings.Join(rb.session.subscribedMetadataKeys.Keys(), " "))
1796 1796
 		}
1797 1797
 		rb.Add(nil, server.name, RPL_METADATAEND, client.nick, "end of metadata")
1798 1798
 	}

+ 19
- 0
irc/utils/types.go 查看文件

@@ -15,3 +15,22 @@ func (s StringSet) Has(str string) bool {
15 15
 func (s StringSet) Add(str string) {
16 16
 	s[str] = empty{}
17 17
 }
18
+
19
+func (s StringSet) Remove(str string) {
20
+	_, ok := s[str]
21
+	if ok {
22
+		delete(s, str)
23
+	}
24
+}
25
+
26
+func (s StringSet) Size() int {
27
+	return len(s)
28
+}
29
+
30
+func (s StringSet) Keys() (keys []string) {
31
+	for key := range s {
32
+		keys = append(keys, key)
33
+	}
34
+
35
+	return keys
36
+}

正在加载...
取消
保存