Complete rewrite

This commit is contained in:
2025-10-01 21:24:29 -07:00
parent 5b29c26102
commit 5b0b6a48a9
18 changed files with 371 additions and 374 deletions

46
src/irc/broadcast.go Normal file
View File

@@ -0,0 +1,46 @@
package irc
import (
"git.chromaticdragon.app/pyrex/minimal-irc-server/v2/src/transport"
)
type BroadcastGroup struct {
channels []canonicalChannelName
users []*User
specificallyExcludedUsers []*User
}
func NewBroadcastGroup() *BroadcastGroup {
return &BroadcastGroup{}
}
func (bcg *BroadcastGroup) AddChannels(names ...canonicalChannelName) {
bcg.channels = append(bcg.channels, names...)
}
func (bcg *BroadcastGroup) AddUsers(users ...*User) {
bcg.users = append(bcg.users, users...)
}
func (bcg *BroadcastGroup) AddSpecificallyExcludedUsers(users ...*User) {
bcg.specificallyExcludedUsers = append(bcg.users, users...)
}
func Broadcast(bcg *BroadcastGroup, content transport.Content) {
g := GetGlobals()
allUsers := make(map[*User]struct{})
for _, c := range bcg.channels {
for u := range g.Users.ByCanonicalChannel(c) {
allUsers[u] = struct{}{}
}
}
for _, u := range bcg.users {
allUsers[u] = struct{}{}
}
for _, u := range bcg.specificallyExcludedUsers {
delete(allUsers, u)
}
for u := range allUsers {
g.Server.SendMessage(u.clientId, content)
}
}