Set avatar and displayname on join
Also on the main matrix object.
This commit is contained in:
parent
ae2c8d8e2e
commit
2fb883a4d1
2 changed files with 13 additions and 6 deletions
|
|
@ -327,9 +327,14 @@ export default {
|
||||||
// Set avatar and display name to either the randomly chosen ones, or the
|
// Set avatar and display name to either the randomly chosen ones, or the
|
||||||
// ones the users has changed to.
|
// ones the users has changed to.
|
||||||
setProfileData = true;
|
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);
|
return Promise.resolve(user);
|
||||||
} else {
|
} else {
|
||||||
console.log("Join: Set display name to: " + this.selectedProfile.name);
|
console.log("Join: Set display name to: " + this.selectedProfile.name);
|
||||||
|
|
@ -348,7 +353,7 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
console.log("Join: Updating avatar");
|
console.log("Join: Updating avatar");
|
||||||
return util.setAvatar(
|
return util.setAvatar(
|
||||||
this.$matrix.matrixClient,
|
this.$matrix,
|
||||||
this.selectedProfile.image,
|
this.selectedProfile.image,
|
||||||
function (progress) {
|
function (progress) {
|
||||||
console.log("Progress: " + JSON.stringify(progress));
|
console.log("Progress: " + JSON.stringify(progress));
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ class Util {
|
||||||
return this._importAll(require.context('../assets/avatars/', true, /\.(jpeg|jpg|png)$/));
|
return this._importAll(require.context('../assets/avatars/', true, /\.(jpeg|jpg|png)$/));
|
||||||
}
|
}
|
||||||
|
|
||||||
setAvatar(matrixClient, file, onUploadProgress) {
|
setAvatar(matrix, file, onUploadProgress) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.get(file, { responseType: 'arraybuffer' })
|
axios.get(file, { responseType: 'arraybuffer' })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
@ -471,12 +471,14 @@ class Util {
|
||||||
progressHandler: onUploadProgress,
|
progressHandler: onUploadProgress,
|
||||||
onlyContentUri: false
|
onlyContentUri: false
|
||||||
};
|
};
|
||||||
matrixClient.uploadContent(response.data, opts)
|
var avatarUri;
|
||||||
|
matrix.matrixClient.uploadContent(response.data, opts)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const uri = response.content_uri;
|
avatarUri = response.content_uri;
|
||||||
return matrixClient.setAvatarUrl(uri);
|
return matrix.matrixClient.setAvatarUrl(avatarUri);
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
matrix.userAvatar = avatarUri;
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue