diff --git a/lib/shared/sidebar-utils.js b/lib/shared/sidebar-utils.js --- a/lib/shared/sidebar-utils.js +++ b/lib/shared/sidebar-utils.js @@ -22,7 +22,6 @@ } from '../types/message-types.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; -import { threadTypes, threadTypeIsThick } from '../types/thread-types-enum.js'; import type { LoggedInUserInfo } from '../types/user-types.js'; import type { GetENSNames } from '../utils/ens-helpers.js'; import { @@ -105,9 +104,9 @@ return createPendingThread({ viewerID, - threadType: threadTypeIsThick(parentThreadInfo.type) - ? threadTypes.THICK_SIDEBAR - : threadTypes.SIDEBAR, + threadType: + threadSpecs[parentThreadInfo.type].protocol.sidebarConfig + .sidebarThreadType, members: [...initialMembers.values()], parentThreadInfo, threadColor: color, 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 @@ -13,6 +13,7 @@ import { extractUserMentionsFromText } from './mention-utils.js'; import { relationshipBlockedInEitherDirection } from './relationship-utils.js'; import type { SidebarItem } from './sidebar-item-utils.js'; +import { protocols } from './threads/protocols/thread-protocols.js'; import { threadSpecs, threadTypeIsCommunityRoot, @@ -414,10 +415,10 @@ sourceMessageID: ?string, ): string { let pendingThreadKey; - if (sourceMessageID && threadTypeIsThick(threadType)) { - pendingThreadKey = `${pendingThickSidebarURLPrefix}/${sourceMessageID}`; - } else if (sourceMessageID) { - pendingThreadKey = `${pendingSidebarURLPrefix}/${sourceMessageID}`; + if (sourceMessageID) { + const prefix = + threadSpecs[threadType].protocol.sidebarConfig.pendingSidebarURLPrefix; + pendingThreadKey = `${prefix}/${sourceMessageID}`; } else { pendingThreadKey = [...memberIDs].sort().join('+'); } @@ -442,18 +443,13 @@ } const [threadTypeString, threadKey] = pendingThreadIDMatches[1].split('/'); - let threadType; - if (threadTypeString === pendingThickSidebarURLPrefix) { - threadType = threadTypes.THICK_SIDEBAR; - } else if (threadTypeString === pendingSidebarURLPrefix) { - threadType = threadTypes.SIDEBAR; - } else { - threadType = assertThreadType(Number(threadTypeString.replace('type', ''))); - } + const threadType = + protocols.find( + p => p.sidebarConfig.pendingSidebarURLPrefix === threadTypeString, + )?.sidebarConfig.sidebarThreadType ?? + assertThreadType(Number(threadTypeString.replace('type', ''))); - const threadTypeStringIsSidebar = - threadTypeString === pendingSidebarURLPrefix || - threadTypeString === pendingThickSidebarURLPrefix; + const threadTypeStringIsSidebar = threadTypeIsSidebar(threadType); const memberIDs = threadTypeStringIsSidebar ? [] : threadKey.split('+'); const sourceMessageID = threadTypeStringIsSidebar ? threadKey : null; return { @@ -1601,9 +1597,8 @@ return threadInfo; } members.push(...mentionedNewMembers); - const threadType = threadTypeIsThick(parentThreadInfo.type) - ? threadTypes.THICK_SIDEBAR - : threadTypes.SIDEBAR; + const threadType = + threadSpecs[parentThreadInfo.type].protocol.sidebarConfig.sidebarThreadType; return createPendingThread({ viewerID, diff --git a/lib/shared/threads/protocols/dm-thread-protocol.js b/lib/shared/threads/protocols/dm-thread-protocol.js --- a/lib/shared/threads/protocols/dm-thread-protocol.js +++ b/lib/shared/threads/protocols/dm-thread-protocol.js @@ -18,6 +18,7 @@ import type { ChangeThreadSettingsPayload } from '../../../types/thread-types.js'; import { dateString as stringFromDate } from '../../../utils/date-utils.js'; import { SendMessageError } from '../../../utils/errors.js'; +import { pendingThickSidebarURLPrefix } from '../../../utils/validation-utils.js'; import { dmOperationSpecificationTypes, type OutboundDMOperationSpecification, @@ -490,6 +491,11 @@ uploadMultimediaToKeyserver: false, canActionsTargetPendingMessages: true, + + sidebarConfig: { + sidebarThreadType: thickThreadTypes.THICK_SIDEBAR, + pendingSidebarURLPrefix: pendingThickSidebarURLPrefix, + }, }); export { dmThreadProtocol }; diff --git a/lib/shared/threads/protocols/keyserver-thread-protocol.js b/lib/shared/threads/protocols/keyserver-thread-protocol.js --- a/lib/shared/threads/protocols/keyserver-thread-protocol.js +++ b/lib/shared/threads/protocols/keyserver-thread-protocol.js @@ -34,6 +34,7 @@ import { getMediaMessageServerDBContentsFromMedia } from '../../../types/messages/media.js'; import type { RawReactionMessageInfo } from '../../../types/messages/reaction.js'; import type { Dispatch } from '../../../types/redux-types.js'; +import { thinThreadTypes } from '../../../types/thread-types-enum.js'; import { blobHashFromBlobServiceURI, isBlobServiceURI, @@ -42,6 +43,7 @@ getMessageForException, SendMessageError, } from '../../../utils/errors.js'; +import { pendingSidebarURLPrefix } from '../../../utils/validation-utils.js'; import { getNextLocalID } from '../../id-utils.js'; import type { ThreadProtocol, @@ -327,6 +329,11 @@ uploadMultimediaToKeyserver: true, canActionsTargetPendingMessages: false, + + sidebarConfig: { + sidebarThreadType: thinThreadTypes.SIDEBAR, + pendingSidebarURLPrefix: pendingSidebarURLPrefix, + }, }); function mediaIDIsKeyserverID(mediaID: string): boolean { diff --git a/lib/shared/threads/protocols/thread-protocols.js b/lib/shared/threads/protocols/thread-protocols.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/protocols/thread-protocols.js @@ -0,0 +1,8 @@ +// @flow + +import { dmThreadProtocol } from './dm-thread-protocol.js'; +import { keyserverThreadProtocol } from './keyserver-thread-protocol.js'; + +const protocols = [dmThreadProtocol, keyserverThreadProtocol]; + +export { protocols }; diff --git a/lib/shared/threads/thread-spec.js b/lib/shared/threads/thread-spec.js --- a/lib/shared/threads/thread-spec.js +++ b/lib/shared/threads/thread-spec.js @@ -46,6 +46,7 @@ ThreadInfo, } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { Dispatch } from '../../types/redux-types.js'; +import type { ThreadType } from '../../types/thread-types-enum.js'; import type { ChangeThreadSettingsPayload, UpdateThreadRequest, @@ -232,6 +233,10 @@ }, +uploadMultimediaToKeyserver: boolean, +canActionsTargetPendingMessages: boolean, + +sidebarConfig: { + +sidebarThreadType: ThreadType, + +pendingSidebarURLPrefix: string, + }, }; export type ThreadSpec = {