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 @@ -12,11 +12,11 @@ state.keyserverStore.keyserverInfos[ashoatKeyserverID]?.cookie; const cookiesSelector: (state: AppState) => { - +[keyserverID: string]: string, + +[keyserverID: string]: ?string, } = createSelector( (state: AppState) => state.keyserverStore.keyserverInfos, (infos: { +[key: string]: KeyserverInfo }) => { - const cookies = {}; + const cookies: { [keyserverID: string]: ?string } = {}; for (const keyserverID in infos) { cookies[keyserverID] = infos[keyserverID].cookie; } @@ -49,13 +49,69 @@ state.keyserverStore.keyserverInfos[ashoatKeyserverID] ?.lastCommunicatedPlatformDetails; +const urlPrefixesSelector: (state: AppState) => { + +[keyserverID: string]: string, +} = createSelector( + (state: AppState) => state.keyserverStore.keyserverInfos, + (infos: { +[key: string]: KeyserverInfo }) => { + const result: { [keyserverID: string]: string } = {}; + for (const keyserverID in infos) { + result[keyserverID] = infos[keyserverID].urlPrefix; + } + return result; + }, +); + +const sessionIDsSelector: (state: AppState) => { + +[keyserverID: string]: ?string, +} = createSelector( + (state: AppState) => state.keyserverStore.keyserverInfos, + (infos: { +[key: string]: KeyserverInfo }) => { + const result: { [keyserverID: string]: ?string } = {}; + for (const keyserverID in infos) { + result[keyserverID] = infos[keyserverID].sessionID; + } + return result; + }, +); + +const connectionsSelector: (state: AppState) => { + +[keyserverID: string]: ConnectionInfo, +} = createSelector( + (state: AppState) => state.keyserverStore.keyserverInfos, + (infos: { +[key: string]: KeyserverInfo }) => { + const result: { [keyserverID: string]: ConnectionInfo } = {}; + for (const keyserverID in infos) { + result[keyserverID] = infos[keyserverID].connection; + } + return result; + }, +); + +const lastCommunicatedPlatformDetailsObjSelector: (state: AppState) => { + +[keyserverID: string]: ?PlatformDetails, +} = createSelector( + (state: AppState) => state.keyserverStore.keyserverInfos, + (infos: { +[key: string]: KeyserverInfo }) => { + const result: { [keyserverID: string]: ?PlatformDetails } = {}; + for (const keyserverID in infos) { + result[keyserverID] = infos[keyserverID].lastCommunicatedPlatformDetails; + } + return result; + }, +); + export { cookieSelector, - cookiesSelector, sessionIDSelector, updatesCurrentAsOfSelector, currentAsOfSelector, urlPrefixSelector, connectionSelector, lastCommunicatedPlatformDetailsSelector, + cookiesSelector, + urlPrefixesSelector, + sessionIDsSelector, + connectionsSelector, + lastCommunicatedPlatformDetailsObjSelector, }; 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 @@ -8,6 +8,11 @@ urlPrefixSelector, connectionSelector, lastCommunicatedPlatformDetailsSelector, + cookiesSelector, + urlPrefixesSelector, + sessionIDsSelector, + connectionsSelector, + lastCommunicatedPlatformDetailsObjSelector, } from './keyserver-selectors.js'; import type { PlatformDetails } from '../types/device-types.js'; import type { AppState } from '../types/redux-types.js'; @@ -51,4 +56,49 @@ }), ); -export { serverCallStateSelector }; +export type ServersCallState = { + +cookies: { +[keyserverID: string]: ?string }, + +urlPrefixes: { +[keyserverID: string]: string }, + +sessionIDs: { +[keyserverID: string]: ?string }, + +connectionStatuses: { +[keyserverID: string]: ConnectionStatus }, + +lastCommunicatedPlatformDetails: { + +[keyserverID: string]: ?PlatformDetails, + }, + +currentUserInfo: ?CurrentUserInfo, +}; + +const serversCallStateSelector: (state: AppState) => ServersCallState = + createSelector( + cookiesSelector, + urlPrefixesSelector, + sessionIDsSelector, + connectionsSelector, + lastCommunicatedPlatformDetailsObjSelector, + (state: AppState) => state.currentUserInfo, + ( + cookies: { +[keyserverID: string]: ?string }, + urlPrefixes: { +[keyserverID: string]: string }, + sessionIDs: { +[keyserverID: string]: ?string }, + connectionInfos: { +[keyserverID: string]: ConnectionInfo }, + lastCommunicatedPlatformDetails: { + +[keyserverID: string]: ?PlatformDetails, + }, + currentUserInfo: ?CurrentUserInfo, + ) => { + const connectionStatuses = {}; + for (const key in connectionInfos) { + connectionStatuses[key] = connectionInfos[key].status; + } + + return { + cookies, + urlPrefixes, + sessionIDs, + connectionStatuses, + lastCommunicatedPlatformDetails, + currentUserInfo, + }; + }, + ); + +export { serverCallStateSelector, serversCallStateSelector };