Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33324327
D14167.1768857381.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D14167.1768857381.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,45 @@
+// @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 resolveConnectionPromisesCallbacks = 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) {
+ resolveConnectionPromisesCallbacks.current.forEach(cb => cb());
+ resolveConnectionPromisesCallbacks.current = [];
+ }
+ }, [isConnectedOrUnreachable]);
+
+ const waitForConnection = React.useCallback((): Promise<void> => {
+ if (isConnectedOrUnreachable) {
+ return Promise.resolve();
+ }
+ return new Promise(resolve => {
+ resolveConnectionPromisesCallbacks.current.push(resolve);
+ });
+ }, [isConnectedOrUnreachable]);
+
+ return waitForConnection;
+}
+
+export { useWaitForConnection };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 19, 9:16 PM (9 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5958208
Default Alt Text
D14167.1768857381.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