Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2133 #2137

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions irc/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,26 @@ func (channel *Channel) auditoriumFriends(client *Client) (friends []*Client) {
return
}

// returns whether the client is visible to unprivileged users in the channel
// (i.e., respecting auditorium mode). note that this assumes that the client
// is a member; if the client is not, it may return true anyway
func (channel *Channel) memberIsVisible(client *Client) bool {
// fast path, we assume they're a member so if this isn't an auditorium,
// they're visible:
if !channel.flags.HasMode(modes.Auditorium) {
return true
}

channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock()

clientData, found := channel.members[client]
if !found {
return false
}
return clientData.modes.HighestChannelUserMode() != modes.Mode(0)
}

// data for RPL_LIST
func (channel *Channel) listData() (memberCount int, name, topic string) {
channel.stateMutex.RLock()
Expand Down
9 changes: 6 additions & 3 deletions irc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,10 @@ func (client *Client) destroy(session *Session) {
}

var quitItem history.Item
var channels []*Channel
var quitHistoryChannels []*Channel
// use a defer here to avoid writing to mysql while holding the destroy semaphore:
defer func() {
for _, channel := range channels {
for _, channel := range quitHistoryChannels {
channel.AddHistoryItem(quitItem, details.account)
}
}()
Expand All @@ -1322,8 +1322,11 @@ func (client *Client) destroy(session *Session) {
// clean up channels
// (note that if this is a reattach, client has no channels and therefore no friends)
friends := make(ClientSet)
channels = client.Channels()
channels := client.Channels()
for _, channel := range channels {
if channel.memberIsVisible(client) {
quitHistoryChannels = append(quitHistoryChannels, channel)
}
for _, member := range channel.auditoriumFriends(client) {
friends.Add(member)
}
Expand Down
4 changes: 3 additions & 1 deletion irc/nickname.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func performNickChange(server *Server, client *Client, target *Client, session *
}

for _, channel := range target.Channels() {
channel.AddHistoryItem(histItem, details.account)
if channel.memberIsVisible(client) {
channel.AddHistoryItem(histItem, details.account)
}
}

newCfnick := target.NickCasefolded()
Expand Down
Loading