Browse Source

fix #2133 (#2137)

* fix #2133

Don't record NICK and QUIT in history for invisible auditorium members
pull/2140/head
Shivaram Lingamneni 1 month ago
parent
commit
8d082865da
No account linked to committer's email address
3 changed files with 29 additions and 4 deletions
  1. 20
    0
      irc/channel.go
  2. 6
    3
      irc/client.go
  3. 3
    1
      irc/nickname.go

+ 20
- 0
irc/channel.go View File

1622
 	return
1622
 	return
1623
 }
1623
 }
1624
 
1624
 
1625
+// returns whether the client is visible to unprivileged users in the channel
1626
+// (i.e., respecting auditorium mode). note that this assumes that the client
1627
+// is a member; if the client is not, it may return true anyway
1628
+func (channel *Channel) memberIsVisible(client *Client) bool {
1629
+	// fast path, we assume they're a member so if this isn't an auditorium,
1630
+	// they're visible:
1631
+	if !channel.flags.HasMode(modes.Auditorium) {
1632
+		return true
1633
+	}
1634
+
1635
+	channel.stateMutex.RLock()
1636
+	defer channel.stateMutex.RUnlock()
1637
+
1638
+	clientData, found := channel.members[client]
1639
+	if !found {
1640
+		return false
1641
+	}
1642
+	return clientData.modes.HighestChannelUserMode() != modes.Mode(0)
1643
+}
1644
+
1625
 // data for RPL_LIST
1645
 // data for RPL_LIST
1626
 func (channel *Channel) listData() (memberCount int, name, topic string) {
1646
 func (channel *Channel) listData() (memberCount int, name, topic string) {
1627
 	channel.stateMutex.RLock()
1647
 	channel.stateMutex.RLock()

+ 6
- 3
irc/client.go View File

1297
 	}
1297
 	}
1298
 
1298
 
1299
 	var quitItem history.Item
1299
 	var quitItem history.Item
1300
-	var channels []*Channel
1300
+	var quitHistoryChannels []*Channel
1301
 	// use a defer here to avoid writing to mysql while holding the destroy semaphore:
1301
 	// use a defer here to avoid writing to mysql while holding the destroy semaphore:
1302
 	defer func() {
1302
 	defer func() {
1303
-		for _, channel := range channels {
1303
+		for _, channel := range quitHistoryChannels {
1304
 			channel.AddHistoryItem(quitItem, details.account)
1304
 			channel.AddHistoryItem(quitItem, details.account)
1305
 		}
1305
 		}
1306
 	}()
1306
 	}()
1322
 	// clean up channels
1322
 	// clean up channels
1323
 	// (note that if this is a reattach, client has no channels and therefore no friends)
1323
 	// (note that if this is a reattach, client has no channels and therefore no friends)
1324
 	friends := make(ClientSet)
1324
 	friends := make(ClientSet)
1325
-	channels = client.Channels()
1325
+	channels := client.Channels()
1326
 	for _, channel := range channels {
1326
 	for _, channel := range channels {
1327
+		if channel.memberIsVisible(client) {
1328
+			quitHistoryChannels = append(quitHistoryChannels, channel)
1329
+		}
1327
 		for _, member := range channel.auditoriumFriends(client) {
1330
 		for _, member := range channel.auditoriumFriends(client) {
1328
 			friends.Add(member)
1331
 			friends.Add(member)
1329
 		}
1332
 		}

+ 3
- 1
irc/nickname.go View File

120
 	}
120
 	}
121
 
121
 
122
 	for _, channel := range target.Channels() {
122
 	for _, channel := range target.Channels() {
123
-		channel.AddHistoryItem(histItem, details.account)
123
+		if channel.memberIsVisible(client) {
124
+			channel.AddHistoryItem(histItem, details.account)
125
+		}
124
 	}
126
 	}
125
 
127
 
126
 	newCfnick := target.NickCasefolded()
128
 	newCfnick := target.NickCasefolded()

Loading…
Cancel
Save