From 3585ed9456095d4a2a4a4d9d79933ad0f8cf2eaf Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 19 Nov 2021 19:53:29 +0200 Subject: [PATCH] Fix avatar URLs without mxc:// looking like they work when they actually don't. Fixes #85 --- maubot/management/frontend/src/api.js | 6 +++--- maubot/management/frontend/src/pages/dashboard/Client.js | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/maubot/management/frontend/src/api.js b/maubot/management/frontend/src/api.js index 44db7c3..d6a30dd 100644 --- a/maubot/management/frontend/src/api.js +++ b/maubot/management/frontend/src/api.js @@ -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}` } diff --git a/maubot/management/frontend/src/pages/dashboard/Client.js b/maubot/management/frontend/src/pages/dashboard/Client.js index ac81114..806e112 100644 --- a/maubot/management/frontend/src/pages/dashboard/Client.js +++ b/maubot/management/frontend/src/pages/dashboard/Client.js @@ -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() {