Browse Source

Merge pull request #1761 from delthas/feature-extended-monitor

Add support for extended-monitor
tags/v2.8.0-rc1
Shivaram Lingamneni 2 years ago
parent
commit
9b6ec04ca5
No account linked to committer's email address
5 changed files with 36 additions and 5 deletions
  1. 6
    0
      gencapdefs.py
  2. 6
    1
      irc/caps/defs.go
  3. 8
    1
      irc/client.go
  4. 3
    3
      irc/handlers.go
  5. 13
    0
      irc/monitor.go

+ 6
- 0
gencapdefs.py View File

177
         url="https://github.com/ircv3/ircv3-specifications/pull/435",
177
         url="https://github.com/ircv3/ircv3-specifications/pull/435",
178
         standard="draft IRCv3",
178
         standard="draft IRCv3",
179
     ),
179
     ),
180
+    CapDef(
181
+        identifier="ExtendedMonitor",
182
+        name="draft/extended-monitor",
183
+        url="https://github.com/ircv3/ircv3-specifications/pull/466",
184
+        standard="draft IRCv3",
185
+    ),
180
 ]
186
 ]
181
 
187
 
182
 def validate_defs():
188
 def validate_defs():

+ 6
- 1
irc/caps/defs.go View File

7
 
7
 
8
 const (
8
 const (
9
 	// number of recognized capabilities:
9
 	// number of recognized capabilities:
10
-	numCapabs = 27
10
+	numCapabs = 28
11
 	// length of the uint64 array that represents the bitset:
11
 	// length of the uint64 array that represents the bitset:
12
 	bitsetLen = 1
12
 	bitsetLen = 1
13
 )
13
 )
53
 	// https://github.com/ircv3/ircv3-specifications/pull/362
53
 	// https://github.com/ircv3/ircv3-specifications/pull/362
54
 	EventPlayback Capability = iota
54
 	EventPlayback Capability = iota
55
 
55
 
56
+	// ExtendedMonitor is the draft IRCv3 capability named "draft/extended-monitor":
57
+	// https://github.com/ircv3/ircv3-specifications/pull/466
58
+	ExtendedMonitor Capability = iota
59
+
56
 	// Languages is the proposed IRCv3 capability named "draft/languages":
60
 	// Languages is the proposed IRCv3 capability named "draft/languages":
57
 	// https://gist.github.com/DanielOaks/8126122f74b26012a3de37db80e4e0c6
61
 	// https://gist.github.com/DanielOaks/8126122f74b26012a3de37db80e4e0c6
58
 	Languages Capability = iota
62
 	Languages Capability = iota
135
 		"draft/channel-rename",
139
 		"draft/channel-rename",
136
 		"draft/chathistory",
140
 		"draft/chathistory",
137
 		"draft/event-playback",
141
 		"draft/event-playback",
142
+		"draft/extended-monitor",
138
 		"draft/languages",
143
 		"draft/languages",
139
 		"draft/multiline",
144
 		"draft/multiline",
140
 		"draft/relaymsg",
145
 		"draft/relaymsg",

+ 8
- 1
irc/client.go View File

1025
 	return
1025
 	return
1026
 }
1026
 }
1027
 
1027
 
1028
+// Friends refers to clients that share a channel or extended-monitor this client.
1029
+func (client *Client) FriendsMonitors(capabs ...caps.Capability) (result map[*Session]empty) {
1030
+	result = client.Friends(capabs...)
1031
+	client.server.monitorManager.AddMonitors(result, client.nickCasefolded, capabs...)
1032
+	return
1033
+}
1034
+
1028
 // helper for Friends
1035
 // helper for Friends
