From 9bb9d1fa1e617b7243e593930c72af37cacdb463 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 31 Jul 2021 16:59:37 +0100 Subject: [PATCH] Add nicknames + role colours back. --- src/components/common/user/UserShort.tsx | 30 +++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/components/common/user/UserShort.tsx b/src/components/common/user/UserShort.tsx index cee11ff9..3a39554d 100644 --- a/src/components/common/user/UserShort.tsx +++ b/src/components/common/user/UserShort.tsx @@ -1,8 +1,11 @@ import { observer } from "mobx-react-lite"; +import { useParams } from "react-router-dom"; import { User } from "revolt.js/dist/maps/Users"; import { Text } from "preact-i18n"; +import { useClient } from "../../../context/revoltjs/RevoltClient"; + import UserIcon from "./UserIcon"; export const Username = observer( @@ -13,30 +16,35 @@ export const Username = observer( let username = user?.username; let color; - /* // ! FIXME: this must be really bad for perf. if (user) { - let { server } = useParams<{ server?: string }>(); + const { server } = useParams<{ server?: string }>(); if (server) { - let ctx = useForceUpdate(); - let member = useMember(`${server}${user._id}`, ctx); + const client = useClient(); + const member = client.members.getKey({ + server, + user: user._id, + }); + if (member) { if (member.nickname) { username = member.nickname; } if (member.roles && member.roles.length > 0) { - let s = useServer(server, ctx); - for (let role of member.roles) { - let c = s?.roles?.[role].colour; - if (c) { - color = c; - continue; + let srv = client.servers.get(member._id.server); + if (srv?.roles) { + for (let role of member.roles) { + let c = srv.roles[role].colour; + if (c) { + color = c; + continue; + } } } } } } - } */ + } return (