diff --git a/lib/components/chat-mention-provider.react.js b/lib/components/chat-mention-provider.react.js --- a/lib/components/chat-mention-provider.react.js +++ b/lib/components/chat-mention-provider.react.js @@ -5,16 +5,13 @@ import genesis from '../facts/genesis.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; import SentencePrefixSearchIndex from '../shared/sentence-prefix-search-index.js'; -import type { - MinimallyEncodedResolvedThreadInfo, - MinimallyEncodedThreadInfo, -} from '../types/minimally-encoded-thread-permissions-types.js'; +import type { MinimallyEncodedResolvedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; import type { ChatMentionCandidates, ChatMentionCandidatesObj, ResolvedThreadInfo, - LegacyThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; import { useResolvedThreadInfosObj } from '../utils/entity-helpers.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -24,7 +21,7 @@ }; export type ChatMentionContextType = { +getChatMentionSearchIndex: ( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ) => SentencePrefixSearchIndex, +communityThreadIDForGenesisThreads: { +[id: string]: string }, +chatMentionCandidatesObj: ChatMentionCandidatesObj, @@ -46,7 +43,7 @@ const searchIndices = useChatMentionSearchIndex(chatMentionCandidatesObj); const getChatMentionSearchIndex = React.useCallback( - (threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo) => { + (threadInfo: ThreadInfo) => { if (threadInfo.community === genesis.id) { return searchIndices[communityThreadIDForGenesisThreads[threadInfo.id]]; } diff --git a/lib/hooks/chat-mention-hooks.js b/lib/hooks/chat-mention-hooks.js --- a/lib/hooks/chat-mention-hooks.js +++ b/lib/hooks/chat-mention-hooks.js @@ -8,10 +8,9 @@ type ChatMentionContextType, } from '../components/chat-mention-provider.react.js'; import genesis from '../facts/genesis.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { ChatMentionCandidates, - LegacyThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; function useChatMentionContext(): ChatMentionContextType { @@ -22,7 +21,7 @@ } function useThreadChatMentionCandidates( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): ChatMentionCandidates { const { communityThreadIDForGenesisThreads, chatMentionCandidatesObj } = useChatMentionContext(); diff --git a/lib/hooks/child-threads.js b/lib/hooks/child-threads.js --- a/lib/hooks/child-threads.js +++ b/lib/hooks/child-threads.js @@ -14,15 +14,12 @@ import { childThreadInfos } from '../selectors/thread-selectors.js'; import { threadInChatList } from '../shared/thread-utils.js'; import threadWatcher from '../shared/thread-watcher.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; -import type { LegacyThreadInfo, RawThreadInfo } from '../types/thread-types.js'; +import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; type ThreadFilter = { - +predicate?: ( - thread: LegacyThreadInfo | MinimallyEncodedThreadInfo, - ) => boolean, + +predicate?: (thread: ThreadInfo) => boolean, +searchText?: string, }; @@ -43,9 +40,7 @@ }, [childThreads, predicate]); const filterSubchannels = React.useCallback( - ( - thread: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), - ) => { + (thread: ?(RawThreadInfo | ThreadInfo)) => { const candidateThreadID = thread?.id; if (!candidateThreadID) { return false; diff --git a/lib/hooks/promote-sidebar.react.js b/lib/hooks/promote-sidebar.react.js --- a/lib/hooks/promote-sidebar.react.js +++ b/lib/hooks/promote-sidebar.react.js @@ -13,16 +13,15 @@ threadIsSidebar, } from '../shared/thread-utils.js'; import type { LoadingStatus } from '../types/loading-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import type { ThreadInfo } from '../types/thread-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; function canPromoteSidebar( - sidebarThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, - parentThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + sidebarThreadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, ): boolean { if (!threadIsSidebar(sidebarThreadInfo)) { return false; @@ -46,7 +45,7 @@ }; function usePromoteSidebar( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, onError?: () => mixed, ): PromoteSidebarType { const dispatchActionPromise = useDispatchActionPromise(); @@ -57,10 +56,9 @@ const loadingStatus = useSelector(loadingStatusSelector); const { parentThreadID } = threadInfo; - const parentThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo = - useSelector(state => - parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, - ); + const parentThreadInfo: ?ThreadInfo = useSelector(state => + parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, + ); const canPromote = canPromoteSidebar(threadInfo, parentThreadInfo); diff --git a/lib/hooks/relationship-prompt.js b/lib/hooks/relationship-prompt.js --- a/lib/hooks/relationship-prompt.js +++ b/lib/hooks/relationship-prompt.js @@ -8,12 +8,11 @@ updateRelationshipsActionTypes, } from '../actions/relationship-actions.js'; import { getSingleOtherUser } from '../shared/thread-utils.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { type RelationshipAction, relationshipActions, } from '../types/relationship-types.js'; -import type { LegacyThreadInfo } from '../types/thread-types.js'; +import type { ThreadInfo } from '../types/thread-types.js'; import type { UserInfo } from '../types/user-types.js'; import { useDispatchActionPromise, @@ -34,7 +33,7 @@ }; function useRelationshipPrompt( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, onErrorCallback?: () => void, pendingPersonalThreadUserInfo?: ?UserInfo, ): RelationshipPromptData { diff --git a/lib/hooks/search-threads.js b/lib/hooks/search-threads.js --- a/lib/hooks/search-threads.js +++ b/lib/hooks/search-threads.js @@ -10,11 +10,10 @@ import { sidebarInfoSelector } from '../selectors/thread-selectors.js'; import { threadIsChannel } from '../shared/thread-utils.js'; import type { SetState } from '../types/hook-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { SidebarInfo, - LegacyThreadInfo, RawThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -32,7 +31,7 @@ }; function useSearchThreads( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, childThreadInfos: $ReadOnlyArray, ): SearchThreadsResult { const [searchState, setSearchState] = React.useState({ @@ -92,7 +91,7 @@ } function useSearchSidebars( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): SearchThreadsResult { const childThreadInfos = useSelector( state => sidebarInfoSelector(state)[threadInfo.id] ?? [], @@ -101,12 +100,11 @@ } function useSearchSubchannels( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): SearchThreadsResult { const filterFunc = React.useCallback( - ( - thread: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo | RawThreadInfo), - ) => threadIsChannel(thread) && thread?.parentThreadID === threadInfo.id, + (thread: ?(ThreadInfo | RawThreadInfo)) => + threadIsChannel(thread) && thread?.parentThreadID === threadInfo.id, [threadInfo.id], ); const childThreadInfos = useFilteredChatListData(filterFunc); diff --git a/lib/hooks/toggle-unread-status.js b/lib/hooks/toggle-unread-status.js --- a/lib/hooks/toggle-unread-status.js +++ b/lib/hooks/toggle-unread-status.js @@ -10,12 +10,11 @@ SetThreadUnreadStatusPayload, SetThreadUnreadStatusRequest, } from '../types/activity-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; -import type { LegacyThreadInfo } from '../types/thread-types.js'; +import type { ThreadInfo } from '../types/thread-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; function useToggleUnreadStatus( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, mostRecentNonLocalMessage: ?string, afterAction: () => void, ): () => void { diff --git a/lib/shared/ancestor-threads.js b/lib/shared/ancestor-threads.js --- a/lib/shared/ancestor-threads.js +++ b/lib/shared/ancestor-threads.js @@ -6,12 +6,14 @@ ancestorThreadInfos, } from '../selectors/thread-selectors.js'; import { threadIsPending } from '../shared/thread-utils.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import { + type LegacyThreadInfo, + type ThreadInfo, +} from '../types/thread-types.js'; import { useSelector } from '../utils/redux-utils.js'; function useAncestorThreads( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): $ReadOnlyArray { return useSelector(state => { if (!threadIsPending(threadInfo.id)) { 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 @@ -16,9 +16,8 @@ ResolvedClientAvatar, GenericUserInfoWithAvatar, } from '../types/avatar-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; -import type { LegacyThreadInfo, RawThreadInfo } from '../types/thread-types.js'; +import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js'; import type { UserInfos } from '../types/user-types.js'; import { useSelector } from '../utils/redux-utils.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; @@ -271,7 +270,7 @@ } function getUserAvatarForThread( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, ): ClientAvatar { @@ -297,8 +296,8 @@ } function getAvatarForThread( - thread: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, - containingThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + thread: RawThreadInfo | ThreadInfo, + containingThreadInfo: ?ThreadInfo, ): ClientAvatar { if (thread.avatar) { return thread.avatar; @@ -313,9 +312,7 @@ return getDefaultAvatar(thread.id, thread.color); } -function useAvatarForThread( - thread: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, -): ClientAvatar { +function useAvatarForThread(thread: RawThreadInfo | ThreadInfo): ClientAvatar { const containingThreadID = thread.containingThreadID; const containingThreadInfo = useSelector(state => containingThreadID ? threadInfoSelector(state)[containingThreadID] : null, diff --git a/lib/shared/edit-messages-utils.js b/lib/shared/edit-messages-utils.js --- a/lib/shared/edit-messages-utils.js +++ b/lib/shared/edit-messages-utils.js @@ -14,9 +14,8 @@ RawMessageInfo, } from '../types/message-types'; import { messageTypes } from '../types/message-types-enum.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import { type ThreadInfo } from '../types/thread-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -49,7 +48,7 @@ } function useCanEditMessage( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo, ): boolean { const currentUserInfo = useSelector(state => state.currentUserInfo); diff --git a/lib/shared/inline-engagement-utils.js b/lib/shared/inline-engagement-utils.js --- a/lib/shared/inline-engagement-utils.js +++ b/lib/shared/inline-engagement-utils.js @@ -1,12 +1,9 @@ // @flow import type { ReactionInfo } from '../selectors/chat-selectors.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; -import type { LegacyThreadInfo } from '../types/thread-types.js'; +import type { ThreadInfo } from '../types/thread-types.js'; -function getInlineEngagementSidebarText( - threadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, -): string { +function getInlineEngagementSidebarText(threadInfo: ?ThreadInfo): string { if (!threadInfo) { return ''; } 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,16 +4,13 @@ import SentencePrefixSearchIndex from './sentence-prefix-search-index.js'; import { threadOtherMembers } from './thread-utils.js'; import { stringForUserExplicit } from './user-utils.js'; -import type { - MinimallyEncodedResolvedThreadInfo, - MinimallyEncodedThreadInfo, -} from '../types/minimally-encoded-thread-permissions-types.js'; +import type { MinimallyEncodedResolvedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; import type { - LegacyThreadInfo, ResolvedThreadInfo, ChatMentionCandidates, RelativeMemberInfo, + ThreadInfo, } from '../types/thread-types.js'; import { idSchemaRegex, chatNameMaxLength } from '../utils/validation-utils.js'; @@ -164,8 +161,8 @@ } function getUserMentionsCandidates( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, - parentThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, ): $ReadOnlyArray { if (threadInfo.type !== threadTypes.SIDEBAR) { return threadInfo.members; diff --git a/lib/shared/message-utils.js b/lib/shared/message-utils.js --- a/lib/shared/message-utils.js +++ b/lib/shared/message-utils.js @@ -41,8 +41,11 @@ RawReactionMessageInfo, ReactionMessageInfo, } from '../types/messages/reaction.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; -import type { RawThreadInfo, LegacyThreadInfo } from '../types/thread-types.js'; +import type { + RawThreadInfo, + LegacyThreadInfo, + ThreadInfo, +} from '../types/thread-types.js'; import type { UserInfos } from '../types/user-types.js'; import { extractKeyserverIDFromID } from '../utils/action-utils.js'; import { @@ -76,8 +79,8 @@ function robotextForMessageInfo( messageInfo: RobotextMessageInfo, - threadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, - parentThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + threadInfo: ?ThreadInfo, + parentThreadInfo: ?ThreadInfo, ): EntityText { const messageSpec = messageSpecs[messageInfo.type]; invariant( @@ -411,8 +414,8 @@ | RobotextMessageInfo | ReactionMessageInfo | EditMessageInfo, - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, - parentThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, markdownRules: ParserRules, ): EntityText { const { messageTitle } = messageSpecs[messageInfo.type]; @@ -498,7 +501,7 @@ }; function useMessagePreview( originalMessageInfo: ?MessageInfo, - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, markdownRules: ParserRules, ): ?MessagePreviewResult { let messageInfo; @@ -680,7 +683,7 @@ function isInvalidPinSourceForThread( messageInfo: RawMessageInfo | MessageInfo, - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): boolean { const isValidPinSource = !isInvalidPinSource(messageInfo); const isFirstMessageInSidebar = threadInfo.sourceMessageID === messageInfo.id; diff --git a/lib/shared/notif-utils.js b/lib/shared/notif-utils.js --- a/lib/shared/notif-utils.js +++ b/lib/shared/notif-utils.js @@ -17,10 +17,9 @@ } from '../types/message-types.js'; import type { CreateSidebarMessageInfo } from '../types/messages/create-sidebar.js'; import type { TextMessageInfo } from '../types/messages/text.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { NotifTexts, ResolvedNotifTexts } from '../types/notif-types.js'; import { type ThreadType, threadTypes } from '../types/thread-types-enum.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import type { LegacyThreadInfo, ThreadInfo } from '../types/thread-types.js'; import type { RelativeUserInfo, UserInfo } from '../types/user-types.js'; import { prettyDate } from '../utils/date-utils.js'; import type { GetENSNames } from '../utils/ens-helpers.js'; @@ -109,7 +108,7 @@ type NotifTextsForSubthreadCreationInput = { +creator: RelativeUserInfo, +threadType: ThreadType, - +parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + +parentThreadInfo: ThreadInfo, +childThreadName: ?string, +childThreadUIName: string | ThreadEntity, }; @@ -151,7 +150,7 @@ +createSidebarMessageInfo: CreateSidebarMessageInfo, +sidebarSourceMessageInfo?: ?SidebarSourceMessageInfo, +firstSidebarMessageInfo?: ?TextMessageInfo, - +threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + +threadInfo: ThreadInfo, +params: NotificationTextsParams, }; function notifTextsForSidebarCreation( diff --git a/lib/shared/reaction-utils.js b/lib/shared/reaction-utils.js --- a/lib/shared/reaction-utils.js +++ b/lib/shared/reaction-utils.js @@ -12,9 +12,8 @@ RobotextMessageInfo, ComposableMessageInfo, } from '../types/message-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import type { ThreadInfo } from '../types/thread-types.js'; import { useSelector } from '../utils/redux-utils.js'; function useViewerAlreadySelectedMessageReactions( @@ -75,7 +74,7 @@ } function useCanCreateReactionFromMessage( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo, ): boolean { const targetMessageCreatorRelationship = useSelector( 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 @@ -24,11 +24,10 @@ MessageListData, } from '../selectors/chat-selectors.js'; import type { MessageInfo, RawMessageInfo } from '../types/message-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; import { type ThreadType, threadTypes } from '../types/thread-types-enum.js'; -import { type LegacyThreadInfo } from '../types/thread-types.js'; +import { type ThreadInfo } from '../types/thread-types.js'; import type { AccountUserInfo, UserListItem, @@ -59,8 +58,8 @@ +searchIndex: SearchIndex, +excludeUserIDs: $ReadOnlyArray, +includeServerSearchUsers?: $ReadOnlyArray, - +inputParentThreadInfo?: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, - +inputCommunityThreadInfo?: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + +inputParentThreadInfo?: ?ThreadInfo, + +inputCommunityThreadInfo?: ?ThreadInfo, +threadType?: ?ThreadType, }): UserListItem[] { const communityThreadInfo = 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 @@ -94,6 +94,7 @@ type UserProfileThreadInfo, type RelativeMemberInfo, type RawThreadInfo, + type ThreadInfo, } from '../types/thread-types.js'; import { updateTypes } from '../types/update-types-enum.js'; import { type ClientUpdateInfo } from '../types/update-types.js'; @@ -123,7 +124,7 @@ import { pendingThreadIDRegex } from '../utils/validation-utils.js'; function threadHasPermission( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), + threadInfo: ?(ThreadInfo | RawThreadInfo), permission: ThreadPermission, ): boolean { if (!threadInfo) { @@ -140,9 +141,7 @@ return permissionLookup(threadInfo.currentUser.permissions, permission); } -function viewerIsMember( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function viewerIsMember(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return !!( threadInfo && threadInfo.currentUser.role !== null && @@ -150,48 +149,38 @@ ); } -function threadIsInHome( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function threadIsInHome(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return !!(threadInfo && threadInfo.currentUser.subscription.home); } // Can have messages -function threadInChatList( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function threadInChatList(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return ( viewerIsMember(threadInfo) && threadHasPermission(threadInfo, threadPermissions.VISIBLE) ); } -function threadIsTopLevel( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function threadIsTopLevel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return threadInChatList(threadInfo) && threadIsChannel(threadInfo); } -function threadIsChannel( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function threadIsChannel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return !!(threadInfo && threadInfo.type !== threadTypes.SIDEBAR); } -function threadIsSidebar( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), -): boolean { +function threadIsSidebar(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return threadInfo?.type === threadTypes.SIDEBAR; } function threadInBackgroundChatList( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), ): boolean { return threadInChatList(threadInfo) && !threadIsInHome(threadInfo); } function threadInHomeChatList( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), ): boolean { return threadInChatList(threadInfo) && threadIsInHome(threadInfo); } @@ -199,7 +188,7 @@ // Can have Calendar entries, // does appear as a top-level entity in the thread list function threadInFilterList( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), ): boolean { return ( threadInChatList(threadInfo) && @@ -209,7 +198,7 @@ } function userIsMember( - threadInfo: ?(LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), userID: string, ): boolean { if (!threadInfo) { @@ -238,9 +227,9 @@ ); } -function threadMembersWithoutAddedAshoat< - T: LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo, ->(threadInfo: T): $PropertyType { +function threadMembersWithoutAddedAshoat( + threadInfo: T, +): $PropertyType { if (threadInfo.community !== genesis.id) { return threadInfo.members; } @@ -249,14 +238,12 @@ ); } -function threadIsGroupChat( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, -): boolean { +function threadIsGroupChat(threadInfo: ThreadInfo): boolean { return threadInfo.members.length > 2; } function threadOrParentThreadIsGroupChat( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ) { return threadMembersWithoutAddedAshoat(threadInfo).length > 2; } @@ -270,7 +257,7 @@ } function getSingleOtherUser( - threadInfo: LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, ): ?string { if (!viewerID) { @@ -332,7 +319,7 @@ +viewerID: string, +threadType: ThreadType, +members: $ReadOnlyArray, - +parentThreadInfo?: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + +parentThreadInfo?: ?ThreadInfo, +threadColor?: ?string, +name?: ?string, +sourceMessageID?: string, @@ -477,7 +464,7 @@ // Returns map from user ID to AccountUserInfo function extractMentionedMembers( text: string, - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): Map { const memberMap = memberLowercaseUsernameMap(threadInfo.members); const mentions = extractUserMentionsFromText(text); @@ -496,8 +483,8 @@ // they will be automatically added to that sidebar function extractNewMentionedParentMembers( messageText: string, - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, - parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ThreadInfo, ): AccountUserInfo[] { const mentionedMembersOfParent = extractMentionedMembers( messageText, @@ -513,7 +500,7 @@ type SharedCreatePendingSidebarInput = { +sourceMessageInfo: ComposableMessageInfo | RobotextMessageInfo, - +parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + +parentThreadInfo: ThreadInfo, +loggedInUserInfo: LoggedInUserInfo, }; @@ -685,7 +672,7 @@ } type CreateRealThreadParameters = { - +threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + +threadInfo: ThreadInfo, +dispatchActionPromise: DispatchActionPromise, +createNewThread: ClientNewThreadRequest => Promise, +sourceMessageID: ?string, @@ -870,9 +857,7 @@ return rawThreadInfo; } -function threadUIName( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, -): string | ThreadEntity { +function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity { if (threadInfo.name) { return firstLine(threadInfo.name); } @@ -991,7 +976,7 @@ } function threadIsWithBlockedUserOnly( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, checkOnlyViewerBlock?: boolean, @@ -1023,7 +1008,7 @@ } function threadFrozenDueToBlock( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, ): boolean { @@ -1031,7 +1016,7 @@ } function threadFrozenDueToViewerBlock( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, ): boolean { @@ -1047,7 +1032,7 @@ function memberIsAdmin( memberInfo: RelativeMemberInfo | MemberInfo, - threadInfo: LegacyThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): boolean { return !!( memberInfo.role && roleIsAdminRole(threadInfo.roles[memberInfo.role]) @@ -1070,12 +1055,7 @@ } function threadHasAdminRole( - threadInfo: ?( - | RawThreadInfo - | LegacyThreadInfo - | ServerThreadInfo - | MinimallyEncodedThreadInfo - ), + threadInfo: ?(RawThreadInfo | ThreadInfo | ServerThreadInfo), ): boolean { if (!threadInfo) { return false; @@ -1084,7 +1064,7 @@ } function threadOrParentThreadHasAdminRole( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ) { return ( threadMembersWithoutAddedAshoat(threadInfo).filter(member => @@ -1185,9 +1165,7 @@ } } -function useWatchThread( - threadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, -) { +function useWatchThread(threadInfo: ?ThreadInfo) { const dispatchActionPromise = useDispatchActionPromise(); const callFetchMostRecentMessages = useFetchMostRecentMessages(); @@ -1220,10 +1198,10 @@ }; type ExistingThreadInfoFinder = ( params: ExistingThreadInfoFinderParams, -) => ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo; +) => ?ThreadInfo; // TODO (atul): Parameterize function once `createPendingThread` is updated. function useExistingThreadInfoFinder( - baseThreadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + baseThreadInfo: ?ThreadInfo, ): ExistingThreadInfoFinder { const threadInfos = useSelector(threadInfoSelector); const loggedInUserInfo = useLoggedInUserInfo(); @@ -1233,9 +1211,7 @@ pendingToRealizedThreadIDsSelector(state.threadStore.threadInfos), ); return React.useCallback( - ( - params: ExistingThreadInfoFinderParams, - ): ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo => { + (params: ExistingThreadInfoFinderParams): ?ThreadInfo => { if (!baseThreadInfo) { return null; } @@ -1336,11 +1312,7 @@ } function threadMemberHasPermission( - threadInfo: - | ServerThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | MinimallyEncodedThreadInfo, + threadInfo: ServerThreadInfo | RawThreadInfo | ThreadInfo, memberID: string, permission: ThreadPermission, ): boolean { @@ -1357,7 +1329,7 @@ } function useCanCreateSidebarFromMessage( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, messageInfo: ComposableMessageInfo | RobotextMessageInfo, ): boolean { const messageCreatorUserInfo = useSelector( @@ -1386,7 +1358,7 @@ } function useSidebarExistsOrCanBeCreated( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, messageItem: ChatMessageInfoItem, ): boolean { const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( @@ -1396,9 +1368,7 @@ return !!messageItem.threadCreatedFromMessage || canCreateSidebarFromMessage; } -function checkIfDefaultMembersAreVoiced( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, -): boolean { +function checkIfDefaultMembersAreVoiced(threadInfo: ThreadInfo): boolean { const defaultRoleID = Object.keys(threadInfo.roles).find( roleID => threadInfo.roles[roleID].isDefault, ); @@ -1424,7 +1394,7 @@ parentThreadInfo: | ?ServerThreadInfo | RawThreadInfo - | LegacyThreadInfo + | ThreadInfo | MinimallyEncodedThreadInfo, threadType: ThreadType, ): ?string { @@ -1441,11 +1411,7 @@ } function getCommunity( - parentThreadInfo: - | ?ServerThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | MinimallyEncodedThreadInfo, + parentThreadInfo: ?ServerThreadInfo | RawThreadInfo | ThreadInfo, ): ?string { if (!parentThreadInfo) { return null; @@ -1551,7 +1517,7 @@ } function removeMemberFromThread( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, memberInfo: RelativeMemberInfo, dispatchActionPromise: DispatchActionPromise, removeUserFromThreadServerCall: ( @@ -1570,7 +1536,7 @@ } function switchMemberAdminRoleInThread( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, memberInfo: RelativeMemberInfo, isCurrentlyAdmin: boolean, dispatchActionPromise: DispatchActionPromise, @@ -1603,7 +1569,7 @@ function getAvailableThreadMemberActions( memberInfo: RelativeMemberInfo, - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, canEdit: ?boolean = true, ): $ReadOnlyArray<'change_role' | 'remove_user'> { const role = memberInfo.role; @@ -1638,11 +1604,11 @@ } function patchThreadInfoToIncludeMentionedMembersOfParent( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, - parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ThreadInfo, messageText: string, viewerID: string, -): LegacyThreadInfo | MinimallyEncodedThreadInfo { +): ThreadInfo { const members: UserIDAndUsername[] = threadInfo.members .map(({ id, username }) => username ? ({ id, username }: UserIDAndUsername) : null, @@ -1669,7 +1635,7 @@ } function threadInfoInsideCommunity( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, communityID: string, ): boolean { return threadInfo.community === communityID || threadInfo.id === communityID; @@ -1680,7 +1646,7 @@ }; function useRoleMemberCountsForCommunity( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): RoleAndMemberCount { return React.useMemo(() => { const roleIDsToNames: { [string]: string } = {}; @@ -1746,16 +1712,14 @@ }, [threadInfo]); } -function communityOrThreadNoun( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, -): string { +function communityOrThreadNoun(threadInfo: RawThreadInfo | ThreadInfo): string { return threadTypeIsCommunityRoot(threadInfo.type) ? 'community' : threadNoun(threadInfo.type, threadInfo.parentThreadID); } function getThreadsToDeleteText( - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): string { return `${ threadTypeIsCommunityRoot(threadInfo.type) diff --git a/lib/shared/user-utils.js b/lib/shared/user-utils.js --- a/lib/shared/user-utils.js +++ b/lib/shared/user-utils.js @@ -2,11 +2,10 @@ import { memberHasAdminPowers } from './thread-utils.js'; import { useENSNames } from '../hooks/ens-cache.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { RawThreadInfo, ServerThreadInfo, - LegacyThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; import type { UserInfo } from '../types/user-types.js'; import { useSelector } from '../utils/redux-utils.js'; @@ -34,11 +33,7 @@ } function useKeyserverAdmin( - community: - | LegacyThreadInfo - | RawThreadInfo - | ServerThreadInfo - | MinimallyEncodedThreadInfo, + community: ThreadInfo | RawThreadInfo | ServerThreadInfo, ): ?UserInfo { const userInfos = useSelector(state => state.userStore.userInfos); // This hack only works as long as there is only one admin diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -20,6 +20,7 @@ MinimallyEncodedRelativeMemberInfo, MinimallyEncodedResolvedThreadInfo, MinimallyEncodedRoleInfo, + MinimallyEncodedThreadInfo, } from './minimally-encoded-thread-permissions-types.js'; import { type ThreadSubscription, @@ -185,6 +186,8 @@ pinnedCount: t.maybe(t.Number), }); +export type ThreadInfo = LegacyThreadInfo | MinimallyEncodedThreadInfo; + export type ResolvedThreadInfo = { +id: string, +type: 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 @@ -2,19 +2,16 @@ import { values } from './objects.js'; import { threadInFilterList, threadIsChannel } from '../shared/thread-utils.js'; -import type { - MinimallyEncodedResolvedThreadInfo, - MinimallyEncodedThreadInfo, -} from '../types/minimally-encoded-thread-permissions-types.js'; +import type { MinimallyEncodedResolvedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { communitySubthreads } from '../types/thread-types-enum.js'; import type { - LegacyThreadInfo, ResolvedThreadInfo, RawThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; type WritableCommunityDrawerItemData = { - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, itemChildren: $ReadOnlyArray>, hasSubchannelsButton: boolean, labelStyle: T, @@ -25,9 +22,7 @@ function createRecursiveDrawerItemsData( childThreadInfosMap: { - +[id: string]: $ReadOnlyArray< - LegacyThreadInfo | MinimallyEncodedThreadInfo, - >, + +[id: string]: $ReadOnlyArray, }, communities: $ReadOnlyArray< ResolvedThreadInfo | MinimallyEncodedResolvedThreadInfo, @@ -68,10 +63,10 @@ return result; } -function threadHasSubchannels( - threadInfo: T, +function threadHasSubchannels( + threadInfo: ThreadInfo, childThreadInfosMap: { - +[id: string]: $ReadOnlyArray, + +[id: string]: $ReadOnlyArray, }, ): boolean { if (!childThreadInfosMap[threadInfo.id]?.length) { @@ -108,10 +103,7 @@ function filterThreadIDsBelongingToCommunity( communityID: string, threadInfosObj: { - +[id: string]: - | LegacyThreadInfo - | RawThreadInfo - | MinimallyEncodedThreadInfo, + +[id: string]: RawThreadInfo | ThreadInfo, }, ): $ReadOnlySet { const threadInfos = values(threadInfosObj); diff --git a/lib/utils/entity-helpers.js b/lib/utils/entity-helpers.js --- a/lib/utils/entity-helpers.js +++ b/lib/utils/entity-helpers.js @@ -9,18 +9,16 @@ entityTextToRawString, } from './entity-text.js'; import type { UseENSNamesOptions } from '../hooks/ens-cache.js'; -import type { - MinimallyEncodedResolvedThreadInfo, - MinimallyEncodedThreadInfo, -} from '../types/minimally-encoded-thread-permissions-types.js'; +import type { MinimallyEncodedResolvedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import type { LegacyThreadInfo, ResolvedThreadInfo, + ThreadInfo, } from '../types/thread-types.js'; import { values } from '../utils/objects.js'; function useResolvedThreadInfos( - threadInfos: $ReadOnlyArray, + threadInfos: $ReadOnlyArray, options?: ?UseENSNamesOptions, ): $ReadOnlyArray { const entityText = React.useMemo( @@ -117,7 +115,7 @@ } function useResolvedThreadInfo( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, ): ResolvedThreadInfo | MinimallyEncodedResolvedThreadInfo { const resolutionInput = React.useMemo(() => [threadInfo], [threadInfo]); const [resolvedThreadInfo] = useResolvedThreadInfos(resolutionInput); @@ -125,7 +123,7 @@ } function useResolvedOptionalThreadInfo( - threadInfo: ?LegacyThreadInfo | ?MinimallyEncodedThreadInfo, + threadInfo: ?ThreadInfo, ): ?ResolvedThreadInfo | ?MinimallyEncodedResolvedThreadInfo { const resolutionInput = React.useMemo( () => (threadInfo ? [threadInfo] : []), diff --git a/lib/utils/entity-text.js b/lib/utils/entity-text.js --- a/lib/utils/entity-text.js +++ b/lib/utils/entity-text.js @@ -9,13 +9,12 @@ import { useENSNames, type UseENSNamesOptions } from '../hooks/ens-cache.js'; import { threadNoun } from '../shared/thread-utils.js'; import { stringForUser } from '../shared/user-utils.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { type ThreadType, threadTypes, threadTypeValidator, } from '../types/thread-types-enum.js'; -import type { LegacyThreadInfo, RawThreadInfo } from '../types/thread-types.js'; +import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js'; import { basePluralize } from '../utils/text-utils.js'; export type UserEntity = { @@ -135,23 +134,17 @@ type EntityTextThreadInput = | { +display: 'uiName', - +threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + +threadInfo: ThreadInfo, } | { +display?: 'shortName', - +threadInfo: - | LegacyThreadInfo - | RawThreadInfo - | MinimallyEncodedThreadInfo, + +threadInfo: RawThreadInfo | ThreadInfo, +subchannel?: ?boolean, +possessive?: ?boolean, } | { +display: 'alwaysDisplayShortName', - +threadInfo: - | LegacyThreadInfo - | RawThreadInfo - | MinimallyEncodedThreadInfo, + +threadInfo: RawThreadInfo | ThreadInfo, +possessive?: ?boolean, } | { diff --git a/lib/utils/role-utils.js b/lib/utils/role-utils.js --- a/lib/utils/role-utils.js +++ b/lib/utils/role-utils.js @@ -4,16 +4,15 @@ import { useSelector } from './redux-utils.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { configurableCommunityPermissions, type ThreadRolePermissionsBlob, type UserSurfacedPermission, } from '../types/thread-permission-types.js'; import type { - LegacyThreadInfo, RoleInfo, RelativeMemberInfo, + ThreadInfo, } from '../types/thread-types'; import { threadTypes } from '../types/thread-types-enum.js'; @@ -57,7 +56,7 @@ } function useRolesFromCommunityThreadInfo( - threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: ThreadInfo, memberInfos: $ReadOnlyArray, ): $ReadOnlyMap { // Our in-code system has chat-specific roles, while the diff --git a/lib/utils/toggle-pin-utils.js b/lib/utils/toggle-pin-utils.js --- a/lib/utils/toggle-pin-utils.js +++ b/lib/utils/toggle-pin-utils.js @@ -3,13 +3,12 @@ import { isInvalidPinSourceForThread } from '../shared/message-utils.js'; import { threadHasPermission } from '../shared/thread-utils.js'; import type { RawMessageInfo, MessageInfo } from '../types/message-types.js'; -import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadPermissions } from '../types/thread-permission-types.js'; -import type { RawThreadInfo, LegacyThreadInfo } from '../types/thread-types.js'; +import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js'; function canToggleMessagePin( messageInfo: RawMessageInfo | MessageInfo, - threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): boolean { const isValidMessage = !isInvalidPinSourceForThread(messageInfo, threadInfo); const hasManagePinsPermission = threadHasPermission(