1029
 func addFriendsToSet(set map[*Session]empty, client *Client, capabs ...caps.Capability) {
1036
 func addFriendsToSet(set map[*Session]empty, client *Client, capabs ...caps.Capability) {
1030
 	client.stateMutex.RLock()
1037
 	client.stateMutex.RLock()
1049
 func (client *Client) sendChghost(oldNickMask string, vhost string) {
1056
 func (client *Client) sendChghost(oldNickMask string, vhost string) {
1050
 	details := client.Details()
1057
 	details := client.Details()
1051
 	isBot := client.HasMode(modes.Bot)
1058
 	isBot := client.HasMode(modes.Bot)
1052
-	for fClient := range client.Friends(caps.ChgHost) {
1059
+	for fClient := range client.FriendsMonitors(caps.ChgHost) {
1053
 		fClient.sendFromClientInternal(false, time.Time{}, "", oldNickMask, details.accountName, isBot, nil, "CHGHOST", details.username, vhost)
1060
 		fClient.sendFromClientInternal(false, time.Time{}, "", oldNickMask, details.accountName, isBot, nil, "CHGHOST", details.username, vhost)
1054
 	}
1061
 	}
1055
 }
1062
 }

+ 3
- 3
irc/handlers.go View File

109
 
109
 
110
 	if client.Registered() {
110
 	if client.Registered() {
111
 		// dispatch account-notify
111
 		// dispatch account-notify
112
-		for friend := range client.Friends(caps.AccountNotify) {
112
+		for friend := range client.FriendsMonitors(caps.AccountNotify) {
113
 			if friend != rb.session {
113
 			if friend != rb.session {
114
 				friend.Send(nil, details.nickMask, "ACCOUNT", details.accountName)
114
 				friend.Send(nil, details.nickMask, "ACCOUNT", details.accountName)
115
 			}
115
 			}
421
 	// dispatch away-notify
421
 	// dispatch away-notify
422
 	details := client.Details()
422
 	details := client.Details()
423
 	isBot := client.HasMode(modes.Bot)
423
 	isBot := client.HasMode(modes.Bot)
424
-	for session := range client.Friends(caps.AwayNotify) {
424
+	for session := range client.FriendsMonitors(caps.AwayNotify) {
425
 		if isAway {
425
 		if isAway {
426
 			session.sendFromClientInternal(false, time.Time{}, "", details.nickMask, details.accountName, isBot, nil, "AWAY", awayMessage)
426
 			session.sendFromClientInternal(false, time.Time{}, "", details.nickMask, details.accountName, isBot, nil, "AWAY", awayMessage)
427
 		} else {
427
 		} else {
2926
 
2926
 
2927
 	// alert friends
2927
 	// alert friends
2928
 	now := time.Now().UTC()
2928
 	now := time.Now().UTC()
2929
-	friends := client.Friends(caps.SetName)
2929
+	friends := client.FriendsMonitors(caps.SetName)
2930
 	delete(friends, rb.session)
2930
 	delete(friends, rb.session)
2931
 	isBot := client.HasMode(modes.Bot)
2931
 	isBot := client.HasMode(modes.Bot)
2932
 	for session := range friends {
2932
 	for session := range friends {

+ 13
- 0
irc/monitor.go View File

6
 import (
6
 import (
7
 	"sync"
7
 	"sync"
8
 
8
 
9
+	"github.com/ergochat/ergo/irc/caps"
10
+
9
 	"github.com/ergochat/irc-go/ircmsg"
11
 	"github.com/ergochat/irc-go/ircmsg"
10
 )
12
 )
11
 
13
 
23
 	mm.watchedby = make(map[string]map[*Session]empty)
25
 	mm.watchedby = make(map[string]map[*Session]empty)
24
 }
26
 }
25
 
27
 
28
+// AddMonitors adds clients using extended-monitor monitoring `client`'s nick to the passed user set.
29
+func (manager *MonitorManager) AddMonitors(users map[*Session]empty, cfnick string, capabs ...caps.Capability) {
30
+	manager.RLock()
31
+	defer manager.RUnlock()
32
+	for session := range manager.watchedby[cfnick] {
33
+		if session.capabilities.Has(caps.ExtendedMonitor) && session.capabilities.HasAll(capabs...) {
34
+			users[session] = empty{}
35
+		}
36
+	}
37
+}
38
+
26
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
39
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
27
 func (manager *MonitorManager) AlertAbout(nick, cfnick string, online bool) {
40
 func (manager *MonitorManager) AlertAbout(nick, cfnick string, online bool) {
28
 	var watchers []*Session
41
 	var watchers []*Session

Loading…
Cancel
Save