diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -18,7 +18,7 @@ import { threadHasPermission, threadIsPending, - parseLocallyUniqueThreadID, + parsePendingThreadID, createPendingThread, } from 'lib/shared/thread-utils'; import { defaultWebEnabledApps } from 'lib/types/enabled-apps'; @@ -233,7 +233,7 @@ threadIsPending(finalNavInfo.activeChatThreadID) && finalNavInfo.pendingThread?.id !== finalNavInfo.activeChatThreadID ) { - const pendingThreadData = parseLocallyUniqueThreadID( + const pendingThreadData = parsePendingThreadID( finalNavInfo.activeChatThreadID, ); if ( diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -48,7 +48,7 @@ logInActionTypes, registerActionTypes, } from '../actions/user-actions'; -import { locallyUniqueToRealizedThreadIDsSelector } from '../selectors/thread-selectors'; +import { pendingToRealizedThreadIDsSelector } from '../selectors/thread-selectors'; import { messageID, combineTruncationStatuses, @@ -189,7 +189,7 @@ messageStore: MessageStore, threadInfos: { +[threadID: string]: RawThreadInfo }, ): ReassignmentResult { - const locallyUniqueToRealizedThreadIDs = locallyUniqueToRealizedThreadIDsSelector( + const pendingToRealizedThreadIDs = pendingToRealizedThreadIDsSelector( threadInfos, ); @@ -197,7 +197,7 @@ const messages = {}; for (const storeMessageID in messageStore.messages) { const message = messageStore.messages[storeMessageID]; - const newThreadID = locallyUniqueToRealizedThreadIDs.get(message.threadID); + const newThreadID = pendingToRealizedThreadIDs.get(message.threadID); messages[storeMessageID] = newThreadID ? { @@ -223,7 +223,7 @@ const reassignedThreadIDs = []; for (const threadID in messageStore.threads) { const threadMessageInfo = messageStore.threads[threadID]; - const newThreadID = locallyUniqueToRealizedThreadIDs.get(threadID); + const newThreadID = pendingToRealizedThreadIDs.get(threadID); if (!newThreadID) { threads[threadID] = threadMessageInfo; continue; @@ -635,12 +635,10 @@ payload: T, threadInfos: { +[id: string]: RawThreadInfo }, ): T { - const locallyUniqueToRealizedThreadIDs = locallyUniqueToRealizedThreadIDsSelector( + const pendingToRealizedThreadIDs = pendingToRealizedThreadIDsSelector( threadInfos, ); - const realizedThreadID = locallyUniqueToRealizedThreadIDs.get( - payload.threadID, - ); + const realizedThreadID = pendingToRealizedThreadIDs.get(payload.threadID); return realizedThreadID ? { ...payload, threadID: realizedThreadID } : payload; diff --git a/lib/selectors/thread-selectors.js b/lib/selectors/thread-selectors.js --- a/lib/selectors/thread-selectors.js +++ b/lib/selectors/thread-selectors.js @@ -24,7 +24,7 @@ threadHasAdminRole, roleIsAdminRole, threadIsPending, - getLocallyUniqueThreadID, + getPendingThreadID, } from '../shared/thread-utils'; import type { EntryInfo } from '../types/entry-types'; import type { MessageStore, RawMessageInfo } from '../types/message-types'; @@ -351,11 +351,11 @@ rawThreadInfos: { +[id: string]: RawThreadInfo }, threadInfos: { +[id: string]: ThreadInfo }, ) => { - const locallyUniqueToRealizedThreadIDs = locallyUniqueToRealizedThreadIDsSelector( + const pendingToRealizedThreadIDs = pendingToRealizedThreadIDsSelector( rawThreadInfos, ); const result = {}; - for (const realizedID of locallyUniqueToRealizedThreadIDs.values()) { + for (const realizedID of pendingToRealizedThreadIDs.values()) { const threadInfo = threadInfos[realizedID]; if (threadInfo && threadInfo.sourceMessageID) { result[threadInfo.sourceMessageID] = threadInfo; @@ -364,7 +364,7 @@ return result; }, ); -const locallyUniqueToRealizedThreadIDsSelector: (rawThreadInfos: { +const pendingToRealizedThreadIDsSelector: (rawThreadInfos: { +[id: string]: RawThreadInfo, }) => $ReadOnlyMap = createSelector( (rawThreadInfos: { +[id: string]: RawThreadInfo }) => rawThreadInfos, @@ -378,17 +378,17 @@ const actualMemberIDs = rawThreadInfo.members .filter(member => member.role) .map(member => member.id); - const locallyUniqueThreadID = getLocallyUniqueThreadID( + const pendingThreadID = getPendingThreadID( rawThreadInfo.type, actualMemberIDs, rawThreadInfo.sourceMessageID, ); - const existingResult = result.get(locallyUniqueThreadID); + const existingResult = result.get(pendingThreadID); if ( !existingResult || rawThreadInfos[existingResult].creationTime > rawThreadInfo.creationTime ) { - result.set(locallyUniqueThreadID, threadID); + result.set(pendingThreadID, threadID); } } return result; @@ -410,5 +410,5 @@ mostRecentlyReadThreadSelector, sidebarInfoSelector, threadInfoFromSourceMessageIDSelector, - locallyUniqueToRealizedThreadIDsSelector, + pendingToRealizedThreadIDsSelector, }; 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 @@ -30,7 +30,7 @@ import { threadSearchIndex as threadSearchIndexSelector } from '../selectors/nav-selectors'; import { threadInfoSelector, - locallyUniqueToRealizedThreadIDsSelector, + pendingToRealizedThreadIDsSelector, } from '../selectors/thread-selectors'; import { getRelativeMemberInfos, @@ -258,7 +258,7 @@ return otherMemberIDs[0]; } -function getLocallyUniqueThreadID( +function getPendingThreadID( threadType: ThreadType, memberIDs: $ReadOnlyArray, sourceMessageID: ?string, @@ -270,20 +270,20 @@ return `pending/${pendingThreadTypeString}${pendingThreadKey}`; } -const locallyUniqueThreadIDRegex = +const pendingThreadIDRegex = 'pending/(type[0-9]+/[0-9]+(\\+[0-9]+)*|sidebar/[0-9]+)'; -type LocallyUniqueThreadIDContents = { +type PendingThreadIDContents = { +threadType: ThreadType, +memberIDs: $ReadOnlyArray, +sourceMessageID: ?string, }; -function parseLocallyUniqueThreadID( +function parsePendingThreadID( pendingThreadID: string, -): ?LocallyUniqueThreadIDContents { - const locallyUniqueRegex = new RegExp(`^${locallyUniqueThreadIDRegex}$`); - const pendingThreadIDMatches = locallyUniqueRegex.exec(pendingThreadID); +): ?PendingThreadIDContents { + const pendingRegex = new RegExp(`^${pendingThreadIDRegex}$`); + const pendingThreadIDMatches = pendingRegex.exec(pendingThreadID); if (!pendingThreadIDMatches) { return null; } @@ -326,11 +326,7 @@ : []; const nonViewerMemberIDs = nonViewerMembers.map(member => member.id); const memberIDs = [...nonViewerMemberIDs, viewerID]; - const threadID = getLocallyUniqueThreadID( - threadType, - memberIDs, - sourceMessageID, - ); + const threadID = getPendingThreadID(threadType, memberIDs, sourceMessageID); const permissions = { [threadPermissions.KNOW_OF]: true, @@ -1033,8 +1029,8 @@ ); const userInfos = useSelector(state => state.userStore.userInfos); - const locallyUniqueToRealizedThreadIDs = useSelector(state => - locallyUniqueToRealizedThreadIDsSelector(state.threadStore.threadInfos), + const pendingToRealizedThreadIDs = useSelector(state => + pendingToRealizedThreadIDsSelector(state.threadStore.threadInfos), ); return React.useCallback( (params: ExistingThreadInfoFinderParams): ?ThreadInfo => { @@ -1061,20 +1057,18 @@ const { sourceMessageID } = baseThreadInfo; const pendingThreadID = searching - ? getLocallyUniqueThreadID( + ? getPendingThreadID( pendingThreadType(userInfoInputArray.length), [...userInfoInputArray.map(user => user.id), viewerID], sourceMessageID, ) - : getLocallyUniqueThreadID( + : getPendingThreadID( baseThreadInfo.type, baseThreadInfo.members.map(member => member.id), sourceMessageID, ); - const realizedThreadID = locallyUniqueToRealizedThreadIDs.get( - pendingThreadID, - ); + const realizedThreadID = pendingToRealizedThreadIDs.get(pendingThreadID); if (realizedThreadID && threadInfos[realizedThreadID]) { return threadInfos[realizedThreadID]; } @@ -1095,7 +1089,7 @@ baseThreadInfo, threadInfos, viewerID, - locallyUniqueToRealizedThreadIDs, + pendingToRealizedThreadIDs, userInfos, ], ); @@ -1412,9 +1406,9 @@ threadIsGroupChat, threadIsPending, getSingleOtherUser, - getLocallyUniqueThreadID, - locallyUniqueThreadIDRegex, - parseLocallyUniqueThreadID, + getPendingThreadID, + pendingThreadIDRegex, + parsePendingThreadID, createPendingThread, createPendingThreadItem, createPendingSidebar, diff --git a/lib/shared/thread-utils.test.js b/lib/shared/thread-utils.test.js --- a/lib/shared/thread-utils.test.js +++ b/lib/shared/thread-utils.test.js @@ -1,16 +1,16 @@ // @flow import { threadTypes } from '../types/thread-types'; -import { parseLocallyUniqueThreadID } from './thread-utils'; +import { parsePendingThreadID } from './thread-utils'; -describe('parseLocallyUniqueThreadID(pendingThreadID: string)', () => { +describe('parsePendingThreadID(pendingThreadID: string)', () => { it('should return correct data for real pending sidebar ID', () => { const sidebarResult = { threadType: threadTypes.SIDEBAR, memberIDs: [], sourceMessageID: '12345', }; - expect(parseLocallyUniqueThreadID('pending/sidebar/12345')).toStrictEqual( + expect(parsePendingThreadID('pending/sidebar/12345')).toStrictEqual( sidebarResult, ); }); @@ -21,9 +21,9 @@ memberIDs: ['83810', '86622'], sourceMessageID: null, }; - expect( - parseLocallyUniqueThreadID('pending/type6/83810+86622'), - ).toStrictEqual(pendingPersonalResult); + expect(parsePendingThreadID('pending/type6/83810+86622')).toStrictEqual( + pendingPersonalResult, + ); const pendingCommunityOpenResult = { threadType: threadTypes.COMMUNITY_OPEN_SUBTHREAD, @@ -31,30 +31,28 @@ sourceMessageID: null, }; expect( - parseLocallyUniqueThreadID('pending/type3/83810+86622+83889'), + parsePendingThreadID('pending/type3/83810+86622+83889'), ).toStrictEqual(pendingCommunityOpenResult); }); it('should return null when there are missing information in ID', () => { - expect(parseLocallyUniqueThreadID('pending/type4/')).toBeNull(); - expect(parseLocallyUniqueThreadID('type12/83810+86622')).toBeNull(); - expect(parseLocallyUniqueThreadID('pending/83810')).toBeNull(); - expect(parseLocallyUniqueThreadID('pending')).toBeNull(); - expect(parseLocallyUniqueThreadID('')).toBeNull(); - expect(parseLocallyUniqueThreadID('pending/something/12345')).toBeNull(); + expect(parsePendingThreadID('pending/type4/')).toBeNull(); + expect(parsePendingThreadID('type12/83810+86622')).toBeNull(); + expect(parsePendingThreadID('pending/83810')).toBeNull(); + expect(parsePendingThreadID('pending')).toBeNull(); + expect(parsePendingThreadID('')).toBeNull(); + expect(parsePendingThreadID('pending/something/12345')).toBeNull(); }); it('should return null when the format is invalid', () => { - expect(parseLocallyUniqueThreadID('someothertext/type1/12345')).toBeNull(); - expect( - parseLocallyUniqueThreadID('pending/type6/12312+++11+12'), - ).toBeNull(); - expect(parseLocallyUniqueThreadID('pending/type3/83810+')).toBeNull(); + expect(parsePendingThreadID('someothertext/type1/12345')).toBeNull(); + expect(parsePendingThreadID('pending/type6/12312+++11+12')).toBeNull(); + expect(parsePendingThreadID('pending/type3/83810+')).toBeNull(); }); it('should throw invariant violation when thread type is invalid ', () => { - expect(() => - parseLocallyUniqueThreadID('pending/type123/12345'), - ).toThrowError('number is not ThreadType enum'); + expect(() => parsePendingThreadID('pending/type123/12345')).toThrowError( + 'number is not ThreadType enum', + ); }); }); diff --git a/lib/utils/url-utils.js b/lib/utils/url-utils.js --- a/lib/utils/url-utils.js +++ b/lib/utils/url-utils.js @@ -2,7 +2,7 @@ import urlParseLax from 'url-parse-lax'; -import { locallyUniqueThreadIDRegex } from '../shared/thread-utils'; +import { pendingThreadIDRegex } from '../shared/thread-utils'; export type URLInfo = { +year?: number, @@ -30,7 +30,7 @@ const accountSettingsRegex = new RegExp('(/|^)settings/account(/|$)', 'i'); const dangerZoneRegex = new RegExp('(/|^)settings/danger-zone(/|$)', 'i'); const threadPendingRegex = new RegExp( - `(/|^)thread/(${locallyUniqueThreadIDRegex})(/|$)`, + `(/|^)thread/(${pendingThreadIDRegex})(/|$)`, 'i', ); const threadCreationRegex = new RegExp( diff --git a/native/chat/thread-draft-updater.react.js b/native/chat/thread-draft-updater.react.js --- a/native/chat/thread-draft-updater.react.js +++ b/native/chat/thread-draft-updater.react.js @@ -3,7 +3,7 @@ import invariant from 'invariant'; import * as React from 'react'; -import { locallyUniqueToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; +import { pendingToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; import { draftKeyFromThreadID } from 'lib/shared/thread-utils'; import { useDrafts } from '../data/core-data'; @@ -12,15 +12,15 @@ const ThreadDraftUpdater: React.ComponentType<{}> = React.memo<{}>( function ThreadDraftUpdater() { - const locallyUniqueToRealizedThreadIDs = useSelector((state: AppState) => - locallyUniqueToRealizedThreadIDsSelector(state.threadStore.threadInfos), + const pendingToRealizedThreadIDs = useSelector((state: AppState) => + pendingToRealizedThreadIDsSelector(state.threadStore.threadInfos), ); const drafts = useDrafts(); const cachedThreadIDsRef = React.useRef(); if (!cachedThreadIDsRef.current) { const newCachedThreadIDs = new Set(); - for (const realizedThreadID of locallyUniqueToRealizedThreadIDs.values()) { + for (const realizedThreadID of pendingToRealizedThreadIDs.values()) { newCachedThreadIDs.add(realizedThreadID); } cachedThreadIDsRef.current = newCachedThreadIDs; @@ -28,22 +28,19 @@ const { moveDraft } = drafts; React.useEffect(() => { - for (const [ - locallyUniqueThreadID, - threadID, - ] of locallyUniqueToRealizedThreadIDs) { + for (const [pendingThreadID, threadID] of pendingToRealizedThreadIDs) { const cachedThreadIDs = cachedThreadIDsRef.current; invariant(cachedThreadIDs, 'should be set'); if (cachedThreadIDs.has(threadID)) { continue; } moveDraft( - draftKeyFromThreadID(locallyUniqueThreadID), + draftKeyFromThreadID(pendingThreadID), draftKeyFromThreadID(threadID), ); cachedThreadIDs.add(threadID); } - }, [locallyUniqueToRealizedThreadIDs, moveDraft]); + }, [pendingToRealizedThreadIDs, moveDraft]); return null; }, ); diff --git a/web/input/input-state-container.react.js b/web/input/input-state-container.react.js --- a/web/input/input-state-container.react.js +++ b/web/input/input-state-container.react.js @@ -29,7 +29,7 @@ type MultimediaUploadExtras, } from 'lib/actions/upload-actions'; import { getNextLocalUploadID } from 'lib/media/media-utils'; -import { locallyUniqueToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; +import { pendingToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; import { createMediaMessageInfo, localIDPrefix, @@ -87,7 +87,7 @@ +viewerID: ?string, +messageStoreMessages: { +[id: string]: RawMessageInfo }, +exifRotate: boolean, - +locallyUniqueRealizedThreadIDs: $ReadOnlyMap, + +pendingRealizedThreadIDs: $ReadOnlyMap, +dispatch: Dispatch, +dispatchActionPromise: DispatchActionPromise, +calendarQuery: () => CalendarQuery, @@ -135,7 +135,7 @@ let updated = false; for (const threadID in state) { const newThreadID = - props.locallyUniqueRealizedThreadIDs.get(threadID) ?? threadID; + props.pendingRealizedThreadIDs.get(threadID) ?? threadID; if (newThreadID !== threadID) { updated = true; } @@ -509,7 +509,7 @@ ); getRealizedOrPendingThreadID(threadID: string): string { - return this.props.locallyUniqueRealizedThreadIDs.get(threadID) ?? threadID; + return this.props.pendingRealizedThreadIDs.get(threadID) ?? threadID; } async appendFiles( @@ -1242,8 +1242,8 @@ const messageStoreMessages = useSelector( state => state.messageStore.messages, ); - const locallyUniqueToRealizedThreadIDs = useSelector(state => - locallyUniqueToRealizedThreadIDsSelector(state.threadStore.threadInfos), + const pendingToRealizedThreadIDs = useSelector(state => + pendingToRealizedThreadIDsSelector(state.threadStore.threadInfos), ); const calendarQuery = useSelector(nonThreadCalendarQuery); const callUploadMultimedia = useServerCall(uploadMultimedia); @@ -1277,7 +1277,7 @@ viewerID={viewerID} messageStoreMessages={messageStoreMessages} exifRotate={exifRotate} - locallyUniqueRealizedThreadIDs={locallyUniqueToRealizedThreadIDs} + pendingRealizedThreadIDs={pendingToRealizedThreadIDs} calendarQuery={calendarQuery} uploadMultimedia={callUploadMultimedia} deleteUpload={callDeleteUpload} 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,6 +1,6 @@ // @flow -import { locallyUniqueToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; +import { pendingToRealizedThreadIDsSelector } from 'lib/selectors/thread-selectors'; import { threadIsPending } from 'lib/shared/thread-utils'; import type { RawThreadInfo } from 'lib/types/thread-types'; @@ -22,12 +22,10 @@ const { activeChatThreadID } = state; if (activeChatThreadID) { - const locallyUniqueToRealizedThreadIDs = locallyUniqueToRealizedThreadIDsSelector( + const pendingToRealizedThreadIDs = pendingToRealizedThreadIDsSelector( newThreadInfos, ); - const realizedThreadID = locallyUniqueToRealizedThreadIDs.get( - activeChatThreadID, - ); + const realizedThreadID = pendingToRealizedThreadIDs.get(activeChatThreadID); if (realizedThreadID) { state = { ...state,