From 2fb883a4d17a1498bf4e01192d7f538e5116f037 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Tue, 13 Apr 2021 19:57:26 +0200 Subject: [PATCH] Set avatar and displayname on join Also on the main matrix object. --- src/components/Join.vue | 9 +++++++-- src/plugins/utils.js | 10 ++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/Join.vue b/src/components/Join.vue index ec3eb00..1893e02 100644 --- a/src/components/Join.vue +++ b/src/components/Join.vue @@ -327,9 +327,14 @@ export default { // Set avatar and display name to either the randomly chosen ones, or the // ones the users has changed to. setProfileData = true; + + // Set display name and avatar directly on the matrix object. + if (this.selectedProfile.name && this.selectedProfile.name.length > 0) { + this.$matrix.userDisplayName = this.selectedProfile.name; + } } - if (!setProfileData || !this.selectedProfile.name) { + if (!setProfileData || !this.selectedProfile.name || this.selectedProfile.name.length == 0) { return Promise.resolve(user); } else { console.log("Join: Set display name to: " + this.selectedProfile.name); @@ -348,7 +353,7 @@ export default { } else { console.log("Join: Updating avatar"); return util.setAvatar( - this.$matrix.matrixClient, + this.$matrix, this.selectedProfile.image, function (progress) { console.log("Progress: " + JSON.stringify(progress)); diff --git a/src/plugins/utils.js b/src/plugins/utils.js index b27463b..91d07f3 100644 --- a/src/plugins/utils.js +++ b/src/plugins/utils.js @@ -461,7 +461,7 @@ class Util { return this._importAll(require.context('../assets/avatars/', true, /\.(jpeg|jpg|png)$/)); } - setAvatar(matrixClient, file, onUploadProgress) { + setAvatar(matrix, file, onUploadProgress) { return new Promise((resolve, reject) => { axios.get(file, { responseType: 'arraybuffer' }) .then(response => { @@ -471,12 +471,14 @@ class Util { progressHandler: onUploadProgress, onlyContentUri: false }; - matrixClient.uploadContent(response.data, opts) + var avatarUri; + matrix.matrixClient.uploadContent(response.data, opts) .then((response) => { - const uri = response.content_uri; - return matrixClient.setAvatarUrl(uri); + avatarUri = response.content_uri; + return matrix.matrixClient.setAvatarUrl(avatarUri); }) .then(result => { + matrix.userAvatar = avatarUri; resolve(result); }) .catch(err => {