From 0febd99fbe4f01a5fe43b0411cb54c40687657e0 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 5 Jul 2020 12:54:01 +0100 Subject: [PATCH 1/8] Add _unstable_getSharedRooms --- src/client.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/client.js b/src/client.js index 7efa758e9..4f1eb960b 100644 --- a/src/client.js +++ b/src/client.js @@ -4843,6 +4843,23 @@ MatrixClient.prototype._storeClientOptions = function() { return this.store.storeClientOptions(serializableOpts); }; +/** + * Gets a set of room IDs in common with another user + * @param {string} userId The userId to check. + * @return {Promise} Resolves to a set of rooms + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixClient.prototype._unstable_getSharedRooms = function(userId) { + const path = utils.encodeUri("/user/$userId/shared_rooms/$otherUserId", { + $userId: this.credentials.userId, + $otherUserId: userId, + }); + return this._http.authedRequest( + undefined, "GET", path, undefined, undefined, + {prefix: PREFIX_UNSTABLE}, + ); +}; + /** * High level helper method to stop the client from polling and allow a * clean shutdown. From e69e6e198122214117b07138f6b19844c207636c Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 5 Jul 2020 13:47:32 +0100 Subject: [PATCH 2/8] Update _unstable_getSharedRooms response format --- src/client.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 4f1eb960b..3a00d1493 100644 --- a/src/client.js +++ b/src/client.js @@ -4849,15 +4849,16 @@ MatrixClient.prototype._storeClientOptions = function() { * @return {Promise} Resolves to a set of rooms * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype._unstable_getSharedRooms = function(userId) { +MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { const path = utils.encodeUri("/user/$userId/shared_rooms/$otherUserId", { $userId: this.credentials.userId, $otherUserId: userId, }); - return this._http.authedRequest( + const res = await this._http.authedRequest( undefined, "GET", path, undefined, undefined, {prefix: PREFIX_UNSTABLE}, ); + return res.rooms; }; /** From cf0a5305e043829900a0ab3385c78ca6a0b4fe43 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 5 Jul 2020 14:09:18 +0100 Subject: [PATCH 3/8] Throw if server does not support getSharedRooms --- src/client.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client.js b/src/client.js index 3a00d1493..098478a5c 100644 --- a/src/client.js +++ b/src/client.js @@ -4850,6 +4850,9 @@ MatrixClient.prototype._storeClientOptions = function() { * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { + if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2664"))) { + throw Error('Server does not support shared_rooms API'); + } const path = utils.encodeUri("/user/$userId/shared_rooms/$otherUserId", { $userId: this.credentials.userId, $otherUserId: userId, From 4577dc8f445940f891c2be01417b0a5c34261d0d Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Sun, 5 Jul 2020 15:02:51 +0100 Subject: [PATCH 4/8] s/msc2644/msc2666/ --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 098478a5c..779f611ad 100644 --- a/src/client.js +++ b/src/client.js @@ -4850,7 +4850,7 @@ MatrixClient.prototype._storeClientOptions = function() { * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { - if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2664"))) { + if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2666"))) { throw Error('Server does not support shared_rooms API'); } const path = utils.encodeUri("/user/$userId/shared_rooms/$otherUserId", { From 80fe66c481a4e66f06ab6b6eabeed23978a6e869 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 10 Jul 2020 12:01:23 +0100 Subject: [PATCH 5/8] Add /uk.half-shot.msc2666/ prefix --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 779f611ad..b90c29c6b 100644 --- a/src/client.js +++ b/src/client.js @@ -4853,7 +4853,7 @@ MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2666"))) { throw Error('Server does not support shared_rooms API'); } - const path = utils.encodeUri("/user/$userId/shared_rooms/$otherUserId", { + const path = utils.encodeUri("/uk.half-shot.msc2666/user/$userId/shared_rooms/$otherUserId", { $userId: this.credentials.userId, $otherUserId: userId, }); From a919c798f8c904202b3a5c6efe97a2995a926f31 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 31 Jul 2020 14:46:26 +0100 Subject: [PATCH 6/8] Update _unstable_getSharedRooms to match spec --- src/client.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index b90c29c6b..40435f059 100644 --- a/src/client.js +++ b/src/client.js @@ -4849,19 +4849,18 @@ MatrixClient.prototype._storeClientOptions = function() { * @return {Promise} Resolves to a set of rooms * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { +MatrixClient.prototype._unstable_getSharedRooms = async function() { if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2666"))) { throw Error('Server does not support shared_rooms API'); } - const path = utils.encodeUri("/uk.half-shot.msc2666/user/$userId/shared_rooms/$otherUserId", { + const path = utils.encodeUri("/uk.half-shot.msc2666/user/shared_rooms/userId", { $userId: this.credentials.userId, - $otherUserId: userId, }); const res = await this._http.authedRequest( undefined, "GET", path, undefined, undefined, {prefix: PREFIX_UNSTABLE}, ); - return res.rooms; + return res.joined; }; /** From 1a1fe759c312b656c7467be1080e09cd66da50a7 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2020 18:41:45 +0100 Subject: [PATCH 7/8] fix encoding bug --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index 40435f059..a747860ea 100644 --- a/src/client.js +++ b/src/client.js @@ -4853,7 +4853,7 @@ MatrixClient.prototype._unstable_getSharedRooms = async function() { if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2666"))) { throw Error('Server does not support shared_rooms API'); } - const path = utils.encodeUri("/uk.half-shot.msc2666/user/shared_rooms/userId", { + const path = utils.encodeUri("/uk.half-shot.msc2666/user/shared_rooms/$userId", { $userId: this.credentials.userId, }); const res = await this._http.authedRequest( From 6ec7e3a0b7fb97463b07a18a67954bff64317010 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2020 18:42:55 +0100 Subject: [PATCH 8/8] UserId must be sane --- src/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index a747860ea..2b1210fd4 100644 --- a/src/client.js +++ b/src/client.js @@ -4849,12 +4849,12 @@ MatrixClient.prototype._storeClientOptions = function() { * @return {Promise} Resolves to a set of rooms * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype._unstable_getSharedRooms = async function() { +MatrixClient.prototype._unstable_getSharedRooms = async function(userId) { if (!(await this.doesServerSupportUnstableFeature("uk.half-shot.msc2666"))) { throw Error('Server does not support shared_rooms API'); } const path = utils.encodeUri("/uk.half-shot.msc2666/user/shared_rooms/$userId", { - $userId: this.credentials.userId, + $userId: userId, }); const res = await this._http.authedRequest( undefined, "GET", path, undefined, undefined,