Skip to content

Commit

Permalink
[lib] Reintroduce RawThreadInfo (`[Legacy/MinimallyEncoded]RawThrea…
Browse files Browse the repository at this point in the history
…dInfo`)

Summary:
Similar to D10068 and D10072 and D10074, but for `RawThreadInfo`.

---

Depends on D10077

Test Plan: `flow`/CI/etc.

Reviewers: ashoat, ginsu, tomek, rohan

Reviewed By: ginsu

Differential Revision: https://phab.comm.dev/D10078
  • Loading branch information
atulsmadhugiri committed Nov 29, 2023
1 parent 819fb9e commit bfd6ef1
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 339 deletions.
16 changes: 3 additions & 13 deletions lib/hooks/child-threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import { useGlobalThreadSearchIndex } from '../selectors/nav-selectors.js';
import { childThreadInfos } from '../selectors/thread-selectors.js';
import { threadInChatList } from '../shared/thread-utils.js';
import threadWatcher from '../shared/thread-watcher.js';
import type {
MinimallyEncodedThreadInfo,
MinimallyEncodedRawThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { ThreadInfo, LegacyRawThreadInfo } from '../types/thread-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type { ThreadInfo, RawThreadInfo } from '../types/thread-types.js';
import { useDispatchActionPromise } from '../utils/action-utils.js';
import { useSelector } from '../utils/redux-utils.js';

Expand All @@ -44,14 +41,7 @@ function useFilteredChildThreads(
}, [childThreads, predicate]);

