diff --git a/lib/permissions/prefixes.js b/lib/permissions/prefixes.js --- a/lib/permissions/prefixes.js +++ b/lib/permissions/prefixes.js @@ -10,7 +10,11 @@ threadPermissionFilterPrefixes, threadPermissionPropagationPrefixes, } from '../types/thread-permission-types.js'; -import { threadTypes, type ThreadType } from '../types/thread-types-enum.js'; +import { + threadTypes, + type ThreadType, + threadTypeIsSidebar, +} from '../types/thread-types-enum.js'; type ParsedThreadPermissionString = { +permission: ThreadPermission, @@ -56,13 +60,13 @@ if ( threadType !== threadTypes.COMMUNITY_OPEN_SUBTHREAD && threadType !== threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD && - threadType !== threadTypes.SIDEBAR && + !threadTypeIsSidebar(threadType) && (parsed.filterPrefix === threadPermissionFilterPrefixes.OPEN || parsed.filterPrefix === threadPermissionFilterPrefixes.OPEN_TOP_LEVEL) ) { return false; } else if ( - threadType === threadTypes.SIDEBAR && + threadTypeIsSidebar(threadType) && (parsed.filterPrefix === threadPermissionFilterPrefixes.TOP_LEVEL || parsed.filterPrefix === threadPermissionFilterPrefixes.OPEN_TOP_LEVEL) ) { diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -40,7 +40,7 @@ RawThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAppState } from '../types/redux-types.js'; -import { threadTypes } from '../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../types/thread-types-enum.js'; import { maxReadSidebars, maxUnreadSidebars, @@ -459,7 +459,7 @@ lastMessageItem.endsCluster = true; } const threadCreatedFromMessage = - messageInfo.id && threadInfos[threadID]?.type !== threadTypes.SIDEBAR + !threadTypeIsSidebar(threadInfos[threadID]?.type) && messageInfo.id ? threadInfoFromSourceMessageID[messageInfo.id] : undefined; @@ -630,7 +630,7 @@ const containingThread = useSelector(state => { if ( !threadInfo || - threadInfo.type !== threadTypes.SIDEBAR || + !threadTypeIsSidebar(threadInfo.type) || !threadInfo.containingThreadID ) { return null; @@ -658,7 +658,7 @@ const sourceMessageID = threadInfo?.sourceMessageID; if ( !threadInfo || - threadInfo.type !== threadTypes.SIDEBAR || + !threadTypeIsSidebar(threadInfo.type) || !sourceMessageID ) { return null; diff --git a/lib/selectors/sidebar-selectors.js b/lib/selectors/sidebar-selectors.js --- a/lib/selectors/sidebar-selectors.js +++ b/lib/selectors/sidebar-selectors.js @@ -9,7 +9,7 @@ import type { MessageStore, RawMessageInfo } from '../types/message-types.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAppState } from '../types/redux-types.js'; -import { threadTypes } from '../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../types/thread-types-enum.js'; import type { SidebarInfo } from '../types/thread-types.js'; function getMostRecentRawMessageInfo( @@ -36,7 +36,7 @@ for (const childThreadInfo of childThreads) { if ( !threadInChatList(childThreadInfo) || - childThreadInfo.type !== threadTypes.SIDEBAR + !threadTypeIsSidebar(childThreadInfo.type) ) { continue; } 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 @@ -45,9 +45,9 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAppState } from '../types/redux-types.js'; import { - threadTypes, threadTypeIsCommunityRoot, type ThreadType, + threadTypeIsSidebar, } from '../types/thread-types-enum.js'; import type { MixedRawThreadInfos, @@ -386,10 +386,9 @@ continue; } - const topLevelThreadID = - threadInfo.type === threadTypes.SIDEBAR - ? threadInfo.parentThreadID - : threadID; + const topLevelThreadID = threadTypeIsSidebar(threadInfo.type) + ? threadInfo.parentThreadID + : threadID; mostRecent = { threadID: topLevelThreadID, time: mostRecentMessageTime }; } return mostRecent ? mostRecent.threadID : null; @@ -436,7 +435,7 @@ if ( threadIsPending(threadID) || (rawThreadInfo.parentThreadID !== genesis().id && - rawThreadInfo.type !== threadTypes.SIDEBAR) + !threadTypeIsSidebar(rawThreadInfo.type)) ) { continue; } diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js --- a/lib/shared/mention-utils.js +++ b/lib/shared/mention-utils.js @@ -12,7 +12,7 @@ ResolvedThreadInfo, ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; -import { threadTypes } from '../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../types/thread-types-enum.js'; import type { ChatMentionCandidates } from '../types/thread-types.js'; import { chatNameMaxLength, idSchemaRegex } from '../utils/validation-utils.js'; @@ -190,7 +190,7 @@ parentThreadInfo: ?ThreadInfo, ): $ReadOnlyArray { return React.useMemo(() => { - if (threadInfo.type !== threadTypes.SIDEBAR) { + if (!threadTypeIsSidebar(threadInfo.type)) { return threadInfo.members; } if (parentThreadInfo) { diff --git a/lib/shared/messages/create-sub-thread-message-spec.js b/lib/shared/messages/create-sub-thread-message-spec.js --- a/lib/shared/messages/create-sub-thread-message-spec.js +++ b/lib/shared/messages/create-sub-thread-message-spec.js @@ -24,7 +24,7 @@ import type { ThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { NotifTexts } from '../../types/notif-types.js'; import { threadPermissions } from '../../types/thread-permission-types.js'; -import { threadTypes } from '../../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../../types/thread-types-enum.js'; import type { RelativeUserInfo } from '../../types/user-types.js'; import { type EntityText, ET } from '../../utils/entity-text.js'; import { notifTextsForSubthreadCreation } from '../notif-utils.js'; @@ -125,10 +125,9 @@ let text; if (messageInfo.childThreadInfo.name) { - const childNoun = - messageInfo.childThreadInfo.type === threadTypes.SIDEBAR - ? 'thread' - : 'subchannel'; + const childNoun = threadTypeIsSidebar(messageInfo.childThreadInfo.type) + ? 'thread' + : 'subchannel'; text = ET`created a ${childNoun} named "${threadEntity}"`; } else { text = ET`created a ${threadEntity}`; diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -27,7 +27,7 @@ } from '../../types/messages/text.js'; import type { ThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { NotifTexts } from '../../types/notif-types.js'; -import { threadTypes } from '../../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../../types/thread-types-enum.js'; import type { RelativeUserInfo } from '../../types/user-types.js'; import { ET } from '../../utils/entity-text.js'; import { useDispatchActionPromise } from '../../utils/redux-promise-utils.js'; @@ -297,7 +297,7 @@ threadInfo: ThreadInfo, parentThreadInfo: ?ThreadInfo, ) => { - if (threadInfo.type !== threadTypes.SIDEBAR) { + if (!threadTypeIsSidebar(threadInfo.type)) { return; } invariant(parentThreadInfo, 'all sidebars should have a parent thread'); diff --git a/lib/shared/search-utils.js b/lib/shared/search-utils.js --- a/lib/shared/search-utils.js +++ b/lib/shared/search-utils.js @@ -33,7 +33,10 @@ import { userRelationshipStatus } from '../types/relationship-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; import type { ThreadRolePermissionsBlob } from '../types/thread-permission-types.js'; -import { type ThreadType, threadTypes } from '../types/thread-types-enum.js'; +import { + type ThreadType, + threadTypeIsSidebar, +} from '../types/thread-types-enum.js'; import type { AccountUserInfo, GlobalAccountUserInfo, @@ -274,7 +277,7 @@ 'in the Profile tab.', }; } else if (!isMemberOfContainingThread && containingThreadInfo) { - if (threadType !== threadTypes.SIDEBAR) { + if (!threadType || !threadTypeIsSidebar(threadType)) { notice = 'not in community'; alert = { title: 'Not in community', 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 @@ -77,6 +77,7 @@ threadTypeIsThick, assertThinThreadType, assertThickThreadType, + threadTypeIsSidebar, } from '../types/thread-types-enum.js'; import type { LegacyRawThreadInfo, @@ -277,11 +278,11 @@ } function threadIsChannel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { - return !!(threadInfo && threadInfo.type !== threadTypes.SIDEBAR); + return !!(threadInfo && !threadTypeIsSidebar(threadInfo.type)); } function threadIsSidebar(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { - return threadInfo?.type === threadTypes.SIDEBAR; + return !!(threadInfo && threadTypeIsSidebar(threadInfo.type)); } function threadInBackgroundChatList( @@ -304,7 +305,7 @@ return ( threadInChatList(threadInfo) && !!threadInfo && - threadInfo.type !== threadTypes.SIDEBAR + !threadTypeIsSidebar(threadInfo.type) ); } @@ -1151,7 +1152,7 @@ `To move a chat over here, switch the “Muted” option in its settings.`; function threadNoun(threadType: ThreadType, parentThreadID: ?string): string { - if (threadType === threadTypes.SIDEBAR) { + if (threadTypeIsSidebar(threadType)) { return 'thread'; } else if ( threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD && @@ -1181,7 +1182,7 @@ return 'Open'; } else if (threadType === threadTypes.GENESIS_PERSONAL) { return 'Personal'; - } else if (threadType === threadTypes.SIDEBAR) { + } else if (threadTypeIsSidebar(threadType)) { return 'Thread'; } else if (threadType === threadTypes.GENESIS_PRIVATE) { return 'Private'; @@ -1279,7 +1280,7 @@ threadType === threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD || //threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD || threadType === threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD || - threadType === threadTypes.SIDEBAR + threadTypeIsSidebar(threadType) ) { return 'required'; } else if ( @@ -1327,7 +1328,7 @@ if (!parentThreadInfo) { return null; } - if (threadType === threadTypes.SIDEBAR) { + if (threadTypeIsSidebar(threadType)) { return parentThreadInfo.id; } if (!parentThreadInfo.containingThreadID) { 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 @@ -150,6 +150,11 @@ threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD, ]); +export const sidebarThreadTypes: $ReadOnlyArray = Object.freeze([ + threadTypes.SIDEBAR, + threadTypes.THICK_SIDEBAR, +]); + export function threadTypeIsCommunityRoot(threadType: ThreadType): boolean { return communityThreadTypes.includes(threadType); } @@ -159,3 +164,7 @@ ): boolean { return announcementThreadTypes.includes(threadType); } + +export function threadTypeIsSidebar(threadType: ThreadType): boolean { + return sidebarThreadTypes.includes(threadType); +} diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js --- a/native/chat/settings/thread-settings.react.js +++ b/native/chat/settings/thread-settings.react.js @@ -45,7 +45,10 @@ } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { RelationshipButton } from 'lib/types/relationship-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; -import { threadTypes } from 'lib/types/thread-types-enum.js'; +import { + threadTypes, + threadTypeIsSidebar, +} from 'lib/types/thread-types-enum.js'; import type { UserInfos } from 'lib/types/user-types.js'; import { useResolvedOptionalThreadInfo, @@ -573,8 +576,8 @@ const listData: ChatSettingsItem[] = []; const sidebars = - childThreads?.filter( - childThreadInfo => childThreadInfo.type === threadTypes.SIDEBAR, + childThreads?.filter(childThreadInfo => + threadTypeIsSidebar(childThreadInfo.type), ) ?? []; if (sidebars.length === 0) { return listData; diff --git a/native/components/thread-icon.react.js b/native/components/thread-icon.react.js --- a/native/components/thread-icon.react.js +++ b/native/components/thread-icon.react.js @@ -4,7 +4,11 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; -import { threadTypes, type ThreadType } from 'lib/types/thread-types-enum.js'; +import { + threadTypes, + type ThreadType, + threadTypeIsSidebar, +} from 'lib/types/thread-types-enum.js'; import SWMansionIcon from './swmansion-icon.react.js'; @@ -19,7 +23,7 @@ threadType === threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD ) { return ; - } else if (threadType === threadTypes.SIDEBAR) { + } else if (threadTypeIsSidebar(threadType)) { return ( { - if (!activeThreadInfo || activeThreadInfo.type !== threadTypes.SIDEBAR) { + if (!activeThreadInfo || !threadTypeIsSidebar(activeThreadInfo.type)) { return null; } const { parentThreadID } = activeThreadInfo; @@ -55,7 +55,7 @@ return threadInfoSelector(state)[parentThreadID]; }); const activeTopLevelThreadInfo = - activeThreadInfo?.type === threadTypes.SIDEBAR + activeThreadInfo && threadTypeIsSidebar(activeThreadInfo?.type) ? activeSidebarParentThreadInfo : activeThreadInfo; @@ -97,7 +97,7 @@ if ( activeChatThreadItem && threadIsPending(activeThreadID) && - activeThreadInfo?.type !== threadTypes.SIDEBAR && + (!activeThreadInfo || !threadTypeIsSidebar(activeThreadInfo.type)) && !threadListData .map(thread => thread.threadInfo.id) .includes(activeThreadID) @@ -113,7 +113,7 @@ (threadListData: $ReadOnlyArray) => { if ( !activeChatThreadItem || - activeChatThreadItem.threadInfo.type !== threadTypes.SIDEBAR + !threadTypeIsSidebar(activeChatThreadItem.threadInfo.type) ) { return threadListData; } diff --git a/web/chat/thread-menu.react.js b/web/chat/thread-menu.react.js --- a/web/chat/thread-menu.react.js +++ b/web/chat/thread-menu.react.js @@ -17,7 +17,10 @@ } from 'lib/shared/thread-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; -import { threadTypes } from 'lib/types/thread-types-enum.js'; +import { + threadTypes, + threadTypeIsSidebar, +} from 'lib/types/thread-types-enum.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import css from './thread-menu.css'; @@ -110,8 +113,8 @@ ); const hasSidebars = React.useMemo(() => { - return childThreads?.some( - childThreadInfo => childThreadInfo.type === threadTypes.SIDEBAR, + return childThreads?.some(childThreadInfo => + threadTypeIsSidebar(childThreadInfo.type), ); }, [childThreads]); 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 @@ -80,7 +80,7 @@ import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; import { reportTypes } from 'lib/types/report-types.js'; -import { threadTypes } from 'lib/types/thread-types-enum.js'; +import { threadTypeIsSidebar } from 'lib/types/thread-types-enum.js'; import { type ClientNewThinThreadRequest, type NewThreadResult, @@ -1298,7 +1298,7 @@ let threadInfo = inputThreadInfo; const { viewerID } = this.props; - if (viewerID && inputThreadInfo.type === threadTypes.SIDEBAR) { + if (viewerID && threadTypeIsSidebar(inputThreadInfo.type)) { invariant(parentThreadInfo, 'sidebar should have parent'); threadInfo = patchThreadInfoToIncludeMentionedMembersOfParent( inputThreadInfo,