Page MenuHomePhabricator

D10641.diff
No OneTemporary

D10641.diff

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
@@ -96,7 +96,6 @@
ChangeThreadSettingsPayload,
UserProfileThreadInfo,
RelativeMemberInfo,
- ThreadInfo,
MixedRawThreadInfos,
} from '../types/thread-types.js';
import { updateTypes } from '../types/update-types-enum.js';
@@ -127,7 +126,12 @@
import { pendingThreadIDRegex } from '../utils/validation-utils.js';
function threadHasPermission(
- threadInfo: ?(ThreadInfo | LegacyRawThreadInfo | RawThreadInfo),
+ threadInfo: ?(
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ ),
permission: ThreadPermission,
): boolean {
if (!threadInfo) {
@@ -145,7 +149,12 @@
}
function viewerIsMember(
- threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo),
+ threadInfo: ?(
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ ),
): boolean {
return !!(
threadInfo &&
@@ -154,13 +163,20 @@
);
}
-function threadIsInHome(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean {
+function threadIsInHome(
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
+): boolean {
return !!(threadInfo && threadInfo.currentUser.subscription.home);
}
// Can have messages
function threadInChatList(
- threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo),
+ threadInfo: ?(
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ ),
): boolean {
return (
viewerIsMember(threadInfo) &&
@@ -168,26 +184,32 @@
);
}
-function threadIsTopLevel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean {
+function threadIsTopLevel(
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
+): boolean {
return threadInChatList(threadInfo) && threadIsChannel(threadInfo);
}
-function threadIsChannel(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean {
+function threadIsChannel(
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
+): boolean {
return !!(threadInfo && threadInfo.type !== threadTypes.SIDEBAR);
}
-function threadIsSidebar(threadInfo: ?(RawThreadInfo | ThreadInfo)): boolean {
+function threadIsSidebar(
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
+): boolean {
return threadInfo?.type === threadTypes.SIDEBAR;
}
function threadInBackgroundChatList(
- threadInfo: ?(RawThreadInfo | ThreadInfo),
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
): boolean {
return threadInChatList(threadInfo) && !threadIsInHome(threadInfo);
}
function threadInHomeChatList(
- threadInfo: ?(RawThreadInfo | ThreadInfo),
+ threadInfo: ?(RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo),
): boolean {
return threadInChatList(threadInfo) && threadIsInHome(threadInfo);
}
@@ -195,7 +217,12 @@
// Can have Calendar entries,
// does appear as a top-level entity in the thread list
function threadInFilterList(
- threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo),
+ threadInfo: ?(
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ ),
): boolean {
return (
threadInChatList(threadInfo) &&
@@ -205,7 +232,12 @@
}
function userIsMember(
- threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo | ThreadInfo),
+ threadInfo: ?(
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ ),
userID: string,
): boolean {
if (!threadInfo) {
@@ -235,7 +267,11 @@
}
function threadMembersWithoutAddedAshoat<
- T: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ T:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
>(threadInfo: T): $PropertyType<T, 'members'> {
if (threadInfo.community !== genesis.id) {
return threadInfo.members;
@@ -245,12 +281,18 @@
);
}
-function threadIsGroupChat(threadInfo: ThreadInfo): boolean {
+function threadIsGroupChat(
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+): boolean {
return threadInfo.members.length > 2;
}
function threadOrParentThreadIsGroupChat(
- threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ threadInfo:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
) {
return threadMembersWithoutAddedAshoat(threadInfo).length > 2;
}
@@ -264,7 +306,11 @@
}
function getSingleOtherUser(
- threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ threadInfo:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
viewerID: ?string,
): ?string {
if (!viewerID) {
@@ -326,7 +372,7 @@
+viewerID: string,
+threadType: ThreadType,
+members: $ReadOnlyArray<UserIDAndUsername>,
- +parentThreadInfo?: ?ThreadInfo,
+ +parentThreadInfo?: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo),
+threadColor?: ?string,
+name?: ?string,
+sourceMessageID?: string,
@@ -411,7 +457,7 @@
}
type PendingPersonalThread = {
- +threadInfo: ThreadInfo,
+ +threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+pendingPersonalThreadUserInfo: UserInfo,
};
@@ -471,7 +517,7 @@
// Returns map from user ID to AccountUserInfo
function extractMentionedMembers(
text: string,
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
): Map<string, AccountUserInfo> {
const memberMap = memberLowercaseUsernameMap(threadInfo.members);
const mentions = extractUserMentionsFromText(text);
@@ -490,8 +536,8 @@
// they will be automatically added to that sidebar
function extractNewMentionedParentMembers(
messageText: string,
- threadInfo: ThreadInfo,
- parentThreadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
): AccountUserInfo[] {
const mentionedMembersOfParent = extractMentionedMembers(
messageText,
@@ -507,7 +553,7 @@
type SharedCreatePendingSidebarInput = {
+sourceMessageInfo: ComposableMessageInfo | RobotextMessageInfo,
- +parentThreadInfo: ThreadInfo,
+ +parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+loggedInUserInfo: LoggedInUserInfo,
};
@@ -679,7 +725,7 @@
}
type CreateRealThreadParameters = {
- +threadInfo: ThreadInfo,
+ +threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+dispatchActionPromise: DispatchActionPromise,
+createNewThread: ClientNewThreadRequest => Promise<NewThreadResult>,
+sourceMessageID: ?string,
@@ -868,7 +914,9 @@
: rawThreadInfo;
}
-function threadUIName(threadInfo: ThreadInfo): string | ThreadEntity {
+function threadUIName(
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+): string | ThreadEntity {
if (threadInfo.name) {
return firstLine(threadInfo.name);
}
@@ -902,7 +950,7 @@
viewerID: ?string,
userInfos: UserInfos,
): MinimallyEncodedThreadInfo {
- let threadInfo: ThreadInfo;
+ let threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo;
if (rawThreadInfo.minimallyEncoded) {
threadInfo = {
minimallyEncoded: true,
@@ -1013,7 +1061,11 @@
}
function threadIsWithBlockedUserOnly(
- threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ threadInfo:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
viewerID: ?string,
userInfos: UserInfos,
checkOnlyViewerBlock?: boolean,
@@ -1045,7 +1097,11 @@
}
function threadFrozenDueToBlock(
- threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ threadInfo:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
viewerID: ?string,
userInfos: UserInfos,
): boolean {
@@ -1053,7 +1109,7 @@
}
function threadFrozenDueToViewerBlock(
- threadInfo: RawThreadInfo | ThreadInfo,
+ threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo,
viewerID: ?string,
userInfos: UserInfos,
): boolean {
@@ -1069,7 +1125,7 @@
function memberIsAdmin(
memberInfo: RelativeMemberInfo | MemberInfo,
- threadInfo: RawThreadInfo | ThreadInfo,
+ threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo,
): boolean {
return !!(
memberInfo.role && roleIsAdminRole(threadInfo.roles[memberInfo.role])
@@ -1095,7 +1151,8 @@
threadInfo: ?(
| LegacyRawThreadInfo
| RawThreadInfo
- | ThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
| ServerThreadInfo
),
): boolean {
@@ -1106,7 +1163,11 @@
}
function threadOrParentThreadHasAdminRole(
- threadInfo: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo,
+ threadInfo:
+ | LegacyRawThreadInfo
+ | RawThreadInfo
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
) {
return (
threadMembersWithoutAddedAshoat(threadInfo).filter(member =>
@@ -1207,7 +1268,9 @@
}
}
-function useWatchThread(threadInfo: ?ThreadInfo) {
+function useWatchThread(
+ threadInfo: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo),
+) {
const dispatchActionPromise = useDispatchActionPromise();
const callFetchMostRecentMessages = useFetchMostRecentMessages();
@@ -1240,10 +1303,10 @@
};
type ExistingThreadInfoFinder = (
params: ExistingThreadInfoFinderParams,
-) => ?ThreadInfo;
+) => ?(LegacyThreadInfo | MinimallyEncodedThreadInfo);
// TODO (atul): Parameterize function once `createPendingThread` is updated.
function useExistingThreadInfoFinder(
- baseThreadInfo: ?ThreadInfo,
+ baseThreadInfo: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo),
): ExistingThreadInfoFinder {
const threadInfos = useSelector(threadInfoSelector);
const loggedInUserInfo = useLoggedInUserInfo();
@@ -1253,7 +1316,9 @@
pendingToRealizedThreadIDsSelector(state.threadStore.threadInfos),
);
return React.useCallback(
- (params: ExistingThreadInfoFinderParams): ?ThreadInfo => {
+ (
+ params: ExistingThreadInfoFinderParams,
+ ): ?(LegacyThreadInfo | MinimallyEncodedThreadInfo) => {
if (!baseThreadInfo) {
return null;
}
@@ -1358,7 +1423,8 @@
| ServerThreadInfo
| LegacyRawThreadInfo
| RawThreadInfo
- | ThreadInfo,
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
memberID: string,
permission: ThreadPermission,
): boolean {
@@ -1375,7 +1441,7 @@
}
function useCanCreateSidebarFromMessage(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
messageInfo: ComposableMessageInfo | RobotextMessageInfo,
): boolean {
const messageCreatorUserInfo = useSelector(
@@ -1404,7 +1470,7 @@
}
function useSidebarExistsOrCanBeCreated(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
messageItem: ChatMessageInfoItem,
): boolean {
const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage(
@@ -1414,7 +1480,9 @@
return !!messageItem.threadCreatedFromMessage || canCreateSidebarFromMessage;
}
-function checkIfDefaultMembersAreVoiced(threadInfo: ThreadInfo): boolean {
+function checkIfDefaultMembersAreVoiced(
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+): boolean {
const defaultRoleID = Object.keys(threadInfo.roles).find(
roleID => threadInfo.roles[roleID].isDefault,
);
@@ -1441,7 +1509,8 @@
| ?ServerThreadInfo
| LegacyRawThreadInfo
| RawThreadInfo
- | ThreadInfo,
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
threadType: ThreadType,
): ?string {
if (!parentThreadInfo) {
@@ -1461,7 +1530,8 @@
| ?ServerThreadInfo
| LegacyRawThreadInfo
| RawThreadInfo
- | ThreadInfo,
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo,
): ?string {
if (!parentThreadInfo) {
return null;
@@ -1479,7 +1549,7 @@
function getThreadListSearchResults(
chatListData: $ReadOnlyArray<ChatThreadItem>,
searchText: string,
- threadFilter: ThreadInfo => boolean,
+ threadFilter: (LegacyThreadInfo | MinimallyEncodedThreadInfo) => boolean,
threadSearchResults: $ReadOnlySet<string>,
usersSearchResults: $ReadOnlyArray<GlobalAccountUserInfo>,
loggedInUserInfo: ?LoggedInUserInfo,
@@ -1567,7 +1637,7 @@
}
function removeMemberFromThread(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
memberInfo: RelativeMemberInfo,
dispatchActionPromise: DispatchActionPromise,
removeUserFromThreadServerCall: (
@@ -1587,7 +1657,7 @@
function getAvailableThreadMemberActions(
memberInfo: RelativeMemberInfo,
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
canEdit: ?boolean = true,
): $ReadOnlyArray<'change_role' | 'remove_user'> {
const role = memberInfo.role;
@@ -1622,11 +1692,11 @@
}
function patchThreadInfoToIncludeMentionedMembersOfParent(
- threadInfo: ThreadInfo,
- parentThreadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ parentThreadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
messageText: string,
viewerID: string,
-): ThreadInfo {
+): LegacyThreadInfo | MinimallyEncodedThreadInfo {
const members: UserIDAndUsername[] = threadInfo.members
.map(({ id, username }) =>
username ? ({ id, username }: UserIDAndUsername) : null,
@@ -1653,7 +1723,7 @@
}
function threadInfoInsideCommunity(
- threadInfo: RawThreadInfo | ThreadInfo,
+ threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo,
communityID: string,
): boolean {
return threadInfo.community === communityID || threadInfo.id === communityID;
@@ -1664,7 +1734,7 @@
};
function useRoleMemberCountsForCommunity(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
): RoleAndMemberCount {
return React.useMemo(() => {
const roleIDsToNames: { [string]: string } = {};
@@ -1701,7 +1771,7 @@
// the set of permission literals for each role to user-facing permission enums
// to help pre-populate the permission checkboxes when editing roles.
function useRoleUserSurfacedPermissions(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
): RoleUserSurfacedPermissions {
return React.useMemo(() => {
const roleNamesToPermissions: { [string]: Set<UserSurfacedPermission> } =
@@ -1735,14 +1805,16 @@
}, [threadInfo]);
}
-function communityOrThreadNoun(threadInfo: RawThreadInfo | ThreadInfo): string {
+function communityOrThreadNoun(
+ threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo,
+): string {
return threadTypeIsCommunityRoot(threadInfo.type)
? 'community'
: threadNoun(threadInfo.type, threadInfo.parentThreadID);
}
function getThreadsToDeleteText(
- threadInfo: RawThreadInfo | ThreadInfo,
+ threadInfo: RawThreadInfo | LegacyThreadInfo | MinimallyEncodedThreadInfo,
): string {
return `${
threadTypeIsCommunityRoot(threadInfo.type)
@@ -1777,13 +1849,19 @@
}
if (isViewerProfile) {
- const privateThreadInfo: ?ThreadInfo = privateThreadInfos[0];
+ const privateThreadInfo: ?(
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ ) = privateThreadInfos[0];
return privateThreadInfo ? { threadInfo: privateThreadInfo } : null;
}
if (usersWithPersonalThread.has(userID)) {
- const personalThreadInfo: ?ThreadInfo = personalThreadInfos.find(
+ const personalThreadInfo: ?(
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ ) = personalThreadInfos.find(
threadInfo =>
userID === getSingleOtherUser(threadInfo, loggedInUserInfo.id),
);

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 5:16 PM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591128
Default Alt Text
D10641.diff (15 KB)

Event Timeline