diff --git a/keyserver/src/creators/role-creator.js b/keyserver/src/creators/role-creator.js --- a/keyserver/src/creators/role-creator.js +++ b/keyserver/src/creators/role-creator.js @@ -9,14 +9,12 @@ getThreadPermissionBlobFromUserSurfacedPermissions, } from 'lib/permissions/thread-permissions.js'; import { threadHasPermission } from 'lib/shared/thread-utils.js'; +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import { userSurfacedPermissionsSet, threadPermissions, } from 'lib/types/thread-permission-types.js'; -import { - threadTypeIsCommunityRoot, - type ThreadType, -} from 'lib/types/thread-types-enum.js'; +import { type ThreadType } from 'lib/types/thread-types-enum.js'; import type { RoleModificationRequest, RoleModificationResult, diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js --- a/keyserver/src/creators/thread-creator.js +++ b/keyserver/src/creators/thread-creator.js @@ -10,13 +10,11 @@ } from 'lib/shared/color-utils.js'; import { isInvalidSidebarSource } from 'lib/shared/message-utils.js'; import { getThreadTypeParentRequirement } from 'lib/shared/thread-utils.js'; +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; import type { RawMessageInfo, MessageData } from 'lib/types/message-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; -import { - threadTypes, - threadTypeIsCommunityRoot, -} from 'lib/types/thread-types-enum.js'; +import { threadTypes } from 'lib/types/thread-types-enum.js'; import { type ServerNewThinThreadRequest, type NewThreadResponse, diff --git a/keyserver/src/fetchers/user-fetchers.js b/keyserver/src/fetchers/user-fetchers.js --- a/keyserver/src/fetchers/user-fetchers.js +++ b/keyserver/src/fetchers/user-fetchers.js @@ -2,6 +2,7 @@ import invariant from 'invariant'; +import { communityThreadTypes } from 'lib/shared/threads/thread-specs.js'; import { hasMinCodeVersion, FUTURE_CODE_VERSION, @@ -13,7 +14,6 @@ userRelationshipStatus, } from 'lib/types/relationship-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; -import { communityThreadTypes } from 'lib/types/thread-types-enum.js'; import type { UserInfos, CurrentUserInfo, diff --git a/keyserver/src/updaters/role-updaters.js b/keyserver/src/updaters/role-updaters.js --- a/keyserver/src/updaters/role-updaters.js +++ b/keyserver/src/updaters/role-updaters.js @@ -8,9 +8,9 @@ getRolePermissionBlobs, getThreadPermissionBlobFromUserSurfacedPermissions, } from 'lib/permissions/thread-permissions.js'; +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import { type ThinThreadType, - threadTypeIsCommunityRoot, threadTypes, } from 'lib/types/thread-types-enum.js'; import type { ServerLegacyRoleInfo } from 'lib/types/thread-types.js'; diff --git a/lib/components/sync-community-store-handler.react.js b/lib/components/sync-community-store-handler.react.js --- a/lib/components/sync-community-store-handler.react.js +++ b/lib/components/sync-community-store-handler.react.js @@ -7,7 +7,7 @@ fetchCommunityInfosActionTypes, } from '../actions/community-actions.js'; import { isLoggedIn } from '../selectors/user-selectors.js'; -import { threadTypeIsCommunityRoot } from '../types/thread-types-enum.js'; +import { threadTypeIsCommunityRoot } from '../shared/threads/thread-specs.js'; import { FetchTimeout } from '../utils/errors.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; diff --git a/lib/hooks/sidebar-hooks.js b/lib/hooks/sidebar-hooks.js --- a/lib/hooks/sidebar-hooks.js +++ b/lib/hooks/sidebar-hooks.js @@ -7,7 +7,7 @@ import { childThreadInfos } from '../selectors/thread-selectors.js'; import { getMostRecentNonLocalMessageID } from '../shared/message-utils.js'; import { threadInChatList } from '../shared/thread-utils.js'; -import { threadTypeIsSidebar } from '../types/thread-types-enum.js'; +import { threadTypeIsSidebar } from '../shared/threads/thread-specs.js'; import type { SidebarInfo } from '../types/thread-types.js'; import { useSelector } from '../utils/redux-utils.js'; diff --git a/lib/permissions/add-users-permissions.js b/lib/permissions/add-users-permissions.js --- a/lib/permissions/add-users-permissions.js +++ b/lib/permissions/add-users-permissions.js @@ -2,10 +2,10 @@ import { primaryInviteLinksSelector } from '../selectors/invite-links-selectors.js'; import { useThreadHasPermission } from '../shared/thread-utils.js'; +import { threadTypeIsCommunityRoot } from '../shared/threads/thread-specs.js'; import type { InviteLink } from '../types/link-types.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; -import { threadTypeIsCommunityRoot } from '../types/thread-types-enum.js'; import { useSelector } from '../utils/redux-utils.js'; type AddUsersPermissions = { diff --git a/lib/permissions/prefixes.js b/lib/permissions/prefixes.js --- a/lib/permissions/prefixes.js +++ b/lib/permissions/prefixes.js @@ -1,5 +1,6 @@ // @flow +import { threadTypeIsSidebar } from '../shared/threads/thread-specs.js'; import { type ThreadPermission, type ThreadPermissionFilterPrefix, @@ -10,11 +11,7 @@ threadPermissionPropagationPrefixes, threadPermissionMembershipPrefixes, } from '../types/thread-permission-types.js'; -import { - threadTypes, - type ThreadType, - threadTypeIsSidebar, -} from '../types/thread-types-enum.js'; +import { threadTypes, type ThreadType } from '../types/thread-types-enum.js'; type ParsedThreadPermissionString = { +permission: ThreadPermission, diff --git a/lib/permissions/thread-permissions.js b/lib/permissions/thread-permissions.js --- a/lib/permissions/thread-permissions.js +++ b/lib/permissions/thread-permissions.js @@ -7,6 +7,10 @@ constructThreadPermissionString, includeThreadPermissionForThreadType, } from './prefixes.js'; +import { + threadTypeIsAnnouncementThread, + threadTypeIsCommunityRoot, +} from '../shared/threads/thread-specs.js'; import { configurableCommunityPermissions, threadPermissionFilterPrefixes, @@ -29,11 +33,9 @@ type ThinThreadType, type ThickThreadType, threadTypes, - threadTypeIsAnnouncementThread, threadTypeIsThick, assertThickThreadType, assertThinThreadType, - threadTypeIsCommunityRoot, } from '../types/thread-types-enum.js'; function permissionLookup( 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 @@ -27,6 +27,7 @@ type SidebarItem, } from '../shared/sidebar-item-utils.js'; import { threadInChatList, threadIsPending } from '../shared/thread-utils.js'; +import { threadTypeIsSidebar } from '../shared/threads/thread-specs.js'; import { messageTypes } from '../types/message-types-enum.js'; import { type ComposableMessageInfo, @@ -41,7 +42,6 @@ RawThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAppState } from '../types/redux-types.js'; -import { threadTypeIsSidebar } from '../types/thread-types-enum.js'; import type { AccountUserInfo, RelativeUserInfo, diff --git a/lib/selectors/nav-selectors.js b/lib/selectors/nav-selectors.js --- a/lib/selectors/nav-selectors.js +++ b/lib/selectors/nav-selectors.js @@ -5,6 +5,7 @@ import { useENSNames } from '../hooks/ens-cache.js'; import SearchIndex from '../shared/search-index.js'; +import { threadTypeIsPrivate } from '../shared/threads/thread-specs.js'; import type { Platform } from '../types/device-types.js'; import { type CalendarQuery, @@ -18,7 +19,6 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseNavInfo } from '../types/nav-types.js'; import type { BaseAppState } from '../types/redux-types.js'; -import { threadTypeIsPrivate } from '../types/thread-types-enum.js'; import type { UserInfo } from '../types/user-types.js'; import { getConfig } from '../utils/config.js'; import { useSelector } from '../utils/redux-utils.js'; 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 @@ -34,6 +34,15 @@ threadIsPending, getPendingThreadID, } from '../shared/thread-utils.js'; +import { + personalThreadTypes, + privateThreadTypes, + sidebarThreadTypes, + threadTypeIsCommunityRoot, + threadTypeIsPersonal, + threadTypeIsPrivate, + threadTypeIsSidebar, +} from '../shared/threads/thread-specs.js'; import type { ClientAvatar, ClientEmojiAvatar } from '../types/avatar-types'; import type { EntryInfo } from '../types/entry-types.js'; import type { MessageStore } from '../types/message-types.js'; @@ -46,15 +55,8 @@ import type { BaseAppState } from '../types/redux-types.js'; import { threadTypeIsThick, - threadTypeIsCommunityRoot, type ThreadType, threadTypes, - threadTypeIsSidebar, - threadTypeIsPrivate, - threadTypeIsPersonal, - personalThreadTypes, - privateThreadTypes, - sidebarThreadTypes, } from '../types/thread-types-enum.js'; import type { MixedRawThreadInfos, diff --git a/lib/selectors/user-selectors.js b/lib/selectors/user-selectors.js --- a/lib/selectors/user-selectors.js +++ b/lib/selectors/user-selectors.js @@ -9,6 +9,7 @@ getRandomDefaultEmojiAvatar, } from '../shared/avatar-utils.js'; import { getSingleOtherUser } from '../shared/thread-utils.js'; +import { threadTypeIsPersonal } from '../shared/threads/thread-specs.js'; import { type P2PMessageRecipient } from '../tunnelbroker/peer-to-peer-context.js'; import { type AuxUserInfos, @@ -26,7 +27,6 @@ } from '../types/minimally-encoded-thread-permissions-types.js'; import type { BaseAppState } from '../types/redux-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; -import { threadTypeIsPersonal } from '../types/thread-types-enum.js'; import type { RawThreadInfos } from '../types/thread-types.js'; import type { UserInfos, diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js --- a/lib/shared/avatar-utils.js +++ b/lib/shared/avatar-utils.js @@ -7,6 +7,10 @@ import { getETHAddressForUserInfo } from './account-utils.js'; import { selectedThreadColors } from './color-utils.js'; import { threadOtherMembers } from './thread-utils.js'; +import { + threadTypeIsPersonal, + threadTypeIsPrivate, +} from './threads/thread-specs.js'; import genesis from '../facts/genesis.js'; import { useENSAvatar } from '../hooks/ens-cache.js'; import { @@ -22,10 +26,6 @@ ThreadInfo, RawThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; -import { - threadTypeIsPersonal, - threadTypeIsPrivate, -} from '../types/thread-types-enum.js'; import type { UserInfos } from '../types/user-types.js'; const defaultAnonymousUserEmojiAvatar: ClientEmojiAvatar = { 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 @@ -4,6 +4,7 @@ import { markdownUserMentionRegexString } from './account-utils.js'; import SentencePrefixSearchIndex from './sentence-prefix-search-index.js'; +import { threadTypeIsSidebar } from './threads/thread-specs.js'; import { stringForUserExplicit } from './user-utils.js'; import { useENSNames } from '../hooks/ens-cache.js'; import { useUserSearchIndex } from '../selectors/nav-selectors.js'; @@ -12,7 +13,6 @@ ResolvedThreadInfo, ThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.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'; 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,10 +24,10 @@ 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 { 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'; +import { threadTypeIsSidebar } from '../threads/thread-specs.js'; type CreateSubThreadMessageSpec = MessageSpec< CreateSubthreadMessageData, 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 @@ -28,10 +28,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 { - threadTypeIsSidebar, - threadTypeIsThick, -} from '../../types/thread-types-enum.js'; +import { threadTypeIsThick } 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'; @@ -51,6 +48,7 @@ extractNewMentionedParentMembers, threadIsGroupChat, } from '../thread-utils.js'; +import { threadTypeIsSidebar } from '../threads/thread-specs.js'; /** * most of the markdown leaves contain `content` field 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 @@ -9,6 +9,7 @@ userIsMember, userHasDeviceList, } from './thread-utils.js'; +import { threadTypeIsSidebar } from './threads/thread-specs.js'; import { searchMessagesActionTypes, useSearchMessages as useSearchMessagesAction, @@ -40,7 +41,6 @@ import type { ThreadRolePermissionsBlob } from '../types/thread-permission-types.js'; import { type ThreadType, - threadTypeIsSidebar, threadTypeIsThick, } from '../types/thread-types-enum.js'; import type { 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 @@ -12,6 +12,7 @@ useThreadHasPermission, userIsMember, } from './thread-utils.js'; +import { threadTypeIsPersonal } from './threads/thread-specs.js'; import type { ChatMessageInfoItem } from '../selectors/chat-selectors.js'; import { chatMessageItemEngagementTargetMessageInfo } from '../shared/chat-message-item-utils.js'; import { messageTypes } from '../types/message-types-enum.js'; @@ -21,11 +22,7 @@ } 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, - threadTypeIsPersonal, -} from '../types/thread-types-enum.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 { 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,12 @@ import { extractUserMentionsFromText } from './mention-utils.js'; import { relationshipBlockedInEitherDirection } from './relationship-utils.js'; import type { SidebarItem } from './sidebar-item-utils.js'; +import { + threadTypeIsCommunityRoot, + threadTypeIsPersonal, + threadTypeIsPrivate, + threadTypeIsSidebar, +} from './threads/thread-specs.js'; import ashoat from '../facts/ashoat.js'; import genesis from '../facts/genesis.js'; import { useLoggedInUserInfo } from '../hooks/account-hooks.js'; @@ -76,14 +82,10 @@ import { type ThreadType, threadTypes, - threadTypeIsCommunityRoot, assertThreadType, threadTypeIsThick, assertThinThreadType, assertThickThreadType, - threadTypeIsSidebar, - threadTypeIsPrivate, - threadTypeIsPersonal, type ThinThreadType, } from '../types/thread-types-enum.js'; import type { diff --git a/lib/shared/threads/community-announcement-root-spec.js b/lib/shared/threads/community-announcement-root-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-announcement-root-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communityAnnouncementRootSpec: ThreadSpec = Object.freeze({ + traits: new Set(['community', 'announcement']), +}); + +export { communityAnnouncementRootSpec }; diff --git a/lib/shared/threads/community-open-announcement-subthread-spec.js b/lib/shared/threads/community-open-announcement-subthread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-open-announcement-subthread-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communityOpenAnnouncementSubthreadSpec: ThreadSpec = Object.freeze({ + traits: new Set(['communitySubthread', 'announcement']), +}); + +export { communityOpenAnnouncementSubthreadSpec }; diff --git a/lib/shared/threads/community-open-subthread-spec.js b/lib/shared/threads/community-open-subthread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-open-subthread-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communityOpenSubthreadSpec: ThreadSpec = Object.freeze({ + traits: new Set(['communitySubthread']), +}); + +export { communityOpenSubthreadSpec }; diff --git a/lib/shared/threads/community-root-spec.js b/lib/shared/threads/community-root-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-root-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communityRootSpec: ThreadSpec = Object.freeze({ + traits: new Set(['community']), +}); + +export { communityRootSpec }; diff --git a/lib/shared/threads/community-secret-announcement-subthread-spec.js b/lib/shared/threads/community-secret-announcement-subthread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-secret-announcement-subthread-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communitySecretAnnouncementSubthreadSpec: ThreadSpec = Object.freeze({ + traits: new Set(['communitySubthread', 'announcement']), +}); + +export { communitySecretAnnouncementSubthreadSpec }; diff --git a/lib/shared/threads/community-secret-subthread-spec.js b/lib/shared/threads/community-secret-subthread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/community-secret-subthread-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const communitySecretSubthreadSpec: ThreadSpec = Object.freeze({ + traits: new Set(['communitySubthread']), +}); + +export { communitySecretSubthreadSpec }; diff --git a/lib/shared/threads/genesis-personal-spec.js b/lib/shared/threads/genesis-personal-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/genesis-personal-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const genesisPersonalSpec: ThreadSpec = Object.freeze({ + traits: new Set(['personal']), +}); + +export { genesisPersonalSpec }; diff --git a/lib/shared/threads/genesis-private-spec.js b/lib/shared/threads/genesis-private-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/genesis-private-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const genesisPrivateSpec: ThreadSpec = Object.freeze({ + traits: new Set(['private']), +}); + +export { genesisPrivateSpec }; diff --git a/lib/shared/threads/genesis-spec.js b/lib/shared/threads/genesis-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/genesis-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const genesisSpec: ThreadSpec = Object.freeze({ + traits: new Set(['community', 'announcement']), +}); + +export { genesisSpec }; diff --git a/lib/shared/threads/local-spec.js b/lib/shared/threads/local-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/local-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const localSpec: ThreadSpec = Object.freeze({ + traits: new Set(), +}); + +export { localSpec }; diff --git a/lib/shared/threads/personal-spec.js b/lib/shared/threads/personal-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/personal-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const personalSpec: ThreadSpec = Object.freeze({ + traits: new Set(['personal']), +}); + +export { personalSpec }; diff --git a/lib/shared/threads/private-spec.js b/lib/shared/threads/private-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/private-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const privateSpec: ThreadSpec = Object.freeze({ + traits: new Set(['private']), +}); + +export { privateSpec }; diff --git a/lib/shared/threads/sidebar-spec.js b/lib/shared/threads/sidebar-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/sidebar-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const sidebarSpec: ThreadSpec = Object.freeze({ + traits: new Set(['sidebar']), +}); + +export { sidebarSpec }; diff --git a/lib/shared/threads/thick-sidebar-spec.js b/lib/shared/threads/thick-sidebar-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/thick-sidebar-spec.js @@ -0,0 +1,9 @@ +// @flow + +import type { ThreadSpec } from './thread-spec.js'; + +const thickSidebarSpec: ThreadSpec = Object.freeze({ + traits: new Set(['sidebar']), +}); + +export { thickSidebarSpec }; diff --git a/lib/shared/threads/thread-spec.js b/lib/shared/threads/thread-spec.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/thread-spec.js @@ -0,0 +1,13 @@ +// @flow + +export type ThreadTrait = + | 'sidebar' + | 'community' + | 'announcement' + | 'personal' + | 'private' + | 'communitySubthread'; + +export type ThreadSpec = { + +traits: $ReadOnlySet, +}; diff --git a/lib/shared/threads/thread-specs.js b/lib/shared/threads/thread-specs.js new file mode 100644 --- /dev/null +++ b/lib/shared/threads/thread-specs.js @@ -0,0 +1,95 @@ +// @flow + +import { communityAnnouncementRootSpec } from './community-announcement-root-spec.js'; +import { communityOpenAnnouncementSubthreadSpec } from './community-open-announcement-subthread-spec.js'; +import { communityOpenSubthreadSpec } from './community-open-subthread-spec.js'; +import { communityRootSpec } from './community-root-spec.js'; +import { communitySecretAnnouncementSubthreadSpec } from './community-secret-announcement-subthread-spec.js'; +import { communitySecretSubthreadSpec } from './community-secret-subthread-spec.js'; +import { genesisPersonalSpec } from './genesis-personal-spec.js'; +import { genesisPrivateSpec } from './genesis-private-spec.js'; +import { genesisSpec } from './genesis-spec.js'; +import { localSpec } from './local-spec.js'; +import { personalSpec } from './personal-spec.js'; +import { privateSpec } from './private-spec.js'; +import { sidebarSpec } from './sidebar-spec.js'; +import { thickSidebarSpec } from './thick-sidebar-spec.js'; +import type { ThreadSpec, ThreadTrait } from './thread-spec.js'; +import type { ThreadType } from '../../types/thread-types-enum.js'; +import { threadTypes } from '../../types/thread-types-enum.js'; +import { values } from '../../utils/objects.js'; + +export const threadSpecs: { + +[ThreadType]: ThreadSpec, +} = Object.freeze({ + [threadTypes.SIDEBAR]: sidebarSpec, + [threadTypes.GENESIS_PERSONAL]: genesisPersonalSpec, + [threadTypes.GENESIS_PRIVATE]: genesisPrivateSpec, + [threadTypes.COMMUNITY_ROOT]: communityRootSpec, + [threadTypes.COMMUNITY_ANNOUNCEMENT_ROOT]: communityAnnouncementRootSpec, + [threadTypes.COMMUNITY_OPEN_SUBTHREAD]: communityOpenSubthreadSpec, + [threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD]: + communityOpenAnnouncementSubthreadSpec, + [threadTypes.COMMUNITY_SECRET_SUBTHREAD]: communitySecretSubthreadSpec, + [threadTypes.COMMUNITY_SECRET_ANNOUNCEMENT_SUBTHREAD]: + communitySecretAnnouncementSubthreadSpec, + [threadTypes.GENESIS]: genesisSpec, + [threadTypes.LOCAL]: localSpec, + [threadTypes.PERSONAL]: personalSpec, + [threadTypes.PRIVATE]: privateSpec, + [threadTypes.THICK_SIDEBAR]: thickSidebarSpec, +}); + +let threadTypesByTrait = null; +export function getThreadTypesByTrait( + trait: ThreadTrait, +): $ReadOnlyArray { + if (!threadTypesByTrait) { + const threadTypesByTraitMutable: { [ThreadTrait]: Array } = {}; + for (const threadType of values(threadTypes)) { + for (const threadTraits of threadSpecs[threadType].traits) { + if (!threadTypesByTraitMutable[threadTraits]) { + threadTypesByTraitMutable[threadTraits] = []; + } + threadTypesByTraitMutable[threadTraits].push(threadType); + } + } + threadTypesByTrait = threadTypesByTraitMutable; + } + return threadTypesByTrait[trait]; +} + +export const communitySubthreads: $ReadOnlyArray = + getThreadTypesByTrait('communitySubthread'); + +export const communityThreadTypes: $ReadOnlyArray = + getThreadTypesByTrait('community'); +export function threadTypeIsCommunityRoot(threadType: ThreadType): boolean { + return communityThreadTypes.includes(threadType); +} + +export const announcementThreadTypes: $ReadOnlyArray = + getThreadTypesByTrait('announcement'); +export function threadTypeIsAnnouncementThread( + threadType: ThreadType, +): boolean { + return announcementThreadTypes.includes(threadType); +} + +export const sidebarThreadTypes: $ReadOnlyArray = + getThreadTypesByTrait('sidebar'); +export function threadTypeIsSidebar(threadType: ThreadType): boolean { + return sidebarThreadTypes.includes(threadType); +} + +export const personalThreadTypes: $ReadOnlyArray = + getThreadTypesByTrait('personal'); +export function threadTypeIsPersonal(threadType: ThreadType): boolean { + return personalThreadTypes.includes(threadType); +} + +export const privateThreadTypes: $ReadOnlyArray = + getThreadTypesByTrait('private'); +export function threadTypeIsPrivate(threadType: ThreadType): boolean { + return privateThreadTypes.includes(threadType); +} 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 @@ -139,63 +139,3 @@ export const threadTypeValidator: TRefinement = tNumEnum( 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([ - threadTypes.SIDEBAR, - threadTypes.THICK_SIDEBAR, -]); - -export const personalThreadTypes: $ReadOnlyArray = Object.freeze([ - threadTypes.PERSONAL, - threadTypes.GENESIS_PERSONAL, -]); - -export const privateThreadTypes: $ReadOnlyArray = Object.freeze([ - threadTypes.PRIVATE, - threadTypes.GENESIS_PRIVATE, -]); - -export function threadTypeIsCommunityRoot(threadType: ThreadType): boolean { - return communityThreadTypes.includes(threadType); -} - -export function threadTypeIsAnnouncementThread( - threadType: ThreadType, -): boolean { - return announcementThreadTypes.includes(threadType); -} - -export function threadTypeIsSidebar(threadType: ThreadType): boolean { - return sidebarThreadTypes.includes(threadType); -} - -export function threadTypeIsPersonal(threadType: ThreadType): boolean { - return personalThreadTypes.includes(threadType); -} - -export function threadTypeIsPrivate(threadType: ThreadType): boolean { - return privateThreadTypes.includes(threadType); -} diff --git a/lib/utils/drawer-utils.react.js b/lib/utils/drawer-utils.react.js --- a/lib/utils/drawer-utils.react.js +++ b/lib/utils/drawer-utils.react.js @@ -4,12 +4,12 @@ import { values } from './objects.js'; import { threadInFilterList, threadIsChannel } from '../shared/thread-utils.js'; +import { communitySubthreads } from '../shared/threads/thread-specs.js'; import type { ResolvedThreadInfo, ThreadInfo, RawThreadInfo, } from '../types/minimally-encoded-thread-permissions-types.js'; -import { communitySubthreads } from '../types/thread-types-enum.js'; type WritableCommunityDrawerItemData = { threadInfo: ResolvedThreadInfo, diff --git a/native/avatars/thread-avatar.react.js b/native/avatars/thread-avatar.react.js --- a/native/avatars/thread-avatar.react.js +++ b/native/avatars/thread-avatar.react.js @@ -5,6 +5,10 @@ import { useAvatarForThread } from 'lib/hooks/avatar-hooks.js'; import { useResolvedThreadAvatar } from 'lib/shared/avatar-utils.js'; import { getSingleOtherUser, getCommunity } from 'lib/shared/thread-utils.js'; +import { + threadTypeIsPersonal, + threadTypeIsPrivate, +} from 'lib/shared/threads/thread-specs.js'; import type { AvatarSize } from 'lib/types/avatar-types.js'; import type { CommunityInfo } from 'lib/types/community-types.js'; import type { @@ -12,10 +16,6 @@ ResolvedThreadInfo, RawThreadInfo, } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { - threadTypeIsPersonal, - threadTypeIsPrivate, -} from 'lib/types/thread-types-enum.js'; import Avatar from './avatar.react.js'; import { useSelector } from '../redux/redux-utils.js'; diff --git a/native/chat/message-list.react.js b/native/chat/message-list.react.js --- a/native/chat/message-list.react.js +++ b/native/chat/message-list.react.js @@ -8,9 +8,9 @@ import { chatMessageItemKey } from 'lib/shared/chat-message-item-utils.js'; import { useFetchMessages } from 'lib/shared/message-utils.js'; +import { threadTypeIsPersonal } from 'lib/shared/threads/thread-specs.js'; import { useWatchThread } from 'lib/shared/watch-thread-utils.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { threadTypeIsPersonal } from 'lib/types/thread-types-enum.js'; import ChatList from './chat-list.react.js'; import type { ChatNavigationProp } from './chat.react.js'; 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 @@ -38,6 +38,10 @@ viewerIsMember, } from 'lib/shared/thread-utils.js'; import threadWatcher from 'lib/shared/thread-watcher.js'; +import { + threadTypeIsPersonal, + threadTypeIsSidebar, +} from 'lib/shared/threads/thread-specs.js'; import type { RelativeMemberInfo, ResolvedThreadInfo, @@ -45,11 +49,7 @@ } 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 { - threadTypeIsSidebar, - threadTypeIsThick, - threadTypeIsPersonal, -} from 'lib/types/thread-types-enum.js'; +import { threadTypeIsThick } from 'lib/types/thread-types-enum.js'; import type { UserInfos } from 'lib/types/user-types.js'; import { useResolvedOptionalThreadInfo, 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,11 +4,8 @@ import * as React from 'react'; import { StyleSheet } from 'react-native'; -import { - threadTypes, - type ThreadType, - threadTypeIsSidebar, -} from 'lib/types/thread-types-enum.js'; +import { threadTypeIsSidebar } from 'lib/shared/threads/thread-specs.js'; +import { threadTypes, type ThreadType } from 'lib/types/thread-types-enum.js'; import SWMansionIcon from './swmansion-icon.react.js'; diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -52,6 +52,7 @@ threadIsPending, threadIsPendingSidebar, } from 'lib/shared/thread-utils.js'; +import { threadTypeIsSidebar } from 'lib/shared/threads/thread-specs.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; import type { Media, @@ -77,9 +78,8 @@ } from 'lib/types/report-types.js'; import { threadTypeIsThick, - threadTypeIsSidebar, + type ThreadType, } from 'lib/types/thread-types-enum.js'; -import type { ThreadType } from 'lib/types/thread-types-enum.js'; import { type ClientNewThinThreadRequest, type NewThreadResult, diff --git a/native/navigation/community-drawer-content.react.js b/native/navigation/community-drawer-content.react.js --- a/native/navigation/community-drawer-content.react.js +++ b/native/navigation/community-drawer-content.react.js @@ -18,11 +18,11 @@ import { useLegacyAshoatKeyserverCall } from 'lib/keyserver-conn/legacy-keyserver-call.js'; import { communityThreadSelector } from 'lib/selectors/thread-selectors.js'; import { viewerIsMember } from 'lib/shared/thread-utils.js'; +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import type { ClientCommunityInfoWithCommunityName, ClientFetchNativeDrawerAndDirectoryInfosResponse, } from 'lib/types/community-types.js'; -import { threadTypeIsCommunityRoot } from 'lib/types/thread-types-enum.js'; import { createRecursiveDrawerItemsData, useAppendCommunitySuffix, diff --git a/native/navigation/community-drawer-item.react.js b/native/navigation/community-drawer-item.react.js --- a/native/navigation/community-drawer-item.react.js +++ b/native/navigation/community-drawer-item.react.js @@ -3,7 +3,7 @@ import * as React from 'react'; import { View, TouchableOpacity } from 'react-native'; -import { threadTypeIsCommunityRoot } from 'lib/types/thread-types-enum.js'; +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; import { ExpandButton, ExpandButtonDisabled } from './expand-buttons.react.js'; diff --git a/native/utils/drawer-utils.react.js b/native/utils/drawer-utils.react.js --- a/native/utils/drawer-utils.react.js +++ b/native/utils/drawer-utils.react.js @@ -1,7 +1,7 @@ // @flow +import { threadTypeIsCommunityRoot } from 'lib/shared/threads/thread-specs.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { threadTypeIsCommunityRoot } from 'lib/types/thread-types-enum.js'; import type { CommunityDrawerItemData } from 'lib/utils/drawer-utils.react.js'; import type { TextStyle } from '../types/styles.js'; diff --git a/web/avatars/thread-avatar.react.js b/web/avatars/thread-avatar.react.js --- a/web/avatars/thread-avatar.react.js +++ b/web/avatars/thread-avatar.react.js @@ -5,16 +5,16 @@ import { useAvatarForThread } from 'lib/hooks/avatar-hooks.js'; import { useResolvedThreadAvatar } from 'lib/shared/avatar-utils.js'; import { getSingleOtherUser, getCommunity } from 'lib/shared/thread-utils.js'; +import { + threadTypeIsPersonal, + threadTypeIsPrivate, +} from 'lib/shared/threads/thread-specs.js'; import type { AvatarSize } from 'lib/types/avatar-types.js'; import type { CommunityInfo } from 'lib/types/community-types.js'; import type { ThreadInfo, RawThreadInfo, } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { - threadTypeIsPersonal, - threadTypeIsPrivate, -} from 'lib/types/thread-types-enum.js'; import Avatar from './avatar.react.js'; import { useSelector } from '../redux/redux-utils.js'; diff --git a/web/chat/chat-message-list.react.js b/web/chat/chat-message-list.react.js --- a/web/chat/chat-message-list.react.js +++ b/web/chat/chat-message-list.react.js @@ -17,8 +17,8 @@ threadIsPending, threadOtherMembers, } from 'lib/shared/thread-utils.js'; +import { threadTypeIsPersonal } from 'lib/shared/threads/thread-specs.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { threadTypeIsPersonal } from 'lib/types/thread-types-enum.js'; import { defaultMaxTextAreaHeight, editBoxHeight } from './chat-constants.js'; import css from './chat-message-list.css'; diff --git a/web/chat/thread-list-provider.js b/web/chat/thread-list-provider.js --- a/web/chat/thread-list-provider.js +++ b/web/chat/thread-list-provider.js @@ -17,7 +17,7 @@ threadIsPending, useIsThreadInChatList, } from 'lib/shared/thread-utils.js'; -import { threadTypeIsSidebar } from 'lib/types/thread-types-enum.js'; +import { threadTypeIsSidebar } from 'lib/shared/threads/thread-specs.js'; import { useSelector } from '../redux/redux-utils.js'; import { 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 @@ -22,13 +22,15 @@ useThreadHasPermission, viewerIsMember, } from 'lib/shared/thread-utils.js'; -import { type DMLeaveThreadOperation } from 'lib/types/dm-ops.js'; -import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import { threadPermissions } from 'lib/types/thread-permission-types.js'; import { threadTypeIsPersonal, threadTypeIsPrivate, threadTypeIsSidebar, +} from 'lib/shared/threads/thread-specs.js'; +import { type DMLeaveThreadOperation } from 'lib/types/dm-ops.js'; +import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; +import { threadPermissions } from 'lib/types/thread-permission-types.js'; +import { threadTypeIsThick, thickThreadTypes, } from 'lib/types/thread-types-enum.js'; 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 @@ -53,6 +53,7 @@ threadIsPending, threadIsPendingSidebar, } from 'lib/shared/thread-utils.js'; +import { threadTypeIsSidebar } from 'lib/shared/threads/thread-specs.js'; import type { CalendarQuery } from 'lib/types/entry-types.js'; import type { MediaMission, @@ -72,10 +73,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 { - threadTypeIsSidebar, - threadTypeIsThick, -} from 'lib/types/thread-types-enum.js'; +import { threadTypeIsThick } from 'lib/types/thread-types-enum.js'; import type { ThreadType } from 'lib/types/thread-types-enum.js'; import { type ClientNewThinThreadRequest, diff --git a/web/modals/threads/settings/thread-settings-modal.react.js b/web/modals/threads/settings/thread-settings-modal.react.js --- a/web/modals/threads/settings/thread-settings-modal.react.js +++ b/web/modals/threads/settings/thread-settings-modal.react.js @@ -16,13 +16,11 @@ threadUIName, useThreadHasPermission, } from 'lib/shared/thread-utils.js'; +import { threadTypeIsPersonal } from 'lib/shared/threads/thread-specs.js'; import type { ThreadInfo } 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 { - threadTypeIsPersonal, - threadTypes, -} from 'lib/types/thread-types-enum.js'; +import { threadTypes } from 'lib/types/thread-types-enum.js'; import { type ThreadChanges } from 'lib/types/thread-types.js'; import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js';