VIP-only chat channels
This commit is contained in:
parent
0174bf7bd8
commit
940f14e2d6
|
@ -68,11 +68,22 @@ func (c Config) GetChannels() template.JS {
|
|||
return template.JS(data)
|
||||
}
|
||||
|
||||
// GetChannel looks up and returns a channel by ID.
|
||||
func (c Config) GetChannel(id string) (Channel, bool) {
|
||||
for _, ch := range c.PublicChannels {
|
||||
if ch.ID == id {
|
||||
return ch, true
|
||||
}
|
||||
}
|
||||
return Channel{}, false
|
||||
}
|
||||
|
||||
// Channel config for a default public room.
|
||||
type Channel struct {
|
||||
ID string // Like "lobby"
|
||||
Name string // Like "Main Chat Room"
|
||||
Icon string `toml:",omitempty"` // CSS class names for room icon (optional)
|
||||
VIP bool // For VIP users only
|
||||
|
||||
// ChatServer messages to send to the user immediately upon connecting.
|
||||
WelcomeMessages []string
|
||||
|
@ -118,6 +129,14 @@ func DefaultConfig() Config {
|
|||
"Welcome to the Off Topic channel!",
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "vip",
|
||||
Name: "VIPs Only",
|
||||
VIP: true,
|
||||
WelcomeMessages: []string{
|
||||
"This channel is only for operators and VIPs.",
|
||||
},
|
||||
},
|
||||
},
|
||||
TURN: TurnConfig{
|
||||
URLs: []string{
|
||||
|
|
|
@ -336,6 +336,12 @@ func (s *Server) Broadcast(msg messages.Message) {
|
|||
continue
|
||||
}
|
||||
|
||||
// VIP channels: only deliver to subscribed VIP users.
|
||||
if ch, ok := config.Current.GetChannel(msg.Channel); ok && ch.VIP && !sub.IsVIP() {
|
||||
log.Debug("Do not broadcast message to %s: VIP channel and they are not VIP", sub.Username)
|
||||
continue
|
||||
}
|
||||
|
||||
sub.SendJSON(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1575,6 +1575,9 @@ const app = Vue.createApp({
|
|||
// List of current channels, unread indicators etc.
|
||||
let result = [];
|
||||
for (let channel of this.config.channels) {
|
||||
// VIP room we can't see?
|
||||
if (channel.VIP && !this.isVIP) continue;
|
||||
|
||||
let data = {
|
||||
ID: channel.ID,
|
||||
Name: channel.Name,
|
||||
|
|
Loading…
Reference in New Issue
Block a user