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 @@ -33,7 +33,6 @@ roleIsAdminRole, threadIsPending, getPendingThreadID, - pendingThreadType, } from '../shared/thread-utils.js'; import type { ClientAvatar, ClientEmojiAvatar } from '../types/avatar-types'; import type { EntryInfo } from '../types/entry-types.js'; @@ -49,7 +48,13 @@ threadTypeIsThick, threadTypeIsCommunityRoot, type ThreadType, + threadTypes, threadTypeIsSidebar, + threadTypeIsPrivate, + threadTypeIsPersonal, + personalThreadTypes, + privateThreadTypes, + sidebarThreadTypes, } from '../types/thread-types-enum.js'; import type { MixedRawThreadInfos, @@ -459,17 +464,29 @@ ) { continue; } + const actualMemberIDs = rawThreadInfo.members .filter(member => member.role) .map(member => member.id); + // In this function we're generating possible pending thread IDs that // could become `rawThreadInfos`. It is possible that a thick pending // thread becomes a thin thread, so we're including it twice in a map - // for each possible pending thread ID. - const possiblePendingThreadTypes = [ - pendingThreadType(actualMemberIDs.length - 1, 'thin'), - pendingThreadType(actualMemberIDs.length - 1, 'thick'), - ]; + let possiblePendingThreadTypes; + if (threadTypeIsPersonal(rawThreadInfo.type)) { + possiblePendingThreadTypes = personalThreadTypes; + } else if (threadTypeIsPrivate(rawThreadInfo.type)) { + possiblePendingThreadTypes = privateThreadTypes; + } else if (threadTypeIsSidebar(rawThreadInfo.type)) { + possiblePendingThreadTypes = sidebarThreadTypes; + } else { + possiblePendingThreadTypes = [ + threadTypes.LOCAL, + threadTypes.COMMUNITY_SECRET_SUBTHREAD, + ]; + } + for (const type of possiblePendingThreadTypes) { const pendingThreadID = getPendingThreadID( type, diff --git a/lib/types/thread-types-enum.js b/lib/types/thread-types-enum.js --- a/lib/types/thread-types-enum.js +++ b/lib/types/thread-types-enum.js @@ -136,37 +136,40 @@ values(threadTypes), ); -export const communityThreadTypes: $ReadOnlyArray = Object.freeze([ - threadTypes.COMMUNITY_ROOT, - threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT, - threadTypes.GENESIS, -]); - -export const announcementThreadTypes: $ReadOnlyArray = Object.freeze([ - threadTypes.GENESIS, - threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT, - threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD, - threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD, -]); - -export const communitySubthreads: $ReadOnlyArray = Object.freeze([ - threadTypes.COMMUNITY_OPEN_SUBTHREAD, - threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD, - threadTypes.COMMUNITY_SECRET_SUBTHREAD, - threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD, -]); - -export const sidebarThreadTypes: $ReadOnlyArray = Object.freeze([ +export const communityThreadTypes: $ReadOnlyArray = + Object.freeze([ + threadTypes.COMMUNITY_ROOT, + threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT, + threadTypes.GENESIS, + ]); + +export const announcementThreadTypes: $ReadOnlyArray = + Object.freeze([ + threadTypes.GENESIS, + threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT, + threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD, + threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD, + ]); + +export const communitySubthreads: $ReadOnlyArray = + Object.freeze([ + threadTypes.COMMUNITY_OPEN_SUBTHREAD, + threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD, + threadTypes.COMMUNITY_SECRET_SUBTHREAD, + threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD, + ]); + +export const sidebarThreadTypes: $ReadOnlyArray = Object.freeze([ threadTypes.SIDEBAR, threadTypes.THICK_SIDEBAR, ]); -export const personalThreadTypes: $ReadOnlyArray = Object.freeze([ +export const personalThreadTypes: $ReadOnlyArray = Object.freeze([ threadTypes.PERSONAL, threadTypes.GENESIS_PERSONAL, ]); -export const privateThreadTypes: $ReadOnlyArray = Object.freeze([ +export const privateThreadTypes: $ReadOnlyArray = Object.freeze([ threadTypes.PRIVATE, threadTypes.GENESIS_PRIVATE, ]);