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 @@ -3,9 +3,14 @@ import { createSelector } from 'reselect'; import type { PlatformDetails } from '../types/device-types'; -import type { KeyserverInfo } from '../types/keyserver-types'; +import type { + KeyserverInfo, + KeyserverInfos, + SelectedKeyserverInfos, +} from '../types/keyserver-types'; import type { AppState } from '../types/redux-types.js'; import type { ConnectionInfo } from '../types/socket-types.js'; +import type { UserInfos } from '../types/user-types.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; const cookieSelector: (state: AppState) => ?string = (state: AppState) => @@ -49,6 +54,31 @@ state.keyserverStore.keyserverInfos[ashoatKeyserverID] ?.lastCommunicatedPlatformDetails; +const selectedKeyserversSelector: ( + state: AppState, +) => $ReadOnlyArray = createSelector( + (state: AppState) => state.keyserverStore.keyserverInfos, + (state: AppState) => state.userStore.userInfos, + (keyserverInfos: KeyserverInfos, userInfos: UserInfos) => { + const result = []; + + for (const key in keyserverInfos) { + const keyserverInfo = keyserverInfos[key]; + const keyserverAdminUsername = userInfos[key].username; + + if (!keyserverAdminUsername) { + continue; + } + + result.push({ + keyserverAdminUsername, + keyserverInfo, + }); + } + return result; + }, +); + export { cookieSelector, cookiesSelector, @@ -58,4 +88,5 @@ urlPrefixSelector, connectionSelector, lastCommunicatedPlatformDetailsSelector, + selectedKeyserversSelector, }; diff --git a/lib/types/keyserver-types.js b/lib/types/keyserver-types.js --- a/lib/types/keyserver-types.js +++ b/lib/types/keyserver-types.js @@ -27,6 +27,11 @@ +newKeyserverInfo: KeyserverInfo, }; +export type SelectedKeyserverInfos = { + +keyserverAdminUsername: string, + +keyserverInfo: KeyserverInfo, +}; + export const keyserverInfoValidator: TInterface = tShape({ cookie: t.maybe(t.String),