Fix room avatars
This commit is contained in:
parent
b6f7f75fdd
commit
8e7e6cf3f7
3 changed files with 39 additions and 31 deletions
|
|
@ -15,30 +15,16 @@ export default {
|
|||
},
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (this.src) {
|
||||
console.error("GOT URL", this.src);
|
||||
if (this.$matrix.useAuthedMedia) {
|
||||
axios
|
||||
.get(this.src, { responseType: "blob", headers: {
|
||||
Authorization: `Bearer ${this.$matrix.matrixClient.getAccessToken()}`,
|
||||
}})
|
||||
.then((response) => {
|
||||
this.imageSrc = URL.createObjectURL(response.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Download error: ", err);
|
||||
});
|
||||
} else {
|
||||
this.imageSrc = this.src;
|
||||
}
|
||||
}
|
||||
},
|
||||
destroyed() {
|
||||
if (this.imageSrc && this.src != this.imageSrc) {
|
||||
const url = this.imageSrc;
|
||||
this.imageSrc = null;
|
||||
URL.revokeObjectURL(url);
|
||||
this.unloadSrc();
|
||||
},
|
||||
watch: {
|
||||
src: {
|
||||
immediate: true,
|
||||
handler(newValue) {
|
||||
this.unloadSrc();
|
||||
this.loadSrc();
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
|
@ -47,6 +33,33 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
loadSrc() {
|
||||
if (this.src) {
|
||||
if (this.$matrix.useAuthedMedia) {
|
||||
axios
|
||||
.get(this.src, {
|
||||
responseType: "blob", headers: {
|
||||
Authorization: `Bearer ${this.$matrix.matrixClient.getAccessToken()}`,
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
this.imageSrc = URL.createObjectURL(response.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Download error: ", err);
|
||||
});
|
||||
} else {
|
||||
this.imageSrc = this.src;
|
||||
}
|
||||
}
|
||||
},
|
||||
unloadSrc() {
|
||||
if (this.imageSrc && this.src != this.imageSrc) {
|
||||
const url = this.imageSrc;
|
||||
this.imageSrc = null;
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -58,10 +58,7 @@ export default {
|
|||
self.isRoomAvatarLoaded = true;
|
||||
}
|
||||
}
|
||||
).then((url) => {
|
||||
console.error("UPDATE AVATAR", url);
|
||||
this.room.avatar = url;
|
||||
})
|
||||
)
|
||||
},
|
||||
handleRoomPickedAvatar(event) {
|
||||
if (event.target.files && event.target.files[0]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue