Commit 710cc3cc authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add ability to set initial user status.

Setting the status after joining (using the "setstatus" action)
may cause multiple "user" messages to be sent to clients.  Add
the ability to set the initial status at join time.
parent 0b5e40bc
...@@ -107,7 +107,8 @@ The `join` message requests that the sender join or leave a group: ...@@ -107,7 +107,8 @@ The `join` message requests that the sender join or leave a group:
kind: 'join' or 'leave', kind: 'join' or 'leave',
group: group, group: group,
username: username, username: username,
password: password password: password,
status: status
} }
``` ```
......
...@@ -1316,9 +1316,20 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1316,9 +1316,20 @@ func handleClientMessage(c *webClient, m clientMessage) error {
} }
if c.group != nil { if c.group != nil {
return group.ProtocolError("cannot join multiple groups") return group.ProtocolError(
"cannot join multiple groups",
)
} }
c.username = m.Username c.username = m.Username
if m.Status != nil {
s, ok := m.Status.(map[string]interface{})
if !ok {
return group.ProtocolError(
"bad type for status",
)
}
c.status = s
}
g, err := group.AddClient(m.Group, c, g, err := group.AddClient(m.Group, c,
group.ClientCredentials{ group.ClientCredentials{
Username: m.Username, Username: m.Username,
......
...@@ -416,15 +416,19 @@ ServerConnection.prototype.connect = async function(url) { ...@@ -416,15 +416,19 @@ ServerConnection.prototype.connect = async function(url) {
* @param {string} group - The name of the group to join. * @param {string} group - The name of the group to join.
* @param {string} username - the username to join as. * @param {string} username - the username to join as.
* @param {string} password - the password. * @param {string} password - the password.
* @param {Object<string,any>} [status] - the initial status of the user.
*/ */
ServerConnection.prototype.join = function(group, username, password) { ServerConnection.prototype.join = function(group, username, password, status) {
this.send({ let m = {
type: 'join', type: 'join',
kind: 'join', kind: 'join',
group: group, group: group,
username: username, username: username,
password: password, password: password,
}); };
if(status)
m.status = status;
this.send(m);
}; };
/** /**
......
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