From 5bbc5cad9f26df1de735cdffad69e8db973e40eb Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Nov 2020 17:20:03 +0000 Subject: [PATCH 1/4] Client setProfile methods update own user --- src/client.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index 3f2ac2c66..28f936a1e 100644 --- a/src/client.js +++ b/src/client.js @@ -3702,10 +3702,16 @@ MatrixClient.prototype.setProfileInfo = function(info, data, callback) { * @return {Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.setDisplayName = function(name, callback) { - return this.setProfileInfo( +MatrixClient.prototype.setDisplayName = async function(name, callback) { + const prom = await this.setProfileInfo( "displayname", { displayname: name }, callback, ); + const user = this.getUser(this.getUserId()); + if (user) { + user.displayName = name; + user.emit("User.displayName"); + } + return prom; }; /** @@ -3714,10 +3720,16 @@ MatrixClient.prototype.setDisplayName = function(name, callback) { * @return {Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. */ -MatrixClient.prototype.setAvatarUrl = function(url, callback) { - return this.setProfileInfo( +MatrixClient.prototype.setAvatarUrl = async function(url, callback) { + const prom = await this.setProfileInfo( "avatar_url", { avatar_url: url }, callback, ); + const user = this.getUser(this.getUserId()); + if (user) { + user.avatarUrl = url; + user.emit("User.avatarUrl"); + } + return prom; }; /** From 7de0ca2048238e7004edc7ba21e40cb9580fde50 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Nov 2020 17:29:14 +0000 Subject: [PATCH 2/4] pass args --- src/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 28f936a1e..197ddb1e6 100644 --- a/src/client.js +++ b/src/client.js @@ -3709,7 +3709,7 @@ MatrixClient.prototype.setDisplayName = async function(name, callback) { const user = this.getUser(this.getUserId()); if (user) { user.displayName = name; - user.emit("User.displayName"); + user.emit("User.displayName", null, user); } return prom; }; @@ -3727,7 +3727,7 @@ MatrixClient.prototype.setAvatarUrl = async function(url, callback) { const user = this.getUser(this.getUserId()); if (user) { user.avatarUrl = url; - user.emit("User.avatarUrl"); + user.emit("User.avatarUrl", null, user); } return prom; }; From 66aa9c4831adb653635685c238075458309d2ee3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Nov 2020 17:39:25 +0000 Subject: [PATCH 3/4] pass a presence event --- src/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 197ddb1e6..5c72be517 100644 --- a/src/client.js +++ b/src/client.js @@ -3709,7 +3709,7 @@ MatrixClient.prototype.setDisplayName = async function(name, callback) { const user = this.getUser(this.getUserId()); if (user) { user.displayName = name; - user.emit("User.displayName", null, user); + user.emit("User.displayName", user.events.presence, user); } return prom; }; @@ -3727,7 +3727,7 @@ MatrixClient.prototype.setAvatarUrl = async function(url, callback) { const user = this.getUser(this.getUserId()); if (user) { user.avatarUrl = url; - user.emit("User.avatarUrl", null, user); + user.emit("User.avatarUrl", user.events.presence, user); } return prom; }; From 645842f0fd0480abb7db25779c1b0da2a3d525d6 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 2 Nov 2020 18:09:32 +0000 Subject: [PATCH 4/4] Update comments --- src/client.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 5c72be517..561f787e2 100644 --- a/src/client.js +++ b/src/client.js @@ -3699,13 +3699,14 @@ MatrixClient.prototype.setProfileInfo = function(info, data, callback) { /** * @param {string} name * @param {module:client.callback} callback Optional. - * @return {Promise} Resolves: TODO + * @return {Promise} Resolves: {} an empty object. * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype.setDisplayName = async function(name, callback) { const prom = await this.setProfileInfo( "displayname", { displayname: name }, callback, ); + // XXX: synthesise a profile update for ourselves because Synapse is broken and won't const user = this.getUser(this.getUserId()); if (user) { user.displayName = name; @@ -3717,13 +3718,14 @@ MatrixClient.prototype.setDisplayName = async function(name, callback) { /** * @param {string} url * @param {module:client.callback} callback Optional. - * @return {Promise} Resolves: TODO + * @return {Promise} Resolves: {} an empty object. * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype.setAvatarUrl = async function(url, callback) { const prom = await this.setProfileInfo( "avatar_url", { avatar_url: url }, callback, ); + // XXX: synthesise a profile update for ourselves because Synapse is broken and won't const user = this.getUser(this.getUserId()); if (user) { user.avatarUrl = url;