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)
|
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.
|
// Channel config for a default public room.
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
ID string // Like "lobby"
|
ID string // Like "lobby"
|
||||||
Name string // Like "Main Chat Room"
|
Name string // Like "Main Chat Room"
|
||||||
Icon string `toml:",omitempty"` // CSS class names for room icon (optional)
|
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.
|
// ChatServer messages to send to the user immediately upon connecting.
|
||||||
WelcomeMessages []string
|
WelcomeMessages []string
|
||||||
|
@ -118,6 +129,14 @@ func DefaultConfig() Config {
|
||||||
"Welcome to the Off Topic channel!",
|
"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{
|
TURN: TurnConfig{
|
||||||
URLs: []string{
|
URLs: []string{
|
||||||
|
|
|
@ -336,6 +336,12 @@ func (s *Server) Broadcast(msg messages.Message) {
|
||||||
continue
|
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)
|
sub.SendJSON(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1575,6 +1575,9 @@ const app = Vue.createApp({
|
||||||
// List of current channels, unread indicators etc.
|
// List of current channels, unread indicators etc.
|
||||||
let result = [];
|
let result = [];
|
||||||
for (let channel of this.config.channels) {
|
for (let channel of this.config.channels) {
|
||||||
|
// VIP room we can't see?
|
||||||
|
if (channel.VIP && !this.isVIP) continue;
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
ID: channel.ID,
|
ID: channel.ID,
|
||||||
Name: channel.Name,
|
Name: channel.Name,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user