diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -441,7 +441,7 @@ type SharedCreatePendingSidebarInput = { +sourceMessageInfo: ComposableMessageInfo | RobotextMessageInfo, +parentThreadInfo: ThreadInfo, - +viewerID: string, + +loggedInUserInfo: LoggedInUserInfo, }; type BaseCreatePendingSidebarInput = { @@ -451,11 +451,18 @@ function baseCreatePendingSidebar( input: BaseCreatePendingSidebarInput, ): ThreadInfo { - const { sourceMessageInfo, parentThreadInfo, viewerID, messageTitle } = input; + const { + sourceMessageInfo, + parentThreadInfo, + loggedInUserInfo, + messageTitle, + } = input; const { color, type: parentThreadType } = parentThreadInfo; const threadName = trimText(messageTitle, 30); const initialMembers = new Map(); + const { id: viewerID, username } = loggedInUserInfo; + initialMembers.set(viewerID, ({ id: viewerID, username }: UserInfo)); if (userIsMember(parentThreadInfo, sourceMessageInfo.creator.id)) { const { id: sourceAuthorID, username: sourceAuthorUsername } = sourceMessageInfo.creator; @@ -507,8 +514,12 @@ function createUnresolvedPendingSidebar( input: CreateUnresolvedPendingSidebarInput, ): ThreadInfo { - const { sourceMessageInfo, parentThreadInfo, viewerID, markdownRules } = - input; + const { + sourceMessageInfo, + parentThreadInfo, + loggedInUserInfo, + markdownRules, + } = input; const messageTitleEntityText = getMessageTitle( sourceMessageInfo, @@ -523,7 +534,7 @@ sourceMessageInfo, parentThreadInfo, messageTitle, - viewerID, + loggedInUserInfo, }); } @@ -538,7 +549,7 @@ const { sourceMessageInfo, parentThreadInfo, - viewerID, + loggedInUserInfo, markdownRules, getENSNames, } = input; @@ -562,7 +573,7 @@ sourceMessageInfo, parentThreadInfo, messageTitle, - viewerID, + loggedInUserInfo, }); } diff --git a/native/chat/sidebar-input-bar-height-measurer.react.js b/native/chat/sidebar-input-bar-height-measurer.react.js --- a/native/chat/sidebar-input-bar-height-measurer.react.js +++ b/native/chat/sidebar-input-bar-height-measurer.react.js @@ -3,10 +3,11 @@ import * as React from 'react'; import { View, StyleSheet } from 'react-native'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; + import { DummyChatInputBar } from './chat-input-bar.react.js'; import { useMessageListScreenWidth } from './composed-message-width.js'; import { getUnresolvedSidebarThreadInfo } from './sidebar-navigation.js'; -import { useSelector } from '../redux/redux-utils.js'; import type { ChatMessageInfoItemWithHeight } from '../types/chat-types.js'; type Props = { @@ -19,12 +20,11 @@ const width = useMessageListScreenWidth(); - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, + const loggedInUserInfo = useLoggedInUserInfo(); + const sidebarThreadInfo = React.useMemo( + () => getUnresolvedSidebarThreadInfo({ sourceMessage, loggedInUserInfo }), + [sourceMessage, loggedInUserInfo], ); - const sidebarThreadInfo = React.useMemo(() => { - return getUnresolvedSidebarThreadInfo({ sourceMessage, viewerID }); - }, [sourceMessage, viewerID]); if (!sidebarThreadInfo) { return null; } diff --git a/native/chat/sidebar-navigation.js b/native/chat/sidebar-navigation.js --- a/native/chat/sidebar-navigation.js +++ b/native/chat/sidebar-navigation.js @@ -4,33 +4,34 @@ import * as React from 'react'; import { ENSCacheContext } from 'lib/components/ens-cache-provider.react.js'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { createPendingSidebar, createUnresolvedPendingSidebar, } from 'lib/shared/thread-utils.js'; import type { ThreadInfo } from 'lib/types/thread-types.js'; +import type { LoggedInUserInfo } from 'lib/types/user-types.js'; import type { GetENSNames } from 'lib/utils/ens-helpers.js'; import { ChatContext } from './chat-context.js'; import { useNavigateToThread } from './message-list-types.js'; import { getDefaultTextMessageRules } from '../markdown/rules.react.js'; -import { useSelector } from '../redux/redux-utils.js'; import type { ChatMessageInfoItemWithHeight } from '../types/chat-types.js'; type GetUnresolvedSidebarThreadInfoInput = { +sourceMessage: ChatMessageInfoItemWithHeight, - +viewerID?: ?string, + +loggedInUserInfo: ?LoggedInUserInfo, }; function getUnresolvedSidebarThreadInfo( input: GetUnresolvedSidebarThreadInfoInput, ): ?ThreadInfo { - const { sourceMessage, viewerID } = input; + const { sourceMessage, loggedInUserInfo } = input; const threadCreatedFromMessage = sourceMessage.threadCreatedFromMessage; if (threadCreatedFromMessage) { return threadCreatedFromMessage; } - if (!viewerID) { + if (!loggedInUserInfo) { return null; } @@ -38,7 +39,7 @@ return createUnresolvedPendingSidebar({ sourceMessageInfo: messageInfo, parentThreadInfo: threadInfo, - viewerID, + loggedInUserInfo, markdownRules: getDefaultTextMessageRules().simpleMarkdownRules, }); } @@ -50,13 +51,13 @@ async function getSidebarThreadInfo( input: GetSidebarThreadInfoInput, ): Promise { - const { sourceMessage, viewerID, getENSNames } = input; + const { sourceMessage, loggedInUserInfo, getENSNames } = input; const threadCreatedFromMessage = sourceMessage.threadCreatedFromMessage; if (threadCreatedFromMessage) { return threadCreatedFromMessage; } - if (!viewerID) { + if (!loggedInUserInfo) { return null; } @@ -64,7 +65,7 @@ return await createPendingSidebar({ sourceMessageInfo: messageInfo, parentThreadInfo: threadInfo, - viewerID, + loggedInUserInfo, markdownRules: getDefaultTextMessageRules().simpleMarkdownRules, getENSNames, }); @@ -73,21 +74,19 @@ function useNavigateToSidebar( item: ChatMessageInfoItemWithHeight, ): () => mixed { - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, - ); + const loggedInUserInfo = useLoggedInUserInfo(); const navigateToThread = useNavigateToThread(); const cacheContext = React.useContext(ENSCacheContext); const { getENSNames } = cacheContext; return React.useCallback(async () => { const threadInfo = await getSidebarThreadInfo({ sourceMessage: item, - viewerID, + loggedInUserInfo, getENSNames, }); invariant(threadInfo, 'threadInfo should be set'); navigateToThread({ threadInfo }); - }, [navigateToThread, item, viewerID, getENSNames]); + }, [navigateToThread, item, loggedInUserInfo, getENSNames]); } function useAnimatedNavigateToSidebar( diff --git a/native/chat/utils.js b/native/chat/utils.js --- a/native/chat/utils.js +++ b/native/chat/utils.js @@ -4,6 +4,7 @@ import * as React from 'react'; import Animated from 'react-native-reanimated'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { useMessageListData } from 'lib/selectors/chat-selectors.js'; import type { ChatMessageItem } from 'lib/selectors/chat-selectors.js'; import { messageKey } from 'lib/shared/message-utils.js'; @@ -25,7 +26,6 @@ RobotextMessageTooltipModalRouteName, TextMessageTooltipModalRouteName, } from '../navigation/route-names.js'; -import { useSelector } from '../redux/redux-utils.js'; import type { ChatMessageInfoItemWithHeight, ChatMessageItemWithHeight, @@ -217,12 +217,10 @@ setSidebarAnimationType, } = chatContext; - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, - ); + const loggedInUserInfo = useLoggedInUserInfo(); const sidebarThreadInfo = React.useMemo( - () => getUnresolvedSidebarThreadInfo({ sourceMessage, viewerID }), - [sourceMessage, viewerID], + () => getUnresolvedSidebarThreadInfo({ sourceMessage, loggedInUserInfo }), + [sourceMessage, loggedInUserInfo], ); const currentInputBarHeight = diff --git a/web/selectors/thread-selectors.js b/web/selectors/thread-selectors.js --- a/web/selectors/thread-selectors.js +++ b/web/selectors/thread-selectors.js @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux'; import { ENSCacheContext } from 'lib/components/ens-cache-provider.react.js'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { createPendingSidebar } from 'lib/shared/thread-utils.js'; import type { ComposableMessageInfo, @@ -60,7 +61,7 @@ threadInfo: ThreadInfo, ): (event: SyntheticEvent) => mixed { const dispatch = useDispatch(); - const viewerID = useSelector(state => state.currentUserInfo?.id); + const loggedInUserInfo = useLoggedInUserInfo(); const cacheContext = React.useContext(ENSCacheContext); const { getENSNames } = cacheContext; @@ -68,13 +69,13 @@ return React.useCallback( async (event: SyntheticEvent) => { event.preventDefault(); - if (!viewerID) { + if (!loggedInUserInfo) { return; } const pendingSidebarInfo = await createPendingSidebar({ sourceMessageInfo: messageInfo, parentThreadInfo: threadInfo, - viewerID, + loggedInUserInfo, markdownRules: getDefaultTextMessageRules().simpleMarkdownRules, getENSNames, }); @@ -86,7 +87,7 @@ }, }); }, - [viewerID, messageInfo, threadInfo, dispatch, getENSNames], + [loggedInUserInfo, messageInfo, threadInfo, dispatch, getENSNames], ); }