diff --git a/web/redux/nav-reducer.js b/web/redux/nav-reducer.js --- a/web/redux/nav-reducer.js +++ b/web/redux/nav-reducer.js @@ -1,8 +1,13 @@ // @flow import { locallyUniqueToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; -import { threadIsPending } from 'lib/shared/thread-utils'; -import type { RawThreadInfo } from 'lib/types/thread-types'; +import { + createPendingThread, + parseLocallyUniqueThreadID, + threadIsPending, +} from 'lib/shared/thread-utils'; +import { type RawThreadInfo, threadTypes } from 'lib/types/thread-types'; +import type { UserInfos } from 'lib/types/user-types'; import type { Action } from '../redux/redux-setup'; import { type NavInfo, updateNavInfoActionType } from '../types/nav-types'; @@ -11,6 +16,8 @@ oldState: NavInfo, action: Action, newThreadInfos: { +[id: string]: RawThreadInfo }, + userID: ?string, + userInfos: UserInfos, ): NavInfo { let state = oldState; if (action.type === updateNavInfoActionType) { @@ -20,7 +27,7 @@ }; } - const { activeChatThreadID } = state; + const { activeChatThreadID, pendingThread } = state; if (activeChatThreadID) { const locallyUniqueToRealizedThreadIDs = locallyUniqueToRealizedThreadIDsSelector( newThreadInfos, @@ -33,11 +40,40 @@ ...state, activeChatThreadID: realizedThreadID, }; + } else if ( + threadIsPending(activeChatThreadID) && + pendingThread?.id !== activeChatThreadID + ) { + const pendingThreadData = parseLocallyUniqueThreadID(activeChatThreadID); + // We do not create a pending sidebar yet, because it would require + // an efficient way of finding parent thread basing on source message ID + if ( + pendingThreadData && + pendingThreadData.threadType !== threadTypes.SIDEBAR && + userID + ) { + const members = pendingThreadData.memberIDs + .map(id => userInfos[id]) + .filter(Boolean); + const newPendingThread = createPendingThread({ + viewerID: userID, + threadType: pendingThreadData.threadType, + members, + }); + state = { + ...state, + activeChatThreadID: newPendingThread.id, + pendingThread: newPendingThread, + }; + } } } if (state.pendingThread && !threadIsPending(state.activeChatThreadID)) { - const { pendingThread, ...stateWithoutPendingThread } = state; + const { + pendingThread: currentPendingThread, + ...stateWithoutPendingThread + } = state; state = stateWithoutPendingThread; } diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -128,6 +128,8 @@ state.navInfo, action, state.threadStore.threadInfos, + state.currentUserInfo?.id, + state.userStore.userInfos, ), };