From 852b1f277ecdeda8ba934eafc6dbda9907568840 Mon Sep 17 00:00:00 2001 From: "Lucian I. Last" Date: Mon, 13 May 2024 11:53:15 +0200 Subject: [PATCH] Show responders name --- app/src/components/Chat/ChatPost.tsx | 62 +++++++++++++++++++------- app/src/components/Chat/ChatWindow.tsx | 54 ++++++++++++---------- 2 files changed, 76 insertions(+), 40 deletions(-) diff --git a/app/src/components/Chat/ChatPost.tsx b/app/src/components/Chat/ChatPost.tsx index 129cce15d..e09870545 100644 --- a/app/src/components/Chat/ChatPost.tsx +++ b/app/src/components/Chat/ChatPost.tsx @@ -1,28 +1,56 @@ import { IonItem } from "@ionic/react"; import { Post } from "@mattermost/types/posts"; +import { User } from "../../api/types"; +import { useMemo } from "react"; interface Props { post: Post; isMe: boolean; + users: User[]; + prevPost: Post | null; } -export default function ChatPost({ post, isMe }: Props) { +export default function ChatPost({ post, isMe, users, prevPost }: Props) { + const { username, message } = useMemo(() => { + let username = post.props.username; + let message = post.message; + for (let user of users) { + if (user.uid === post.props.username) { + username = user.name; + } + message = message.replaceAll(user.uid, user.name); + } + return { username, message }; + }, [users, post]); + + const isSameUserAsPrev = post.user_id === prevPost?.user_id; + return ( - -
-
{post.props.username}
-
{post.message}
-
-
+ <> + {!isSameUserAsPrev ? ( +
+ {username} +
+ ) : null} + {post.type != "" ? ( +
+
+ {message} +
+
+ ) : ( +
+
+ {message} +
+
+ )} + ); } diff --git a/app/src/components/Chat/ChatWindow.tsx b/app/src/components/Chat/ChatWindow.tsx index 976a56c6e..176c071f2 100644 --- a/app/src/components/Chat/ChatWindow.tsx +++ b/app/src/components/Chat/ChatWindow.tsx @@ -30,7 +30,7 @@ interface Props { // This follows the controller / view component pattern export default function ChatWindow(props: Props) { const { t } = useTranslation(); - const { isChainAdmin, chain } = useContext(StoreContext); + const { isChainAdmin, chain, chainUsers } = useContext(StoreContext); const slowTriggerScrollTop = useDebouncedCallback(() => { const lastPostId = props.postList.order.at(-1); if (lastPostId) { @@ -187,27 +187,25 @@ export default function ChatWindow(props: Props) { ); })} - {isChainAdmin ? ( - setIsActionSheetOpen(false)} - buttons={[ - { - text: "Rename", - handler: () => handleOptionSelect("rename"), - }, - { - text: "Delete", - handler: () => handleOptionSelect("delete"), - }, - { - text: "Cancel", - role: "cancel", - }, - ]} - > - ) : null} + setIsActionSheetOpen(false)} + buttons={[ + { + text: "Rename", + handler: () => handleOptionSelect("rename"), + }, + { + text: "Delete", + handler: () => handleOptionSelect("delete"), + }, + { + text: "Cancel", + role: "cancel", + }, + ]} + >