From c9c8ac08a193037e103a496244f1ec49ea4a6a27 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 31 Aug 2019 12:32:25 +0300 Subject: [PATCH] Show avatar and name from server if profile overwriting is disabled --- maubot/client.py | 14 +++++++++++ .../frontend/src/pages/dashboard/Client.js | 24 ++++++++++++++++--- .../frontend/src/pages/dashboard/Instance.js | 2 +- .../frontend/src/pages/dashboard/Plugin.js | 2 +- maubot/management/frontend/src/res/bot.svg | 5 ++++ .../frontend/src/style/pages/sidebar.sass | 6 ++--- 6 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 maubot/management/frontend/src/res/bot.svg diff --git a/maubot/client.py b/maubot/client.py index 3662dae..6014e0a 100644 --- a/maubot/client.py +++ b/maubot/client.py @@ -46,6 +46,9 @@ class Client: client: MaubotMatrixClient started: bool + remote_displayname: str + remote_avatar_url: ContentURI + def __init__(self, db_instance: DBClient) -> None: self.db_instance = db_instance self.cache[self.id] = self @@ -116,6 +119,7 @@ class Client: if self.avatar_url != "disable": await self.client.set_avatar_url(self.avatar_url) self.start_sync() + await self._update_remote_profile() self.started = True self.log.info("Client started, starting plugin instances...") await self.start_plugins() @@ -167,6 +171,8 @@ class Client: "autojoin": self.autojoin, "displayname": self.displayname, "avatar_url": self.avatar_url, + "remote_displayname": self.remote_displayname, + "remote_avatar_url": self.remote_avatar_url, "instances": [instance.to_dict() for instance in self.references], } @@ -202,6 +208,8 @@ class Client: self.db_instance.displayname = displayname if self.displayname != "disable": await self.client.set_displayname(self.displayname) + else: + await self._update_remote_profile() async def update_avatar_url(self, avatar_url: ContentURI) -> None: if avatar_url is None or avatar_url == self.avatar_url: @@ -209,6 +217,8 @@ class Client: self.db_instance.avatar_url = avatar_url if self.avatar_url != "disable": await self.client.set_avatar_url(self.avatar_url) + else: + await self._update_remote_profile() async def update_access_details(self, access_token: str, homeserver: str) -> None: if not access_token and not homeserver: @@ -228,6 +238,10 @@ class Client: self.db_instance.access_token = access_token self.start_sync() + async def _update_remote_profile(self) -> None: + profile = await self.client.get_profile(self.id) + self.remote_displayname, self.remote_avatar_url = profile.displayname, profile.avatar_url + # region Properties @property diff --git a/maubot/management/frontend/src/pages/dashboard/Client.js b/maubot/management/frontend/src/pages/dashboard/Client.js index 8d9d9b2..a572591 100644 --- a/maubot/management/frontend/src/pages/dashboard/Client.js +++ b/maubot/management/frontend/src/pages/dashboard/Client.js @@ -17,6 +17,7 @@ import React from "react" import { NavLink, withRouter } from "react-router-dom" import { ReactComponent as ChevronRight } from "../../res/chevron-right.svg" import { ReactComponent as UploadButton } from "../../res/upload.svg" +import { ReactComponent as NoAvatarIcon } from "../../res/bot.svg" import { PrefTable, PrefSwitch, PrefInput, PrefSelect } from "../../components/PreferenceTable" import Spinner from "../../components/Spinner" import api from "../../api" @@ -29,11 +30,19 @@ const ClientListEntry = ({ entry }) => { } else if (!entry.started) { classes.push("stopped") } + const avatarURL = entry.avatar_url && api.getAvatarURL({ + id: entry.id, + avatar_url: entry.avatar_url === "disabled" + ? entry.remote_avatar_url + : entry.avatar_url + }) return ( - + {avatarURL + ? + : } {entry.displayname || entry.id} - + ) } @@ -194,11 +203,20 @@ class Client extends BaseMainView { } + get avatarURL() { + return api.getAvatarURL({ + id: this.state.id, + avatar_url: this.state.avatar_url === "disabled" + ? this.props.entry.remote_avatar_url + : this.state.avatar_url + }) + } + renderSidebar = () => !this.isNew && (
- Avatar + Avatar ( {entry.id} - + ) diff --git a/maubot/management/frontend/src/pages/dashboard/Plugin.js b/maubot/management/frontend/src/pages/dashboard/Plugin.js index 9fcb947..f41140b 100644 --- a/maubot/management/frontend/src/pages/dashboard/Plugin.js +++ b/maubot/management/frontend/src/pages/dashboard/Plugin.js @@ -25,7 +25,7 @@ import BaseMainView from "./BaseMainView" const PluginListEntry = ({ entry }) => ( {entry.id} - + ) diff --git a/maubot/management/frontend/src/res/bot.svg b/maubot/management/frontend/src/res/bot.svg new file mode 100644 index 0000000..3c690fb --- /dev/null +++ b/maubot/management/frontend/src/res/bot.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/maubot/management/frontend/src/style/pages/sidebar.sass b/maubot/management/frontend/src/style/pages/sidebar.sass index 75ddcd6..8e76da2 100644 --- a/maubot/management/frontend/src/style/pages/sidebar.sass +++ b/maubot/management/frontend/src/style/pages/sidebar.sass @@ -53,10 +53,10 @@ height: 2rem box-sizing: border-box - &:not(:hover) > svg + &:not(:hover) > svg.chevron display: none - > svg + > svg.chevron float: right &:hover @@ -67,7 +67,7 @@ color: white &.client - img.avatar + img.avatar, svg.avatar max-height: 1.5rem border-radius: 100% vertical-align: middle