Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3511226
D14167.id46560.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D14167.id46560.diff
View Options
diff --git a/lib/hooks/relationship-hooks.js b/lib/hooks/relationship-hooks.js
--- a/lib/hooks/relationship-hooks.js
+++ b/lib/hooks/relationship-hooks.js
@@ -5,6 +5,7 @@
import { useNewThickThread } from './thread-hooks.js';
import { useUsersSupportThickThreads } from './user-identities-hooks.js';
+import { useWaitForConnection } from './wait-for-connection.js';
import { updateRelationships as serverUpdateRelationships } from '../actions/relationship-actions.js';
import { useLegacyAshoatKeyserverCall } from '../keyserver-conn/legacy-keyserver-call.js';
import { pendingToRealizedThreadIDsSelector } from '../selectors/thread-selectors.js';
@@ -89,6 +90,8 @@
const mapUsersSupportingThickThreads = useUsersSupportThickThreads();
+ const waitForConnection = useWaitForConnection();
+
const updateRelationshipsAndSendRobotext = React.useCallback(
async (action: RelationshipAction, userIDs: $ReadOnlyArray<string>) => {
if (!viewerID) {
@@ -97,6 +100,7 @@
);
return {};
}
+ await waitForConnection();
const usersSupportingThickThreads =
await mapUsersSupportingThickThreads(userIDs);
const planForUsers = new Map<string, RobotextPlanForUser>();
@@ -229,6 +233,7 @@
userInfos,
rawThreadInfos,
createNewThickThread,
+ waitForConnection,
],
);
diff --git a/lib/hooks/wait-for-connection.js b/lib/hooks/wait-for-connection.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/wait-for-connection.js
@@ -0,0 +1,44 @@
+// @flow
+
+import * as React from 'react';
+
+import { connectionSelector } from '../selectors/keyserver-selectors.js';
+import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js';
+import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js';
+import { useSelector } from '../utils/redux-utils.js';
+
+function useWaitForConnection(): () => Promise<void> {
+ const { socketState } = useTunnelbroker();
+
+ const connection = useSelector(
+ connectionSelector(authoritativeKeyserverID()),
+ );
+
+ const resolveConnectionPromise = React.useRef<?() => void>();
+
+ const isConnectedOrUnreachable = React.useMemo(() => {
+ return (
+ socketState.connected &&
+ (connection?.unreachable || connection?.status === 'connected')
+ );
+ }, [connection?.status, connection?.unreachable, socketState.connected]);
+
+ React.useEffect(() => {
+ if (isConnectedOrUnreachable) {
+ resolveConnectionPromise.current?.();
+ }
+ }, [isConnectedOrUnreachable]);
+
+ const waitForConnection = React.useCallback((): Promise<void> => {
+ if (isConnectedOrUnreachable) {
+ return Promise.resolve();
+ }
+ return new Promise(resolve => {
+ resolveConnectionPromise.current = resolve;
+ });
+ }, [isConnectedOrUnreachable]);
+
+ return waitForConnection;
+}
+
+export { useWaitForConnection };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 22, 2:03 PM (15 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2687988
Default Alt Text
D14167.id46560.diff (2 KB)
Attached To
Mode
D14167: [lib] Wait for tunnelbroker and keyserver connection when updating relationships
Attached
Detach File
Event Timeline
Log In to Comment