const filterSubchannels = React.useCallback(
(
thread: ?(
| ThreadInfo
| LegacyRawThreadInfo
| MinimallyEncodedThreadInfo
| MinimallyEncodedRawThreadInfo
),
) => {
(thread: ?(ThreadInfo | RawThreadInfo | MinimallyEncodedThreadInfo)) => {
const candidateThreadID = thread?.id;
if (!candidateThreadID) {
return false;
Expand Down
17 changes: 4 additions & 13 deletions lib/hooks/search-threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import { useThreadSearchIndex } from '../selectors/nav-selectors.js';
import { sidebarInfoSelector } from '../selectors/thread-selectors.js';
import { threadIsChannel } from '../shared/thread-utils.js';
import type { SetState } from '../types/hook-types.js';
import type {
MinimallyEncodedRawThreadInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type {
SidebarInfo,
ThreadInfo,
LegacyRawThreadInfo,
RawThreadInfo,
} from '../types/thread-types.js';
import { useSelector } from '../utils/redux-utils.js';

Expand Down Expand Up @@ -107,14 +104,8 @@ function useSearchSubchannels(
threadInfo: ThreadInfo | MinimallyEncodedThreadInfo,
): SearchThreadsResult<ChatThreadItem> {
const filterFunc = React.useCallback(
(
thread: ?(
| ThreadInfo
| LegacyRawThreadInfo
| MinimallyEncodedThreadInfo
| MinimallyEncodedRawThreadInfo
),
) => threadIsChannel(thread) && thread?.parentThreadID === threadInfo.id,
(thread: ?(ThreadInfo | MinimallyEncodedThreadInfo | RawThreadInfo)) =>
threadIsChannel(thread) && thread?.parentThreadID === threadInfo.id,
[threadInfo.id],
);
const childThreadInfos = useFilteredChatListData(filterFunc);
Expand Down
21 changes: 4 additions & 17 deletions lib/selectors/chat-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ import {
type LocalMessageInfo,
isComposableMessageType,
} from '../types/message-types.js';
import type {
MinimallyEncodedRawThreadInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseAppState } from '../types/redux-types.js';
import { threadTypes } from '../types/thread-types-enum.js';
import {
type ThreadInfo,
type LegacyRawThreadInfo,
type RawThreadInfo,
type SidebarInfo,
maxReadSidebars,
maxUnreadSidebars,
Expand Down Expand Up @@ -232,12 +229,7 @@ function useFlattenedChatListData(): $ReadOnlyArray<ChatThreadItem> {

function useFilteredChatListData(
filterFunction: (
threadInfo: ?(
| ThreadInfo
| LegacyRawThreadInfo
| MinimallyEncodedThreadInfo
| MinimallyEncodedRawThreadInfo
),
threadInfo: ?(ThreadInfo | MinimallyEncodedThreadInfo | RawThreadInfo),
) => boolean,
): $ReadOnlyArray<ChatThreadItem> {
const threadInfos = useSelector(threadInfoSelector);
Expand All @@ -264,12 +256,7 @@ function getChatThreadItems(
messageInfos: { +[id: string]: ?MessageInfo },
sidebarInfos: { +[id: string]: $ReadOnlyArray<SidebarInfo> },
filterFunction: (
threadInfo: ?(
| ThreadInfo
| LegacyRawThreadInfo
| MinimallyEncodedThreadInfo
| MinimallyEncodedRawThreadInfo
),
threadInfo: ?(ThreadInfo | MinimallyEncodedThreadInfo | RawThreadInfo),
) => boolean,
): $ReadOnlyArray<ChatThreadItem> {
return _flow(
Expand Down
12 changes: 3 additions & 9 deletions lib/selectors/nav-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ import {
defaultCalendarQuery,
} from '../types/entry-types.js';
import type { CalendarFilter } from '../types/filter-types.js';
import type {
MinimallyEncodedRawThreadInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { MinimallyEncodedThreadInfo } 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 type { LegacyRawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import type { UserInfo } from '../types/user-types.js';
import { getConfig } from '../utils/config.js';
import { values } from '../utils/objects.js';
Expand Down Expand Up @@ -84,10 +81,7 @@ const useENSNamesOptions = { allAtOnce: true };

function useThreadSearchIndex(
threadInfos: $ReadOnlyArray<
| LegacyRawThreadInfo
| ThreadInfo
| MinimallyEncodedRawThreadInfo
| MinimallyEncodedThreadInfo,
RawThreadInfo | ThreadInfo | MinimallyEncodedThreadInfo,
>,
): SearchIndex {
const userInfos = useSelector(state => state.userStore.userInfos);
Expand Down
28 changes: 5 additions & 23 deletions lib/shared/avatar-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ import type {
ResolvedClientAvatar,
GenericUserInfoWithAvatar,
} from '../types/avatar-types.js';
import type {
MinimallyEncodedRawThreadInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { threadTypes } from '../types/thread-types-enum.js';
import {
type LegacyRawThreadInfo,
type ThreadInfo,
} from '../types/thread-types.js';
import type { ThreadInfo, RawThreadInfo } 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';
Expand Down Expand Up @@ -277,11 +271,7 @@ function getAvatarForUser(user: ?GenericUserInfoWithAvatar): ClientAvatar {
}

function getUserAvatarForThread(
threadInfo:
| LegacyRawThreadInfo
| ThreadInfo
| MinimallyEncodedRawThreadInfo
| MinimallyEncodedThreadInfo,
threadInfo: RawThreadInfo | ThreadInfo | MinimallyEncodedThreadInfo,
viewerID: ?string,
userInfos: UserInfos,
): ClientAvatar {
Expand All @@ -307,11 +297,7 @@ function getUserAvatarForThread(
}

function getAvatarForThread(
thread:
| LegacyRawThreadInfo
| ThreadInfo
| MinimallyEncodedThreadInfo
| MinimallyEncodedRawThreadInfo,
thread: RawThreadInfo | ThreadInfo | MinimallyEncodedThreadInfo,
containingThreadInfo: ?ThreadInfo | ?MinimallyEncodedThreadInfo,
): ClientAvatar {
if (thread.avatar) {
Expand All @@ -328,11 +314,7 @@ function getAvatarForThread(
}

function useAvatarForThread(
thread:
| LegacyRawThreadInfo
| ThreadInfo
| MinimallyEncodedRawThreadInfo
| MinimallyEncodedThreadInfo,
thread: RawThreadInfo | ThreadInfo | MinimallyEncodedThreadInfo,
): ClientAvatar {
const containingThreadID = thread.containingThreadID;
const containingThreadInfo = useSelector(state =>
Expand Down
13 changes: 3 additions & 10 deletions lib/shared/message-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ import type {
RawReactionMessageInfo,
ReactionMessageInfo,
} from '../types/messages/reaction.js';
import type {
MinimallyEncodedRawThreadInfo,
MinimallyEncodedThreadInfo,
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { LegacyRawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import type { UserInfos } from '../types/user-types.js';
import { extractKeyserverIDFromID } from '../utils/action-utils.js';
import {
Expand Down Expand Up @@ -683,11 +680,7 @@ function isInvalidPinSource(

function isInvalidPinSourceForThread(
messageInfo: RawMessageInfo | MessageInfo,
threadInfo:
| LegacyRawThreadInfo
| ThreadInfo
| MinimallyEncodedRawThreadInfo
| MinimallyEncodedThreadInfo,
threadInfo: RawThreadInfo | ThreadInfo | MinimallyEncodedThreadInfo,
): boolean {
const isValidPinSource = !isInvalidPinSource(messageInfo);
const isFirstMessageInSidebar = threadInfo.sourceMessageID === messageInfo.id;
Expand Down
Loading

0 comments on commit bfd6ef1

Please sign in to comment.