Skip to content

Commit

Permalink
[lib] Use RawThreadInfos type everywhere
Browse files Browse the repository at this point in the history
Summary:
In some places we were using `RawThreadInfos`, in others we were using `{ +[id: string]: RawThreadInfo }`, and in others we were using `{ +[threadID: string]: RawThreadInfo }`.

This is just for convenience when refactoring. Searching for `RawThreadInfos` or using "go to usages" will actually show us all uses of this type: https://blob.sh/68308a.png

Test Plan: NA

Reviewers: ashoat, ginsu, tomek, rohan

Reviewed By: ashoat

Subscribers: wyilio

Differential Revision: https://phab.comm.dev/D9787
  • Loading branch information
atulsmadhugiri committed Nov 9, 2023
1 parent 6949cb2 commit 6609133
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 57 deletions.
4 changes: 2 additions & 2 deletions keyserver/src/creators/update-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
redisMessageTypes,
type NewUpdatesRedisMessage,
} from 'lib/types/redis-types.js';
import type { RawThreadInfo } from 'lib/types/thread-types.js';
import type { RawThreadInfos } from 'lib/types/thread-types';
import {
type ServerUpdateInfo,
type UpdateData,
Expand Down Expand Up @@ -84,7 +84,7 @@ export type ViewerInfo =
viewer: Viewer,
calendarQuery: ?CalendarQuery,
updatesForCurrentSession?: UpdatesForCurrentSession,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
};
const defaultUpdateCreationResult = { viewerUpdates: [], userInfos: {} };
const sortFunction = (
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/user-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
SubscriptionUpdateRequest,
SubscriptionUpdateResult,
} from '../types/subscription-types.js';
import type { RawThreadInfo } from '../types/thread-types';
import type { RawThreadInfos } from '../types/thread-types';
import type {
UserInfo,
PasswordUpdate,
Expand Down Expand Up @@ -245,7 +245,7 @@ const logIn =

const userInfosArrays = [];

let threadInfos: { +[id: string]: RawThreadInfo } = {};
let threadInfos: RawThreadInfos = {};
const calendarResult = {
calendarQuery: logInInfo.calendarQuery,
rawEntryInfos: [],
Expand Down
3 changes: 2 additions & 1 deletion lib/ops/thread-store-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type BaseStoreOpsHandlers } from './base-ops.js';
import type {
ClientDBThreadInfo,
RawThreadInfo,
RawThreadInfos,
ThreadStore,
} from '../types/thread-types.js';
import {
Expand Down Expand Up @@ -44,7 +45,7 @@ export const threadStoreOpsHandlers: BaseStoreOpsHandlers<
ThreadStore,
ThreadStoreOperation,
ClientDBThreadStoreOperation,
{ +[id: string]: RawThreadInfo },
RawThreadInfos,
ClientDBThreadInfo,
> = {
processStoreOperations(
Expand Down
4 changes: 2 additions & 2 deletions lib/reducers/calendar-filters-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
fullStateSyncActionType,
incrementalStateSyncActionType,
} from '../types/socket-types.js';
import type { RawThreadInfo, ThreadStore } from '../types/thread-types.js';
import type { RawThreadInfos, ThreadStore } from '../types/thread-types.js';
import {
type ClientUpdateInfo,
processUpdatesActionType,
Expand Down Expand Up @@ -158,7 +158,7 @@ function updateFilterListFromUpdateInfos(

function removeDeletedThreadIDsFromFilterList(
state: $ReadOnlyArray<CalendarFilter>,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): $ReadOnlyArray<CalendarFilter> {
const currentlyFilteredIDs = filteredThreadIDs(state);
if (!currentlyFilteredIDs) {
Expand Down
6 changes: 3 additions & 3 deletions lib/reducers/entry-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
fullStateSyncActionType,
incrementalStateSyncActionType,
} from '../types/socket-types.js';
import { type RawThreadInfo } from '../types/thread-types.js';
import { type RawThreadInfos } from '../types/thread-types.js';
import {
type ClientUpdateInfo,
processUpdatesActionType,
Expand Down Expand Up @@ -90,7 +90,7 @@ function mergeNewEntryInfos(
currentEntryInfos: { +[id: string]: RawEntryInfo },
currentDaysToEntries: ?{ +[day: string]: string[] },
newEntryInfos: $ReadOnlyArray<RawEntryInfo>,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
) {
const mergedEntryInfos = {};
let someEntryUpdated = false;
Expand Down Expand Up @@ -163,7 +163,7 @@ function mergeNewEntryInfos(
function reduceEntryInfos(
entryStore: EntryStore,
action: BaseAction,
newThreadInfos: { +[id: string]: RawThreadInfo },
newThreadInfos: RawThreadInfos,
): [EntryStore, $ReadOnlyArray<ClientEntryInconsistencyReportCreationRequest>] {
const { entryInfos, daysToEntries, lastUserInteractionCalendar } = entryStore;
if (
Expand Down
14 changes: 7 additions & 7 deletions lib/reducers/message-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import {
incrementalStateSyncActionType,
} from '../types/socket-types.js';
import { threadPermissions } from '../types/thread-permission-types.js';
import { type RawThreadInfo } from '../types/thread-types.js';
import type { RawThreadInfo, RawThreadInfos } from '../types/thread-types.js';
import {
type ClientUpdateInfo,
processUpdatesActionType,
Expand Down Expand Up @@ -146,7 +146,7 @@ function freshMessageStore(
messageInfos: $ReadOnlyArray<RawMessageInfo>,
truncationStatus: { [threadID: string]: MessageTruncationStatus },
currentAsOf: number,
threadInfos: { +[threadID: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): FreshMessageStoreResult {
const unshimmed = unshimMessageInfos(messageInfos);
const orderedMessageInfos = sortMessageInfoList(unshimmed);
Expand Down Expand Up @@ -212,7 +212,7 @@ type ReassignmentResult = {

function reassignMessagesToRealizedThreads(
messageStore: MessageStore,
threadInfos: { +[threadID: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): ReassignmentResult {
const pendingToRealizedThreadIDs =
pendingToRealizedThreadIDsSelector(threadInfos);
Expand Down Expand Up @@ -305,7 +305,7 @@ function mergeNewMessages(
oldMessageStore: MessageStore,
newMessageInfos: $ReadOnlyArray<RawMessageInfo>,
truncationStatus: { [threadID: string]: MessageTruncationStatus },
threadInfos: { +[threadID: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): MergeNewMessagesResult {
const {
messageStoreOperations: updateWithLatestThreadInfosOps,
Expand Down Expand Up @@ -623,7 +623,7 @@ type UpdateMessageStoreWithLatestThreadInfosResult = {
};
function updateMessageStoreWithLatestThreadInfos(
messageStore: MessageStore,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): UpdateMessageStoreWithLatestThreadInfosResult {
const messageStoreOperations: MessageStoreOperation[] = [];
const {
Expand Down Expand Up @@ -691,7 +691,7 @@ function updateMessageStoreWithLatestThreadInfos(

function ensureRealizedThreadIDIsUsedWhenPossible<T: RawMessageInfo>(
payload: T,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): T {
const pendingToRealizedThreadIDs =
pendingToRealizedThreadIDsSelector(threadInfos);
Expand All @@ -711,7 +711,7 @@ type ReduceMessageStoreResult = {
function reduceMessageStore(
messageStore: MessageStore,
action: BaseAction,
newThreadInfos: { +[id: string]: RawThreadInfo },
newThreadInfos: RawThreadInfos,
): ReduceMessageStoreResult {
if (
action.type === logInActionTypes.success ||
Expand Down
4 changes: 2 additions & 2 deletions lib/reducers/thread-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
fullStateSyncActionType,
incrementalStateSyncActionType,
} from '../types/socket-types.js';
import type { RawThreadInfo, ThreadStore } from '../types/thread-types.js';
import type { RawThreadInfos, ThreadStore } from '../types/thread-types.js';
import {
type ClientUpdateInfo,
processUpdatesActionType,
Expand All @@ -52,7 +52,7 @@ const { processStoreOperations: processThreadStoreOperations } =
threadStoreOpsHandlers;

function generateOpsForThreadUpdates(
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
payload: {
+updatesResult: { +newUpdates: $ReadOnlyArray<ClientUpdateInfo>, ... },
...
Expand Down
19 changes: 10 additions & 9 deletions lib/selectors/thread-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
type RawThreadInfo,
type RelativeMemberInfo,
type SidebarInfo,
type RawThreadInfos,
} from '../types/thread-types.js';
import { dateString, dateFromString } from '../utils/date-utils.js';
import { values } from '../utils/objects.js';
Expand Down Expand Up @@ -273,7 +274,7 @@ const sidebarInfoSelector: (state: BaseAppState<>) => {

const unreadCount: (state: BaseAppState<>) => number = createSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
(threadInfos: { +[id: string]: RawThreadInfo }): number =>
(threadInfos: RawThreadInfos): number =>
values(threadInfos).filter(
threadInfo =>
threadInHomeChatList(threadInfo) && threadInfo.currentUser.unread,
Expand All @@ -282,7 +283,7 @@ const unreadCount: (state: BaseAppState<>) => number = createSelector(

const unreadBackgroundCount: (state: BaseAppState<>) => number = createSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
(threadInfos: { +[id: string]: RawThreadInfo }): number =>
(threadInfos: RawThreadInfos): number =>
values(threadInfos).filter(
threadInfo =>
threadInBackgroundChatList(threadInfo) && threadInfo.currentUser.unread,
Expand Down Expand Up @@ -351,7 +352,7 @@ const otherUsersButNoOtherAdmins: (

function mostRecentlyReadThread(
messageStore: MessageStore,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
): ?string {
let mostRecent = null;
for (const threadID in threadInfos) {
Expand Down Expand Up @@ -393,7 +394,7 @@ const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<>) => {
(state: BaseAppState<>) => state.threadStore.threadInfos,
threadInfoSelector,
(
rawThreadInfos: { +[id: string]: RawThreadInfo },
rawThreadInfos: RawThreadInfos,
threadInfos: { +[id: string]: ThreadInfo },
) => {
const pendingToRealizedThreadIDs =
Expand All @@ -408,11 +409,11 @@ const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<>) => {
return result;
},
);
const pendingToRealizedThreadIDsSelector: (rawThreadInfos: {
+[id: string]: RawThreadInfo,
}) => $ReadOnlyMap<string, string> = createSelector(
(rawThreadInfos: { +[id: string]: RawThreadInfo }) => rawThreadInfos,
(rawThreadInfos: { +[id: string]: RawThreadInfo }) => {
const pendingToRealizedThreadIDsSelector: (
rawThreadInfos: RawThreadInfos,
) => $ReadOnlyMap<string, string> = createSelector(
(rawThreadInfos: RawThreadInfos) => rawThreadInfos,
(rawThreadInfos: RawThreadInfos) => {
const result = new Map();
for (const threadID in rawThreadInfos) {
const rawThreadInfo = rawThreadInfos[threadID];
Expand Down
10 changes: 5 additions & 5 deletions lib/types/account-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type GenericMessagesResult,
} from './message-types.js';
import type { PreRequestUserState } from './session-types.js';
import { type RawThreadInfo } from './thread-types.js';
import { type RawThreadInfos } from './thread-types.js';
import {
type UserInfo,
type LoggedOutUserInfo,
Expand Down Expand Up @@ -69,15 +69,15 @@ export type RegisterResponse = {
rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
currentUserInfo: LoggedInUserInfo,
cookieChange: {
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
userInfos: $ReadOnlyArray<UserInfo>,
},
};

export type RegisterResult = {
+currentUserInfo: LoggedInUserInfo,
+rawMessageInfos: $ReadOnlyArray<RawMessageInfo>,
+threadInfos: { +[id: string]: RawThreadInfo },
+threadInfos: RawThreadInfos,
+userInfos: $ReadOnlyArray<UserInfo>,
+calendarQuery: CalendarQuery,
};
Expand Down Expand Up @@ -142,14 +142,14 @@ export type LogInResponse = {
+rawEntryInfos?: ?$ReadOnlyArray<RawEntryInfo>,
+serverTime: number,
+cookieChange: {
+threadInfos: { +[id: string]: RawThreadInfo },
+threadInfos: RawThreadInfos,
+userInfos: $ReadOnlyArray<UserInfo>,
},
+notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};

export type LogInResult = {
+threadInfos: { +[id: string]: RawThreadInfo },
+threadInfos: RawThreadInfos,
+currentUserInfo: LoggedInUserInfo,
+messagesResult: GenericMessagesResult,
+userInfos: $ReadOnlyArray<UserInfo>,
Expand Down
12 changes: 6 additions & 6 deletions lib/types/report-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { type PlatformDetails } from './device-types.js';
import { type RawEntryInfo, type CalendarQuery } from './entry-types.js';
import { type MediaMission } from './media-types.js';
import type { AppState, BaseAction } from './redux-types.js';
import { type RawThreadInfo } from './thread-types.js';
import { type RawThreadInfos } from './thread-types.js';
import type { UserInfo, UserInfos } from './user-types.js';
import { tPlatformDetails, tShape } from '../utils/validation-utils.js';

Expand Down Expand Up @@ -71,10 +71,10 @@ export type ActionSummary = {
};
export type ThreadInconsistencyReportShape = {
+platformDetails: PlatformDetails,
+beforeAction: { +[id: string]: RawThreadInfo },
+beforeAction: RawThreadInfos,
+action: BaseAction,
+pollResult?: { +[id: string]: RawThreadInfo },
+pushResult: { +[id: string]: RawThreadInfo },
+pollResult?: RawThreadInfos,
+pushResult: RawThreadInfos,
+lastActionTypes?: $ReadOnlyArray<$PropertyType<BaseAction, 'type'>>,
+lastActions?: $ReadOnlyArray<ActionSummary>,
+time?: number,
Expand Down Expand Up @@ -142,9 +142,9 @@ export type ReportCreationRequest =

export type ClientThreadInconsistencyReportShape = {
+platformDetails: PlatformDetails,
+beforeAction: { +[id: string]: RawThreadInfo },
+beforeAction: RawThreadInfos,
+action: BaseAction,
+pushResult: { +[id: string]: RawThreadInfo },
+pushResult: RawThreadInfos,
+lastActions: $ReadOnlyArray<ActionSummary>,
+time: number,
};
Expand Down
6 changes: 3 additions & 3 deletions lib/types/session-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import t, { type TInterface } from 'tcomb';
import type { LogInActionSource } from './account-types.js';
import type { Shape } from './core.js';
import type { CalendarQuery } from './entry-types.js';
import type { RawThreadInfo } from './thread-types.js';
import type { RawThreadInfos } from './thread-types.js';
import {
type UserInfo,
type CurrentUserInfo,
Expand Down Expand Up @@ -53,14 +53,14 @@ export type CookieType = $Values<typeof cookieTypes>;
export type ServerSessionChange =
| {
cookieInvalidated: false,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
userInfos: $ReadOnlyArray<UserInfo>,
sessionID?: null | string,
cookie?: string,
}
| {
cookieInvalidated: true,
threadInfos: { +[id: string]: RawThreadInfo },
threadInfos: RawThreadInfos,
userInfos: $ReadOnlyArray<UserInfo>,
currentUserInfo: LoggedOutUserInfo,
sessionID?: null | string,
Expand Down
4 changes: 2 additions & 2 deletions lib/types/socket-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
type ClientClientResponse,
} from './request-types.js';
import type { SessionState, SessionIdentification } from './session-types.js';
import { type RawThreadInfo, rawThreadInfoValidator } from './thread-types.js';
import { rawThreadInfoValidator, type RawThreadInfos } from './thread-types.js';
import {
type ClientUpdatesResult,
type ClientUpdatesResultWithUserInfos,
Expand Down Expand Up @@ -183,7 +183,7 @@ export const stateSyncPayloadTypes = Object.freeze({
export const fullStateSyncActionType = 'FULL_STATE_SYNC';
export type BaseFullStateSync = {
+messagesResult: MessagesResponse,
+threadInfos: { +[id: string]: RawThreadInfo },
+threadInfos: RawThreadInfos,
+rawEntryInfos: $ReadOnlyArray<RawEntryInfo>,
+userInfos: $ReadOnlyArray<UserInfo>,
+updatesCurrentAsOf: number,
Expand Down
4 changes: 2 additions & 2 deletions lib/types/thread-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export type ServerThreadInfo = {
};

export type ThreadStore = {
+threadInfos: { +[id: string]: RawThreadInfo },
+threadInfos: RawThreadInfos,
};
export const threadStoreValidator: TInterface<ThreadStore> =
tShape<ThreadStore>({
Expand Down Expand Up @@ -459,7 +459,7 @@ export const maxReadSidebars = 3;
// in the chat tab if every one of the displayed sidebars is unread
export const maxUnreadSidebars = 5;

export type ThreadStoreThreadInfos = { +[id: string]: RawThreadInfo };
export type ThreadStoreThreadInfos = RawThreadInfos;

export type ChatMentionCandidates = { +[id: string]: ResolvedThreadInfo };
export type ChatMentionCandidatesObj = {
Expand Down
3 changes: 2 additions & 1 deletion native/redux/edit-thread-permission-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
ThreadCurrentUserInfo,
RawThreadInfo,
RoleInfo,
RawThreadInfos,
} from 'lib/types/thread-types.js';

function addDetailedThreadEditPermissionsToUser<
Expand Down Expand Up @@ -59,7 +60,7 @@ function addDetailedThreadEditPermissionsToRole(

function migrateThreadStoreForEditThreadPermissions(threadInfos: {
+[id: string]: RawThreadInfo,
}): { +[id: string]: RawThreadInfo } {
}): RawThreadInfos {
const newThreadInfos = {};
for (const threadID in threadInfos) {
const threadInfo: RawThreadInfo = threadInfos[threadID];
Expand Down
Loading

0 comments on commit 6609133

Please sign in to comment.