Page MenuHomePhabricator

D10479.diff
No OneTemporary

D10479.diff

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
@@ -82,6 +82,19 @@
const urlPrefixSelector: (keyserverID: string) => (state: AppState) => ?string =
_memoize(baseUrlPrefixSelector);
+const urlsToIDsSelector: (state: AppState) => {
+ +[url: string]: ?string,
+} = createSelector(
+ (state: AppState) => state.keyserverStore.keyserverInfos,
+ (infos: { +[key: string]: KeyserverInfo }) => {
+ const urlToIDs: { [string]: ?string } = {};
+ for (const keyserverID in infos) {
+ urlToIDs[infos[keyserverID].urlPrefix] = keyserverID;
+ }
+ return urlToIDs;
+ },
+);
+
const baseConnectionSelector: (
keyserverID: string,
) => (state: AppState) => ?ConnectionInfo = keyserverID => (state: AppState) =>
@@ -162,6 +175,7 @@
updatesCurrentAsOfSelector,
currentAsOfSelector,
urlPrefixSelector,
+ urlsToIDsSelector,
connectionSelector,
lastCommunicatedPlatformDetailsSelector,
deviceTokensSelector,
diff --git a/lib/shared/keyserver-utils.js b/lib/shared/keyserver-utils.js
--- a/lib/shared/keyserver-utils.js
+++ b/lib/shared/keyserver-utils.js
@@ -6,14 +6,35 @@
useGetVersion,
getVersionActionTypes,
} from '../actions/device-actions.js';
+import { urlsToIDsSelector } from '../selectors/keyserver-selectors.js';
import { useDispatchActionPromise } from '../utils/action-utils.js';
+import { useSelector } from '../utils/redux-utils.js';
function useIsKeyserverURLValid(keyserverURL?: string): () => Promise<boolean> {
+ const urlsToIDs: { +[keyserverID: string]: ?string } =
+ useSelector(urlsToIDsSelector);
+
+ const keyserverID: ?string = keyserverURL
+ ? urlsToIDs[keyserverURL]
+ : undefined;
+
+ const keyserverInfo = useSelector(state =>
+ keyserverID ? state.keyserverStore.keyserverInfos[keyserverID] : undefined,
+ );
+
const serverCallParamOverride = React.useMemo(() => {
if (!keyserverURL) {
return undefined;
}
+ if (keyserverInfo && keyserverID) {
+ return {
+ keyserverInfos: {
+ [(keyserverID: string)]: keyserverInfo,
+ },
+ };
+ }
+
return {
keyserverInfos: {
[(keyserverURL: string)]: {
@@ -21,7 +42,7 @@
},
},
};
- }, [keyserverURL]);
+ }, [keyserverID, keyserverInfo, keyserverURL]);
const getVersionCall = useGetVersion(serverCallParamOverride);

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 26, 5:34 PM (11 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2707756
Default Alt Text
D10479.diff (2 KB)

Event Timeline