From f6e8048d9e2ffe1942a4c41b3ba20a2dfbcff0b0 Mon Sep 17 00:00:00 2001 From: tzyl Date: Mon, 18 Jan 2021 10:17:46 +0000 Subject: [PATCH] Expose getPresence endpoint --- spec/unit/matrix-client.spec.js | 15 +++++++++++++++ src/client.js | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index fc4a4dc56..3811c5b56 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -521,4 +521,19 @@ describe("MatrixClient", function() { xit("should be able to peek into a room using peekInRoom", function(done) { }); }); + + describe("getPresence", function() { + it("should send a presence HTTP GET", function() { + httpLookups = [{ + method: "GET", + path: `/presence/${encodeURIComponent(userId)}/status`, + data: { + "presence": "unavailable", + "last_active_ago": 420845, + }, + }]; + client.getPresence(userId); + expect(httpLookups.length).toEqual(0); + }); + }); }); diff --git a/src/client.js b/src/client.js index 5395cc14d..343b3f2b3 100644 --- a/src/client.js +++ b/src/client.js @@ -3841,6 +3841,19 @@ MatrixClient.prototype.setPresence = function(opts, callback) { ); }; +/** + * @param {string} userId The user to get presence for + * @param {module:client.callback} callback Optional. + * @return {Promise} Resolves: The presence state for this user. + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype.getPresence = function(userId, callback) { + const path = utils.encodeUri("/presence/$userId/status", { + $userId: userId, + }); + + return this._http.authedRequest(callback, "GET", path, undefined, undefined); +}; /** * Retrieve older messages from the given room and put them in the timeline.