Fix avatar URLs without mxc:// looking like they work when they actually don't. Fixes #85

This commit is contained in:
Tulir Asokan 2021-11-19 19:53:29 +02:00
parent ae7e9693fc
commit 3585ed9456
2 changed files with 9 additions and 5 deletions

View File

@ -214,10 +214,10 @@ export async function uploadAvatar(id, data, mime) {
}
export function getAvatarURL({ id, avatar_url }) {
avatar_url = avatar_url || ""
if (avatar_url.startsWith("mxc://")) {
avatar_url = avatar_url.substr("mxc://".length)
if (!avatar_url?.startsWith("mxc://")) {
return null
}
avatar_url = avatar_url.substr("mxc://".length)
return `${BASE_PATH}/proxy/${id}/_matrix/media/r0/download/${avatar_url}?access_token=${
localStorage.accessToken}`
}

View File

@ -215,8 +215,12 @@ class Client extends BaseMainView {
}
get avatarMXC() {
return this.state.avatar_url === "disable"
? this.props.entry.remote_avatar_url : this.state.avatar_url
if (this.state.avatar_url === "disable") {
return this.props.entry.remote_avatar_url
} else if (!this.state.avatar_url?.startsWith("mxc://")) {
return null
}
return this.state.avatar_url
}
get avatarURL() {