diff --git a/lib/hooks/disconnected-bar.js b/lib/hooks/disconnected-bar.js --- a/lib/hooks/disconnected-bar.js +++ b/lib/hooks/disconnected-bar.js @@ -7,10 +7,11 @@ import { connectionSelector } from '../selectors/keyserver-selectors.js'; import { updateDisconnectedBarActionType } from '../types/socket-types.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; function useDisconnectedBarVisibilityHandler(networkConnected: boolean): void { const dispatch = useDispatch(); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const disconnected = connection.showDisconnectedBar; @@ -67,7 +68,7 @@ +disconnected: boolean, +shouldShowDisconnectedBar: boolean, } { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const disconnected = connection.showDisconnectedBar; const socketConnected = connection.status === 'connected'; diff --git a/lib/selectors/keyserver-selectors.js b/lib/selectors/keyserver-selectors.js --- a/lib/selectors/keyserver-selectors.js +++ b/lib/selectors/keyserver-selectors.js @@ -45,9 +45,13 @@ const urlPrefixSelector: (state: AppState) => ?string = (state: AppState) => state.keyserverStore.keyserverInfos[ashoatKeyserverID]?.urlPrefix; -const connectionSelector: (state: AppState) => ?ConnectionInfo = ( - state: AppState, -) => state.keyserverStore.keyserverInfos[ashoatKeyserverID]?.connection; +const baseConnectionSelector: ( + id: string, +) => (state: AppState) => ?ConnectionInfo = (id: string) => (state: AppState) => + state.keyserverStore.keyserverInfos[id]?.connection; + +const connectionSelector: (id: string) => (state: AppState) => ?ConnectionInfo = + _memoize(baseConnectionSelector); const baseLastCommunicatedPlatformDetailsSelector: ( id: string, diff --git a/lib/selectors/server-calls.js b/lib/selectors/server-calls.js --- a/lib/selectors/server-calls.js +++ b/lib/selectors/server-calls.js @@ -35,7 +35,7 @@ urlPrefixSelector, sessionIDSelector, (state: AppState) => state.currentUserInfo, - connectionSelector, + connectionSelector(id), lastCommunicatedPlatformDetailsSelector(id), ( cookie: ?string, diff --git a/lib/socket/activity-handler.react.js b/lib/socket/activity-handler.react.js --- a/lib/socket/activity-handler.react.js +++ b/lib/socket/activity-handler.react.js @@ -14,6 +14,7 @@ import { queueActivityUpdatesActionType } from '../types/activity-types.js'; import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; type Props = { +activeThread: ?string, @@ -28,7 +29,7 @@ }, [activeThread]); const prevActiveThread = prevActiveThreadRef.current; - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const connectionStatus = connection.status; const prevConnectionStatusRef = React.useRef(); diff --git a/lib/socket/api-request-handler.react.js b/lib/socket/api-request-handler.react.js --- a/lib/socket/api-request-handler.react.js +++ b/lib/socket/api-request-handler.react.js @@ -15,6 +15,7 @@ import { registerActiveSocket } from '../utils/action-utils.js'; import { SocketOffline } from '../utils/errors.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; type BaseProps = { +inflightRequests: ?InflightRequests, @@ -93,7 +94,7 @@ const ConnectedAPIRequestHandler: React.ComponentType = React.memo(function ConnectedAPIRequestHandler(props) { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); return ; }); diff --git a/lib/socket/calendar-query-handler.react.js b/lib/socket/calendar-query-handler.react.js --- a/lib/socket/calendar-query-handler.react.js +++ b/lib/socket/calendar-query-handler.react.js @@ -23,6 +23,7 @@ useDispatchActionPromise, } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; type BaseProps = { +currentCalendarQuery: () => CalendarQuery, @@ -127,7 +128,7 @@ const ConnectedCalendarQueryHandler: React.ComponentType = React.memo(function ConnectedCalendarQueryHandler(props) { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const lastUserInteractionCalendar = useSelector( state => state.entryStore.lastUserInteractionCalendar, diff --git a/lib/socket/request-response-handler.react.js b/lib/socket/request-response-handler.react.js --- a/lib/socket/request-response-handler.react.js +++ b/lib/socket/request-response-handler.react.js @@ -24,6 +24,7 @@ } from '../types/socket-types.js'; import { ServerError, SocketTimeout } from '../utils/errors.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; type BaseProps = { +inflightRequests: ?InflightRequests, @@ -137,7 +138,7 @@ const ConnectedRequestResponseHandler: React.ComponentType = React.memo(function ConnectedRequestResponseHandler(props) { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const dispatch = useDispatch(); diff --git a/lib/socket/update-handler.react.js b/lib/socket/update-handler.react.js --- a/lib/socket/update-handler.react.js +++ b/lib/socket/update-handler.react.js @@ -15,6 +15,7 @@ } from '../types/socket-types.js'; import { processUpdatesActionType } from '../types/update-types.js'; import { useSelector } from '../utils/redux-utils.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; type Props = { +sendMessage: (message: ClientSocketMessageWithoutID) => number, @@ -25,7 +26,7 @@ const { addListener, removeListener, sendMessage } = props; const dispatch = useDispatch(); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const connectionStatus = connection.status; const onMessage = React.useCallback( diff --git a/native/calendar/calendar.react.js b/native/calendar/calendar.react.js --- a/native/calendar/calendar.react.js +++ b/native/calendar/calendar.react.js @@ -47,6 +47,7 @@ dateFromString, } from 'lib/utils/date-utils.js'; import sleep from 'lib/utils/sleep.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import CalendarInputBar from './calendar-input-bar.react.js'; import { @@ -1068,7 +1069,7 @@ const calendarFilters = useSelector(state => state.calendarFilters); const dimensions = useSelector(derivedDimensionsInfoSelector); const loadingStatus = useSelector(loadingStatusSelector); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const connectionStatus = connection.status; const colors = useColors(); diff --git a/native/calendar/entry.react.js b/native/calendar/entry.react.js --- a/native/calendar/entry.react.js +++ b/native/calendar/entry.react.js @@ -58,6 +58,7 @@ import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; import { ServerError } from 'lib/utils/errors.js'; import sleep from 'lib/utils/sleep.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import type { EntryInfoWithHeight } from './calendar.react.js'; import LoadingIndicator from './loading-indicator.react.js'; @@ -783,7 +784,7 @@ navContext, }), ); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const online = connection.status === 'connected'; const styles = useStyles(unboundStyles); diff --git a/native/media/encrypted-image.react.js b/native/media/encrypted-image.react.js --- a/native/media/encrypted-image.react.js +++ b/native/media/encrypted-image.react.js @@ -5,6 +5,7 @@ import { MediaCacheContext } from 'lib/components/media-cache-provider.react.js'; import { connectionSelector } from 'lib/selectors/keyserver-selectors.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { decryptBase64, decryptMedia } from './encryption-utils.js'; import LoadableImage from './loadable-image.react.js'; @@ -35,7 +36,7 @@ const mediaCache = React.useContext(MediaCacheContext); const [source, setSource] = React.useState(null); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const connectionStatus = connection.status; const prevConnectionStatusRef = React.useRef(connectionStatus); diff --git a/native/media/remote-image.react.js b/native/media/remote-image.react.js --- a/native/media/remote-image.react.js +++ b/native/media/remote-image.react.js @@ -6,6 +6,7 @@ import { connectionSelector } from 'lib/selectors/keyserver-selectors.js'; import { type ConnectionStatus } from 'lib/types/socket-types.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import LoadableImage from './loadable-image.react.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -68,7 +69,7 @@ } function ConnectedRemoteImage(props: BaseProps): React.Node { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const connectionStatus = connection.status; diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -691,7 +691,7 @@ const notifPermissionAlertInfo = useSelector( state => state.notifPermissionAlertInfo, ); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const updatesCurrentAsOf = useSelector(updatesCurrentAsOfSelector); const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); diff --git a/native/socket.react.js b/native/socket.react.js --- a/native/socket.react.js +++ b/native/socket.react.js @@ -48,7 +48,7 @@ const cookie = useSelector(cookieSelector); const urlPrefix = useSelector(urlPrefixSelector); invariant(urlPrefix, 'missing urlPrefix for given keyserver id'); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const frozen = useSelector(state => state.frozen); const active = useSelector( diff --git a/web/calendar/entry.react.js b/web/calendar/entry.react.js --- a/web/calendar/entry.react.js +++ b/web/calendar/entry.react.js @@ -46,6 +46,7 @@ import { dateString } from 'lib/utils/date-utils.js'; import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js'; import { ServerError } from 'lib/utils/errors.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import css from './calendar.css'; import LoadingIndicator from '../loading-indicator.react.js'; @@ -472,7 +473,7 @@ !!(state.currentUserInfo && !state.currentUserInfo.anonymous && true), ); const calendarQuery = useSelector(nonThreadCalendarQuery); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const online = connection.status === 'connected'; const callCreateEntry = useCreateEntry(); diff --git a/web/push-notif/badge-handler.react.js b/web/push-notif/badge-handler.react.js --- a/web/push-notif/badge-handler.react.js +++ b/web/push-notif/badge-handler.react.js @@ -4,13 +4,14 @@ import { connectionSelector } from 'lib/selectors/keyserver-selectors.js'; import { unreadCount } from 'lib/selectors/thread-selectors.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import electron from '../electron.js'; import { useSelector } from '../redux/redux-utils.js'; import getTitle from '../title/getTitle.js'; function useBadgeHandler() { - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); const prevConnection = React.useRef(); const boundUnreadCount = useSelector(unreadCount); diff --git a/web/socket.react.js b/web/socket.react.js --- a/web/socket.react.js +++ b/web/socket.react.js @@ -34,7 +34,7 @@ const cookie = useSelector(cookieSelector); const urlPrefix = useSelector(urlPrefixSelector); invariant(urlPrefix, 'missing urlPrefix for given keyserver id'); - const connection = useSelector(connectionSelector); + const connection = useSelector(connectionSelector(ashoatKeyserverID)); invariant(connection, 'keyserver missing from keyserverStore'); const active = useSelector( state =>