Commit f8ae908d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement message for locked groups.

parent e824b935
...@@ -114,7 +114,7 @@ The following commands are only available to users with operator ...@@ -114,7 +114,7 @@ The following commands are only available to users with operator
privileges: privileges:
- `/clear`: clears the chat history for all users; - `/clear`: clears the chat history for all users;
- `/lock`: prevents any new users from connecting to the group unless - `/lock message`: prevents any new users from connecting to the group unless
they have operator privileges; they have operator privileges;
- `/unlock`: reverts the effect of `/lock`; - `/unlock`: reverts the effect of `/lock`;
- `/record`: start recording; - `/record`: start recording;
......
...@@ -78,7 +78,7 @@ type Group struct { ...@@ -78,7 +78,7 @@ type Group struct {
description *groupDescription description *groupDescription
// indicates that the group no longer exists, but it still has clients // indicates that the group no longer exists, but it still has clients
dead bool dead bool
locked bool locked *string
clients map[string]Client clients map[string]Client
history []ChatHistoryEntry history []ChatHistoryEntry
} }
...@@ -87,16 +87,24 @@ func (g *Group) Name() string { ...@@ -87,16 +87,24 @@ func (g *Group) Name() string {
return g.name return g.name
} }
func (g *Group) Locked() bool { func (g *Group) Locked() (bool, string) {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
return g.locked if(g.locked != nil) {
return true, *g.locked
} else {
return false, ""
}
} }
func (g *Group) SetLocked(locked bool) { func (g *Group) SetLocked(locked bool, message string) {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
g.locked = locked if locked {
g.locked = &message
} else {
g.locked = nil
}
} }
func (g *Group) Public() bool { func (g *Group) Public() bool {
...@@ -272,8 +280,12 @@ func AddClient(name string, c Client) (*Group, error) { ...@@ -272,8 +280,12 @@ func AddClient(name string, c Client) (*Group, error) {
c.SetPermissions(perms) c.SetPermissions(perms)
if !perms.Op && g.locked { if !perms.Op && g.locked != nil {
return nil, UserError("group is locked") m := *g.locked
if m == "" {
m = "group is locked"
}
return nil, UserError(m)
} }
if !perms.Op && g.description.MaxClients > 0 { if !perms.Op && g.description.MaxClients > 0 {
......
...@@ -1008,7 +1008,7 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1008,7 +1008,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if !c.permissions.Op { if !c.permissions.Op {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
} }
c.group.SetLocked(m.Kind == "lock") c.group.SetLocked(m.Kind == "lock", m.Value)
case "record": case "record":
if !c.permissions.Record { if !c.permissions.Record {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
......
...@@ -419,11 +419,13 @@ ServerConnection.prototype.chat = function(username, kind, message) { ...@@ -419,11 +419,13 @@ ServerConnection.prototype.chat = function(username, kind, message) {
* *
* @param {string} kind - One of "clearchat", "lock", "unlock", "record or * @param {string} kind - One of "clearchat", "lock", "unlock", "record or
* "unrecord". * "unrecord".
* @param {string} [message]
*/ */
ServerConnection.prototype.groupAction = function(kind) { ServerConnection.prototype.groupAction = function(kind, message) {
this.send({ this.send({
type: 'groupaction', type: 'groupaction',
kind: kind, kind: kind,
value: message,
}); });
}; };
......
...@@ -1072,7 +1072,7 @@ function handleInput() { ...@@ -1072,7 +1072,7 @@ function handleInput() {
displayError("You're not an operator"); displayError("You're not an operator");
return; return;
} }
serverConnection.groupAction(cmd.slice(1)); serverConnection.groupAction(cmd.slice(1), rest);
return; return;
case '/record': case '/record':
case '/unrecord': case '/unrecord':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment