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, @@ -385,7 +390,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, @@ -394,7 +399,7 @@ emptyItem?: React.ComponentType<{}>, usersSearchResults: $ReadOnlyArray, filterThreads: ThreadInfo => boolean, - viewerID: ?string, + loggedInUserInfo: ?LoggedInUserInfo, ): $ReadOnlyArray => { const chatThreadItems = getThreadListSearchResults( reduxChatListData, @@ -402,7 +407,7 @@ filterThreads, threadsSearchResults, usersSearchResults, - viewerID, + loggedInUserInfo?.id, ); const chatItems: Item[] = [...chatThreadItems]; @@ -462,8 +467,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} @@ -472,9 +479,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} @@ -514,7 +519,7 @@ return userInfos.filter( info => !this.props.usersWithPersonalThread.has(info.id) && - info.id !== this.props.viewerID, + info.id !== this.props.loggedInUserInfo?.id, ); } @@ -556,11 +561,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 }); @@ -611,9 +617,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); @@ -628,7 +632,7 @@