Browse Source

Use our own stringset instead of menge's

metadata
Daniel Oaks 2 years ago
parent
commit
e6ee9e50e0
3 changed files with 25 additions and 7 deletions
  1. 2
    3
      irc/client.go
  2. 4
    4
      irc/handlers.go
  3. 19
    0
      irc/utils/types.go

+ 2
- 3
irc/client.go View File

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

+ 4
- 4
irc/handlers.go View File

1737
 				continue
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
 				rb.Add(nil, server.name, ERR_METADATATOOMANYSUBS, client.nick, key)
1741
 				rb.Add(nil, server.name, ERR_METADATATOOMANYSUBS, client.nick, key)
1742
 				break
1742
 				break
1743
 			}
1743
 			}
1754
 			}
1754
 			}
1755
 
1755
 
1756
 			addedKeys = append(addedKeys, key)
1756
 			addedKeys = append(addedKeys, key)
1757
+			rb.session.subscribedMetadataKeys.Add(key)
1757
 		}
1758
 		}
1758
-		rb.session.subscribedMetadataKeys.Add(addedKeys...)
1759
 
1759
 
1760
 		if len(addedKeys) > 0 {
1760
 		if len(addedKeys) > 0 {
1761
 			rb.Add(nil, server.name, RPL_METADATASUBOK, client.nick, strings.Join(addedKeys, " "))
1761
 			rb.Add(nil, server.name, RPL_METADATASUBOK, client.nick, strings.Join(addedKeys, " "))
1779
 			}
1779
 			}
1780
 
1780
 
1781
 			removedKeys = append(removedKeys, key)
1781
 			removedKeys = append(removedKeys, key)
1782
+			rb.session.subscribedMetadataKeys.Remove(key)
1782
 		}
1783
 		}
1783
-		rb.session.subscribedMetadataKeys.Remove(removedKeys...)
1784
 
1784
 
1785
 		if len(removedKeys) > 0 {
1785
 		if len(removedKeys) > 0 {
1786
 			rb.Add(nil, server.name, RPL_METADATAUNSUBOK, client.nick, strings.Join(removedKeys, " "))
1786
 			rb.Add(nil, server.name, RPL_METADATAUNSUBOK, client.nick, strings.Join(removedKeys, " "))
1792
 		defer rb.session.stateMutex.RUnlock()
1792
 		defer rb.session.stateMutex.RUnlock()
1793
 		if rb.session.subscribedMetadataKeys.Size() > 0 {
1793
 		if rb.session.subscribedMetadataKeys.Size() > 0 {
1794
 			//TODO: loop and return subscriptions with multiple numerics if we need to
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
 		rb.Add(nil, server.name, RPL_METADATAEND, client.nick, "end of metadata")
1797
 		rb.Add(nil, server.name, RPL_METADATAEND, client.nick, "end of metadata")
1798
 	}
1798
 	}

+ 19
- 0
irc/utils/types.go View File

15
 func (s StringSet) Add(str string) {
15
 func (s StringSet) Add(str string) {
16
 	s[str] = empty{}
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
+}

Loading…
Cancel
Save