@@ -17,11 +17,14 @@ import {
1717 isSingleEmoji ,
1818 Message ,
1919 useKeysQuery ,
20+ useNostrGetUserProfileQuery ,
2021 useResendMessage
2122} from "@ecency/ns-query" ;
2223import { format } from "date-fns" ;
2324import { useInViewport } from "react-in-viewport" ;
2425import "./_chat-message-item.scss" ;
26+ import { makePath } from "../../../components/profile-link" ;
27+ import { Link } from "react-router-dom" ;
2528
2629interface Props {
2730 type : "sender" | "receiver" ;
@@ -49,7 +52,7 @@ export function ChatMessageItem({
4952 className = ""
5053} : Props ) {
5154 const ref = useRef < HTMLDivElement | null > ( null ) ;
52- const { global } = useMappedStore ( ) ;
55+ const { global, activeUser } = useMappedStore ( ) ;
5356 const { publicKey } = useKeysQuery ( ) ;
5457
5558 const [ holdStarted , setHoldStarted ] = useState ( false ) ;
@@ -70,6 +73,17 @@ export function ChatMessageItem({
7073 const { mutateAsync : resendMessage } = useResendMessage ( currentChannel , currentContact ) ;
7174 const { inViewport } = useInViewport ( ref ) ;
7275
76+ const { data : nostrUserProfiles } = useNostrGetUserProfileQuery ( message . creator ) ;
77+
78+ const profile = useMemo (
79+ ( ) => nostrUserProfiles ?. find ( ( p ) => p . creator === message . creator ) ,
80+ [ message , nostrUserProfiles ]
81+ ) ;
82+ const showUsername = useMemo (
83+ ( ) => profile && currentChannel && profile . name != activeUser ?. username ,
84+ [ profile , currentChannel , activeUser ]
85+ ) ;
86+
7387 useMount ( ( ) => onAppear ?.( ) ) ;
7488
7589 useDebounce (
@@ -132,15 +146,31 @@ export function ChatMessageItem({
132146 < div
133147 className = { classNameObject ( {
134148 "duration-300 max-w-[340px]" : true ,
135- "text-sm p -2.5 rounded-b-2xl" : ! isGif && ! isEmoji ,
149+ "text-sm px-2.5 pb -2.5 rounded-b-2xl" : ! isGif && ! isEmoji ,
136150 "bg-blue-dark-sky text-white rounded-tl-2xl" : type === "sender" && ! isEmoji ,
137151 "bg-gray-200 dark:bg-gray-800 rounded-tr-2xl" : type === "receiver" && ! isEmoji ,
138152 "max-w-[300px] rounded-2xl overflow-hidden" : isGif || isImage || isEmoji ,
139153 "same-user-message" : isSameUser ,
140154 "text-[4rem]" : isEmoji ,
141- "scale-90" : holdStarted && ! ! onContextMenu
155+ "scale-90" : holdStarted && ! ! onContextMenu ,
156+ "pt-2.5" : ! showUsername ,
157+ "pt-1.5" : showUsername
142158 } ) }
143159 >
160+ { showUsername && (
161+ < Link
162+ className = { classNameObject ( {
163+ "font-semibold text-sm mb-2 text-blue-dark-sky" : true ,
164+ "px-2.5" : isGif || isEmoji
165+ } ) }
166+ style = { {
167+ display : "inherit"
168+ } }
169+ to = { makePath ( profile ! ! . name ) }
170+ >
171+ { profile ! ! . name }
172+ </ Link >
173+ ) }
144174 < div
145175 className = "sender-message-content [&>img]:rounded-xl"
146176 dangerouslySetInnerHTML = { { __html : renderedPreview } }
0 commit comments