Make sure to set avatar and display name on first join

If you left these at the default random ones, they were not set.
This commit is contained in:
N-Pex 2021-04-13 19:17:07 +02:00
parent 413941523e
commit 2e07068cd7

View file

@ -25,7 +25,7 @@
<v-row v-if="canEditProfile"> <v-row v-if="canEditProfile">
<v-col class="flex-grow-0 flex-shrink-0"> <v-col class="flex-grow-0 flex-shrink-0">
<v-avatar @click="showAvatarPickerList"> <v-avatar @click="showAvatarPickerList">
<v-img v-if="profile" :src="profile.image" /> <v-img v-if="selectedProfile" :src="selectedProfile.image" />
</v-avatar> </v-avatar>
</v-col> </v-col>
<v-col class="flex-shrink-1 flex-grow-1"> <v-col class="flex-shrink-1 flex-grow-1">
@ -50,7 +50,7 @@
{ {
} }
" "
v-model="profile.name" v-model="selectedProfile.name"
></v-text-field> ></v-text-field>
</template> </template>
<template v-slot:item="data"> <template v-slot:item="data">
@ -134,16 +134,15 @@ export default {
waitingForInfo: true, waitingForInfo: true,
waitingForMembership: false, waitingForMembership: false,
availableAvatars: [], availableAvatars: [],
randomProfile: null,
selectedProfile: null, selectedProfile: null,
}; };
}, },
mounted() { mounted() {
this.$matrix.on("Room.myMembership", this.onMyMembership); this.$matrix.on("Room.myMembership", this.onMyMembership);
this.availableAvatars = util.getDefaultAvatars(); this.availableAvatars = util.getDefaultAvatars();
this.randomProfile = this.availableAvatars[ this.selectAvatar(this.availableAvatars[
Math.floor(Math.random() * this.availableAvatars.length) Math.floor(Math.random() * this.availableAvatars.length)
]; ]);
}, },
destroyed() { destroyed() {
this.$matrix.off("Room.myMembership", this.onMyMembership); this.$matrix.off("Room.myMembership", this.onMyMembership);
@ -168,19 +167,6 @@ export default {
return this.$matrix.currentRoomId; return this.$matrix.currentRoomId;
}, },
profile() {
return {
image:
(this.selectedProfile ? this.selectedProfile.image : null) ||
this.userAvatar ||
this.randomProfile.image,
name:
(this.selectedProfile ? this.selectedProfile.name : null) ||
this.userDisplayName ||
this.randomProfile.name,
};
},
canEditProfile() { canEditProfile() {
// If we have an account already, we can't edit profile here (need to go into profile view) // If we have an account already, we can't edit profile here (need to go into profile view)
if (this.currentUser) { if (this.currentUser) {
@ -189,14 +175,6 @@ export default {
return true; return true;
}, },
hasChangedAvatar() {
return this.userAvatar != this.profile.image;
},
hasChangedDisplayName() {
return this.userDisplayName != this.profile.name;
},
userDisplayName() { userDisplayName() {
return this.$matrix.currentUserDisplayName; return this.$matrix.currentUserDisplayName;
}, },
@ -339,16 +317,24 @@ export default {
handleJoin() { handleJoin() {
this.loading = true; this.loading = true;
this.loadingMessage = "Logging in..."; this.loadingMessage = "Logging in...";
const hasUser = this.currentUser ? true : false;
var setProfileData = false;
return this.getLoginPromise() return this.getLoginPromise()
.then( .then(
function (user) { function (user) {
if (!this.hasChangedDisplayName) { if (user.is_guest && !hasUser) {
console.log("Join: No display name change"); // Newly created account, joining first room.
// Set avatar and display name to either the randomly chosen ones, or the
// ones the users has changed to.
setProfileData = true;
}
if (!setProfileData || !this.selectedProfile.name) {
return Promise.resolve(user); return Promise.resolve(user);
} else { } else {
console.log("Join: Set display name to: " + this.profile.name); console.log("Join: Set display name to: " + this.selectedProfile.name);
return this.$matrix.matrixClient.setDisplayName( return this.$matrix.matrixClient.setDisplayName(
this.profile.name, this.selectedProfile.name,
undefined undefined
); );
} }
@ -356,14 +342,14 @@ export default {
) )
.then( .then(
function () { function () {
if (!this.hasChangedAvatar) { if (!setProfileData || !this.selectedProfile.image) {
console.log("Join: No avatar change"); console.log("Join: No avatar change");
return Promise.resolve("no avatar"); return Promise.resolve("no avatar");
} else { } else {
console.log("Join: Updating avatar"); console.log("Join: Updating avatar");
return util.setAvatar( return util.setAvatar(
this.$matrix.matrixClient, this.$matrix.matrixClient,
this.profile.image, this.selectedProfile.image,
function (progress) { function (progress) {
console.log("Progress: " + JSON.stringify(progress)); console.log("Progress: " + JSON.stringify(progress));
} }