diff options
author | Vitaly Takmazov | 2022-10-28 13:43:49 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:58 +0300 |
commit | 8aecfadb13f8fc6053470d80de2acd2b3f160f57 (patch) | |
tree | 6dfb5c0346d9cff2da906058e394715f01ad1403 /vnext | |
parent | 13c15825aa6b651439c043c75d9871e52c69cf9f (diff) |
Fix remote user fetching
Diffstat (limited to 'vnext')
-rw-r--r-- | vnext/src/ui/Thread.js | 55 | ||||
-rw-r--r-- | vnext/src/ui/UserInfo.js | 9 |
2 files changed, 37 insertions, 27 deletions
diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js index 92638104..a290acd7 100644 --- a/vnext/src/ui/Thread.js +++ b/vnext/src/ui/Thread.js @@ -46,19 +46,24 @@ function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postC } }, []); const userRef = useRef(author); - useEffect(() => { - isMounted = true; - if (userRef.current.uri) { - fetchUserUri(userRef.current.uri).then(response => { - if (isMounted) { - setAuthor(response.data); - } - }); + useEffect(() => { + isMounted = true; + if (userRef.current.uri) { + fetchUserUri(userRef.current.uri).then(remote_user => { + if (isMounted) { + setAuthor({ + uid: 0, + uname: remote_user.data.preferredUsername, + avatar: remote_user.data.icon && remote_user.data.icon.url, + uri: author.uri + }); } - return () => { - isMounted = false; - }; - }, [msg.user]); + }); + } + return () => { + isMounted = false; + }; + }, [author.uri, msg.user]); return ( <div style={chatItemStyle(visitor, msg)}> <div className="msg-header"> @@ -105,10 +110,10 @@ function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postC } </> ) : ( - <> - <span> · </span>{active === msg.rid || <Button>Reply</Button>} - </> - ) + <> + <span> · </span>{active === msg.rid || <Button>Reply</Button>} + </> + ) } </div> </div> @@ -204,8 +209,8 @@ export default function Thread(props) { {active === (message.rid || 0) && <MessageInput data={message} text={editing.body || ''} onSend={postComment}>Write a comment...</MessageInput>} </Message> ) : ( - <Spinner /> - ) + <Spinner /> + ) } { message.replies && <ul id="replies"> @@ -215,13 +220,13 @@ export default function Thread(props) { <Comment msg={msg} draft={msg.rid === editing.replyto ? editing.body : ''} visitor={props.visitor} active={active} setActive={setActive} onStartEditing={startEditing} postComment={postComment} /> </li> )) : ( - <> - { - // @ts-ignore - Array(loaders).fill().map((it, i) => <Spinner key={i} />) - } - </> - ) + <> + { + // @ts-ignore + Array(loaders).fill().map((it, i) => <Spinner key={i} />) + } + </> + ) } </ul> } diff --git a/vnext/src/ui/UserInfo.js b/vnext/src/ui/UserInfo.js index 5fe244ea..9a663829 100644 --- a/vnext/src/ui/UserInfo.js +++ b/vnext/src/ui/UserInfo.js @@ -100,9 +100,14 @@ export function UserLink(props) { useEffect(() => { isMounted = true; if (userRef.current.uri) { - fetchUserUri(userRef.current.uri).then(response => { + fetchUserUri(userRef.current.uri).then(remote_user => { if (isMounted) { - setUser(response.data); + setUser({ + uid: 0, + uname: remote_user.data.preferredUsername, + avatar: remote_user.data.icon && remote_user.data.icon.url, + uri: userRef.current.uri + }); } }).catch(reason => { // TODO: debug logging |