1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Merge pull request #167 from Half-Shot/presence_status

Added ability to set and get status_msg for presence.
This commit is contained in:
David Baker
2016-08-18 11:18:03 +01:00
committed by GitHub
2 changed files with 18 additions and 9 deletions

View File

@@ -1413,25 +1413,29 @@ MatrixClient.prototype.mxcUrlToHttp =
}; };
/** /**
* @param {string} presence * @param {Object} opts Options to apply
* @param {string} opts.presence One of "online", "offline" or "unavailable"
* @param {string} opts.status_msg The status message to attach.
* @param {module:client.callback} callback Optional. * @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO * @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
* @throws If 'presence' isn't a valid presence enum value. * @throws If 'presence' isn't a valid presence enum value.
*/ */
MatrixClient.prototype.setPresence = function(presence, callback) { MatrixClient.prototype.setPresence = function(opts, callback) {
var path = utils.encodeUri("/presence/$userId/status", { var path = utils.encodeUri("/presence/$userId/status", {
$userId: this.credentials.userId $userId: this.credentials.userId
}); });
var validStates = ["offline", "online", "unavailable"];
if (validStates.indexOf(presence) == -1) { if (typeof opts === "string") {
throw new Error("Bad presence value: " + presence); opts = { presence: opts }
}
var validStates = ["offline", "online", "unavailable"];
if (validStates.indexOf(opts.presence) == -1) {
throw new Error("Bad presence value: " + opts.presence);
} }
var content = {
presence: presence
};
return this._http.authedRequest( return this._http.authedRequest(
callback, "PUT", path, undefined, content callback, "PUT", path, undefined, opts
); );
}; };

View File

@@ -30,6 +30,7 @@ limitations under the License.
* @prop {string} displayName The 'displayname' of the user if known. * @prop {string} displayName The 'displayname' of the user if known.
* @prop {string} avatarUrl The 'avatar_url' of the user if known. * @prop {string} avatarUrl The 'avatar_url' of the user if known.
* @prop {string} presence The presence enum if known. * @prop {string} presence The presence enum if known.
* @prop {string} presenceStatusMsg The presence status message if known.
* @prop {Number} lastActiveAgo The time elapsed in ms since the user interacted * @prop {Number} lastActiveAgo The time elapsed in ms since the user interacted
* proactively with the server, or we saw a message from the user * proactively with the server, or we saw a message from the user
* @prop {Number} lastPresenceTs Timestamp (ms since the epoch) for when we last * @prop {Number} lastPresenceTs Timestamp (ms since the epoch) for when we last
@@ -44,6 +45,7 @@ limitations under the License.
function User(userId) { function User(userId) {
this.userId = userId; this.userId = userId;
this.presence = "offline"; this.presence = "offline";
this.presenceStatusMsg = null;
this.displayName = userId; this.displayName = userId;
this.avatarUrl = null; this.avatarUrl = null;
this.lastActiveAgo = 0; this.lastActiveAgo = 0;
@@ -96,6 +98,9 @@ User.prototype.setPresenceEvent = function(event) {
this.presence = event.getContent().presence; this.presence = event.getContent().presence;
eventsToFire.push("User.lastPresenceTs"); eventsToFire.push("User.lastPresenceTs");
if (event.getContent().status_msg) {
this.presenceStatusMsg = event.getContent().status_msg;
}
if (event.getContent().displayname) { if (event.getContent().displayname) {
this.displayName = event.getContent().displayname; this.displayName = event.getContent().displayname;
} }