diff --git a/lib/shared/thread-actions-utils.js b/lib/shared/thread-actions-utils.js --- a/lib/shared/thread-actions-utils.js +++ b/lib/shared/thread-actions-utils.js @@ -17,7 +17,10 @@ RelativeMemberInfo, ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; -import { threadTypes } from '../types/thread-types-enum.js'; +import { + threadTypes, + assertThinThreadType, +} from '../types/thread-types-enum.js'; import type { ChangeThreadSettingsPayload, ClientNewThinThreadRequest, @@ -75,8 +78,14 @@ otherMemberIDs.length > 0, 'otherMemberIDs should not be empty for threads', ); + // TODO add support for thickThreadTypes in ENG-8442 + const type = assertThinThreadType(pendingThreadType(otherMemberIDs.length)); + invariant( + type !== 5, // Flow does not recognize that threadTypes.SIDEBAR is 5 + 'pendingThreadType should not return SIDEBAR', + ); resultPromise = createNewThinThread({ - type: pendingThreadType(otherMemberIDs.length), + type, initialMemberIDs: otherMemberIDs, color: threadInfo.color, calendarQuery, 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 @@ -98,6 +98,7 @@ } from '../utils/entity-text.js'; import { entries, values } from '../utils/objects.js'; import { useSelector } from '../utils/redux-utils.js'; +import { usingOlmViaTunnelbrokerForDMs } from '../utils/services-utils.js'; import { firstLine } from '../utils/string-utils.js'; import { pendingThreadIDRegex } from '../utils/validation-utils.js'; @@ -603,24 +604,38 @@ return [...mentionedMembersOfParent.values()]; } -function pendingThreadType(numberOfOtherMembers: number): 4 | 6 | 7 { - if (numberOfOtherMembers === 0) { - return threadTypes.GENESIS_PRIVATE; - } else if (numberOfOtherMembers === 1) { - return threadTypes.GENESIS_PERSONAL; +function pendingThreadType( + numberOfOtherMembers: number, +): 4 | 6 | 7 | 13 | 14 | 15 { + if (usingOlmViaTunnelbrokerForDMs) { + if (numberOfOtherMembers === 0) { + return threadTypes.PRIVATE; + } else if (numberOfOtherMembers === 1) { + return threadTypes.PERSONAL; + } else { + return threadTypes.LOCAL; + } } else { - // TODO flip back to threadTypes.LOCAL in ENG-8442 - return threadTypes.COMMUNITY_SECRET_SUBTHREAD; + if (numberOfOtherMembers === 0) { + return threadTypes.GENESIS_PRIVATE; + } else if (numberOfOtherMembers === 1) { + return threadTypes.GENESIS_PERSONAL; + } else { + return threadTypes.COMMUNITY_SECRET_SUBTHREAD; + } } } function threadTypeCanBePending(threadType: ThreadType): boolean { return ( threadType === threadTypes.GENESIS_PERSONAL || - // TODO flip back to threadTypes.LOCAL in ENG-8442 threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD || threadType === threadTypes.SIDEBAR || - threadType === threadTypes.GENESIS_PRIVATE + threadType === threadTypes.GENESIS_PRIVATE || + threadType === threadTypes.PERSONAL || + threadType === threadTypes.LOCAL || + threadType === threadTypes.THICK_SIDEBAR || + threadType === threadTypes.PRIVATE ); } diff --git a/lib/utils/services-utils.js b/lib/utils/services-utils.js --- a/lib/utils/services-utils.js +++ b/lib/utils/services-utils.js @@ -18,6 +18,11 @@ // an authoritative keyserver for things like DMs. const relyingOnAuthoritativeKeyserver = true; +// If this is true, then DM creation will use E2EE DMs encrypted via Olm and +// brokered by Tunnelbroker, instead of creating chats under GENESIS on the +// authoritative keyserver. +const usingOlmViaTunnelbrokerForDMs = false; + function handleHTTPResponseError(response: Response): void { if (!response.ok) { const { status, statusText } = response; @@ -47,6 +52,7 @@ usingCommServicesAccessToken, supportingMultipleKeyservers, relyingOnAuthoritativeKeyserver, + usingOlmViaTunnelbrokerForDMs, createHTTPAuthorizationHeader, createDefaultHTTPRequestHeaders, };