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 @@ -126,12 +126,7 @@ import { pendingThreadIDRegex } from '../utils/validation-utils.js'; function threadHasPermission( - threadInfo: ?( - | LegacyThreadInfo - | ThreadInfo - | LegacyRawThreadInfo - | RawThreadInfo - ), + threadInfo: ?(ThreadInfo | LegacyRawThreadInfo | RawThreadInfo), permission: ThreadPermission, ): boolean { if (!threadInfo) { @@ -149,12 +144,7 @@ } function viewerIsMember( - threadInfo: ?( - | LegacyThreadInfo - | ThreadInfo - | LegacyRawThreadInfo - | RawThreadInfo - ), + threadInfo: ?(ThreadInfo | LegacyRawThreadInfo | RawThreadInfo), ): boolean { return !!( threadInfo && @@ -163,20 +153,13 @@ ); } -function threadIsInHome( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), -): boolean { +function threadIsInHome(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return !!(threadInfo && threadInfo.currentUser.subscription.home); } // Can have messages function threadInChatList( - threadInfo: ?( - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo - ), + threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo), ): boolean { return ( viewerIsMember(threadInfo) && @@ -184,32 +167,26 @@ ); } -function threadIsTopLevel( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), -): boolean { +function threadIsTopLevel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return threadInChatList(threadInfo) && threadIsChannel(threadInfo); } -function threadIsChannel( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), -): boolean { +function threadIsChannel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return !!(threadInfo && threadInfo.type !== threadTypes.SIDEBAR); } -function threadIsSidebar( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), -): boolean { +function threadIsSidebar(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean { return threadInfo?.type === threadTypes.SIDEBAR; } function threadInBackgroundChatList( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), ): boolean { return threadInChatList(threadInfo) && !threadIsInHome(threadInfo); } function threadInHomeChatList( - threadInfo: ?(RawThreadInfo | LegacyThreadInfo | ThreadInfo), + threadInfo: ?(RawThreadInfo | ThreadInfo), ): boolean { return threadInChatList(threadInfo) && threadIsInHome(threadInfo); } @@ -217,12 +194,7 @@ // Can have Calendar entries, // does appear as a top-level entity in the thread list function threadInFilterList( - threadInfo: ?( - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo - ), + threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo), ): boolean { return ( threadInChatList(threadInfo) && @@ -232,12 +204,7 @@ } function userIsMember( - threadInfo: ?( - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo - ), + threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo), userID: string, ): boolean { if (!threadInfo) { @@ -267,7 +234,7 @@ } function threadMembersWithoutAddedAshoat< - T: LegacyRawThreadInfo | RawThreadInfo | LegacyThreadInfo | ThreadInfo, + T: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, >(threadInfo: T): $PropertyType { if (threadInfo.community !== genesis.id) { return threadInfo.members; @@ -282,11 +249,7 @@ } function threadOrParentThreadIsGroupChat( - threadInfo: - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo, + threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, ) { return threadMembersWithoutAddedAshoat(threadInfo).length > 2; } @@ -300,11 +263,7 @@ } function getSingleOtherUser( - threadInfo: - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo, + threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, viewerID: ?string, ): ?string { if (!viewerID) { @@ -547,7 +506,7 @@ type SharedCreatePendingSidebarInput = { +sourceMessageInfo: ComposableMessageInfo | RobotextMessageInfo, - +parentThreadInfo: LegacyThreadInfo | ThreadInfo, + +parentThreadInfo: ThreadInfo, +loggedInUserInfo: LoggedInUserInfo, }; @@ -1008,7 +967,7 @@ } function getCurrentUser( - threadInfo: LegacyRawThreadInfo | LegacyThreadInfo, + threadInfo: LegacyRawThreadInfo, viewerID: ?string, userInfos: UserInfos, ): ThreadCurrentUserInfo { @@ -1048,11 +1007,7 @@ } function threadIsWithBlockedUserOnly( - threadInfo: - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo, + threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, checkOnlyViewerBlock?: boolean, @@ -1084,11 +1039,7 @@ } function threadFrozenDueToBlock( - threadInfo: - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo, + threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, ): boolean { @@ -1096,7 +1047,7 @@ } function threadFrozenDueToViewerBlock( - threadInfo: RawThreadInfo | LegacyThreadInfo | ThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, viewerID: ?string, userInfos: UserInfos, ): boolean { @@ -1112,7 +1063,7 @@ function memberIsAdmin( memberInfo: RelativeMemberInfo | MemberInfo, - threadInfo: RawThreadInfo | LegacyThreadInfo | ThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): boolean { return !!( memberInfo.role && roleIsAdminRole(threadInfo.roles[memberInfo.role]) @@ -1138,7 +1089,6 @@ threadInfo: ?( | LegacyRawThreadInfo | RawThreadInfo - | LegacyThreadInfo | ThreadInfo | ServerThreadInfo ), @@ -1150,11 +1100,7 @@ } function threadOrParentThreadHasAdminRole( - threadInfo: - | LegacyRawThreadInfo - | RawThreadInfo - | LegacyThreadInfo - | ThreadInfo, + threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, ) { return ( threadMembersWithoutAddedAshoat(threadInfo).filter(member => @@ -1255,7 +1201,7 @@ } } -function useWatchThread(threadInfo: ?(LegacyThreadInfo | ThreadInfo)) { +function useWatchThread(threadInfo: ?ThreadInfo) { const dispatchActionPromise = useDispatchActionPromise(); const callFetchMostRecentMessages = useFetchMostRecentMessages(); @@ -1398,7 +1344,6 @@ | ServerThreadInfo | LegacyRawThreadInfo | RawThreadInfo - | LegacyThreadInfo | ThreadInfo, memberID: string, permission: ThreadPermission, @@ -1416,7 +1361,7 @@ } function useCanCreateSidebarFromMessage( - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, messageInfo: ComposableMessageInfo | RobotextMessageInfo, ): boolean { const messageCreatorUserInfo = useSelector( @@ -1445,7 +1390,7 @@ } function useSidebarExistsOrCanBeCreated( - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, messageItem: ChatMessageInfoItem, ): boolean { const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( @@ -1455,9 +1400,7 @@ return !!messageItem.threadCreatedFromMessage || canCreateSidebarFromMessage; } -function checkIfDefaultMembersAreVoiced( - threadInfo: LegacyThreadInfo | ThreadInfo, -): boolean { +function checkIfDefaultMembersAreVoiced(threadInfo: ThreadInfo): boolean { const defaultRoleID = Object.keys(threadInfo.roles).find( roleID => threadInfo.roles[roleID].isDefault, ); @@ -1612,7 +1555,7 @@ } function removeMemberFromThread( - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, memberInfo: RelativeMemberInfo, dispatchActionPromise: DispatchActionPromise, removeUserFromThreadServerCall: ( @@ -1632,7 +1575,7 @@ function getAvailableThreadMemberActions( memberInfo: RelativeMemberInfo, - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, canEdit: ?boolean = true, ): $ReadOnlyArray<'change_role' | 'remove_user'> { const role = memberInfo.role; @@ -1698,7 +1641,7 @@ } function threadInfoInsideCommunity( - threadInfo: RawThreadInfo | LegacyThreadInfo | ThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, communityID: string, ): boolean { return threadInfo.community === communityID || threadInfo.id === communityID; @@ -1709,7 +1652,7 @@ }; function useRoleMemberCountsForCommunity( - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, ): RoleAndMemberCount { return React.useMemo(() => { const roleIDsToNames: { [string]: string } = {}; @@ -1780,16 +1723,14 @@ }, [threadInfo]); } -function communityOrThreadNoun( - threadInfo: RawThreadInfo | LegacyThreadInfo | ThreadInfo, -): string { +function communityOrThreadNoun(threadInfo: RawThreadInfo | ThreadInfo): string { return threadTypeIsCommunityRoot(threadInfo.type) ? 'community' : threadNoun(threadInfo.type, threadInfo.parentThreadID); } function getThreadsToDeleteText( - threadInfo: RawThreadInfo | LegacyThreadInfo | ThreadInfo, + threadInfo: RawThreadInfo | ThreadInfo, ): string { return `${ threadTypeIsCommunityRoot(threadInfo.type)