From b33f27801eb3b70c2c3ba20b9170b1ae29996857 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 20 Sep 2021 11:18:06 -0700 Subject: [PATCH] redux types: Add two assumeSecretlyGlobalState markings In a bit, we'll make PerAccountState and GlobalState actually be distinct, and we'll mark most of our selectors as per-account or global accordingly. The major area of selectors we'll skip at first, because it requires some careful sorting-out of what its callers expect of it, is the selectors on `state.accounts` found in `accountsSelectors`. We'll initially say those are global selectors, reflecting the data that (like all our selectors) they have access to now in the status quo. Because we'll have GlobalState freely implicitly convert to PerAccountState (for a while) but not vice versa, that means that Flow will notice any place that a per-account selector (which has only a PerAccountState) invokes one of those selectors (which demands a GlobalState). We don't have many of those, but we have these two. In each of these cases, the calling selector really is working on a particular account's data, and although the data it's getting from the callee selector is stored in `state.accounts`, it really is specific to the active account; and in a multi-account future, the data we'll want here is really from whatever account the caller is working on, regardless of whether it's the active account in the UI. So these selectors are perfectly well doing the right thing; we just need to add these assumeSecretlyGlobalState markings, to tell Flow that we know about the type mismatch here and we're on it. --- src/emoji/emojiSelectors.js | 3 ++- src/pm-conversations/pmConversationsSelectors.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/emoji/emojiSelectors.js b/src/emoji/emojiSelectors.js index 78df38f1e1c..84b257e060e 100644 --- a/src/emoji/emojiSelectors.js +++ b/src/emoji/emojiSelectors.js @@ -1,13 +1,14 @@ /* @flow strict-local */ import { createSelector } from 'reselect'; import type { Selector, RealmEmojiById, ImageEmojiType } from '../types'; +import { assumeSecretlyGlobalState } from '../reduxTypes'; import { getRawRealmEmoji } from '../directSelectors'; import { getIdentity } from '../account/accountsSelectors'; import zulipExtraEmojiMap from './zulipExtraEmojiMap'; import { objectFromEntries } from '../jsBackport'; export const getAllImageEmojiById: Selector = createSelector( - getIdentity, + state => getIdentity(assumeSecretlyGlobalState(state)), getRawRealmEmoji, (identity, realmEmoji) => { const result: {| [string]: ImageEmojiType |} = {}; diff --git a/src/pm-conversations/pmConversationsSelectors.js b/src/pm-conversations/pmConversationsSelectors.js index b7a9709c466..871c24e8326 100644 --- a/src/pm-conversations/pmConversationsSelectors.js +++ b/src/pm-conversations/pmConversationsSelectors.js @@ -3,6 +3,7 @@ import invariant from 'invariant'; import { createSelector } from 'reselect'; import type { GlobalState, Message, PmConversationData, Selector } from '../types'; +import { assumeSecretlyGlobalState } from '../reduxTypes'; import { getPrivateMessages } from '../message/messageSelectors'; import { getAllUsersById, getOwnUserId } from '../users/userSelectors'; import { getUnreadByPms, getUnreadByHuddles } from '../unread/unreadSelectors'; @@ -121,7 +122,7 @@ function getRecentConversationsModernImpl( } const getServerIsOld: Selector = createSelector( - getServerVersion, + state => getServerVersion(assumeSecretlyGlobalState(state)), version => !(version && version.isAtLeast(model.MIN_RECENTPMS_SERVER_VERSION)), );