1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

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.
This commit is contained in:
Juliusz Chroboczek 2022-01-25 18:16:42 +01:00
parent 0b5e40bc7f
commit 710cc3cc14
3 changed files with 21 additions and 5 deletions

View file

@ -107,7 +107,8 @@ The `join` message requests that the sender join or leave a group:
kind: 'join' or 'leave',
group: group,
username: username,
password: password
password: password,
status: status
}
```

View file

@ -1316,9 +1316,20 @@ func handleClientMessage(c *webClient, m clientMessage) error {
}
if c.group != nil {
return group.ProtocolError("cannot join multiple groups")
return group.ProtocolError(
"cannot join multiple groups",
)
}
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,
group.ClientCredentials{
Username: m.Username,

View file

@ -416,15 +416,19 @@ ServerConnection.prototype.connect = async function(url) {
* @param {string} group - The name of the group to join.
* @param {string} username - the username to join as.
* @param {string} password - the password.
* @param {Object<string,any>} [status] - the initial status of the user.
*/
ServerConnection.prototype.join = function(group, username, password) {
this.send({
ServerConnection.prototype.join = function(group, username, password, status) {
let m = {
type: 'join',
kind: 'join',
group: group,
username: username,
password: password,
});
};
if(status)
m.status = status;
this.send(m);
};
/**