diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -17,6 +17,7 @@ import { createSelector } from 'reselect'; import { searchUsers } from 'lib/actions/user-actions.js'; +import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; import { type ChatThreadItem, useFlattenedChatListData, @@ -31,7 +32,11 @@ import type { UserSearchResult } from 'lib/types/search-types.js'; import type { ThreadInfo } from 'lib/types/thread-types.js'; import { threadTypes } from 'lib/types/thread-types.js'; -import type { GlobalAccountUserInfo, UserInfo } from 'lib/types/user-types.js'; +import type { + GlobalAccountUserInfo, + UserInfo, + LoggedInUserInfo, +} from 'lib/types/user-types.js'; import { useServerCall } from 'lib/utils/action-utils.js'; import { @@ -99,7 +104,7 @@ ...BaseProps, // Redux state +chatListData: $ReadOnlyArray, - +viewerID: ?string, + +loggedInUserInfo: ?LoggedInUserInfo, +threadSearchIndex: SearchIndex, +styles: typeof unboundStyles, +indicatorStyle: IndicatorStyle, @@ -389,7 +394,7 @@ (propsAndState: PropsAndState) => propsAndState.emptyItem, (propsAndState: PropsAndState) => propsAndState.usersSearchResults, (propsAndState: PropsAndState) => propsAndState.filterThreads, - (propsAndState: PropsAndState) => propsAndState.viewerID, + (propsAndState: PropsAndState) => propsAndState.loggedInUserInfo, ( reduxChatListData: $ReadOnlyArray, searchStatus: SearchStatus, @@ -398,7 +403,7 @@ emptyItem?: React.ComponentType<{}>, usersSearchResults: $ReadOnlyArray, filterThreads: ThreadInfo => boolean, - viewerID: ?string, + loggedInUserInfo: ?LoggedInUserInfo, ): $ReadOnlyArray => { const chatThreadItems = getThreadListSearchResults( reduxChatListData, @@ -406,7 +411,7 @@ filterThreads, threadsSearchResults, usersSearchResults, - viewerID, + loggedInUserInfo?.id, ); const chatItems: Item[] = [...chatThreadItems]; @@ -466,8 +471,10 @@ } const scrollEnabled = searchStatus === 'inactive' || searchStatus === 'active'; - // this.props.viewerID is in extraData since it's used by MessagePreview + // viewerID is in extraData since it's used by MessagePreview // within ChatThreadListItem + const viewerID = this.props.loggedInUserInfo?.id; + const extraData = `${viewerID || ''} ${this.state.openedSwipeableId}`; return ( {fixedSearch} @@ -476,9 +483,7 @@ renderItem={this.renderItem} keyExtractor={ChatThreadList.keyExtractor} getItemLayout={ChatThreadList.getItemLayout} - extraData={`${this.props.viewerID || ''} ${ - this.state.openedSwipeableId - }`} + extraData={extraData} initialNumToRender={11} keyboardShouldPersistTaps="handled" onScroll={this.onScroll} @@ -518,7 +523,7 @@ return userInfos.filter( info => !this.props.usersWithPersonalThread.has(info.id) && - info.id !== this.props.viewerID, + info.id !== this.props.loggedInUserInfo?.id, ); } @@ -560,11 +565,12 @@ }; composeThread = () => { - if (!this.props.viewerID) { + const { loggedInUserInfo } = this.props; + if (!loggedInUserInfo) { return; } const threadInfo = createPendingThread({ - viewerID: this.props.viewerID, + viewerID: loggedInUserInfo.id, threadType: threadTypes.PRIVATE, }); this.props.navigateToThread({ threadInfo, searching: true }); @@ -615,9 +621,7 @@ const ConnectedChatThreadList: React.ComponentType = React.memo( function ConnectedChatThreadList(props: BaseProps) { const boundChatListData = useFlattenedChatListData(); - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, - ); + const loggedInUserInfo = useLoggedInUserInfo(); const threadSearchIndex = useGlobalThreadSearchIndex(); const styles = useStyles(unboundStyles); const indicatorStyle = useSelector(indicatorStyleSelector); @@ -632,7 +636,7 @@