Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3518022
D13653.id45169.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13653.id45169.diff
View Options
diff --git a/lib/actions/holder-actions.js b/lib/actions/holder-actions.js
--- a/lib/actions/holder-actions.js
+++ b/lib/actions/holder-actions.js
@@ -217,4 +217,4 @@
);
}
-export { useClearAllHolders, useProcessBlobHolders };
+export { processHoldersAction, useClearAllHolders, useProcessBlobHolders };
diff --git a/lib/handlers/holders-handler.react.js b/lib/handlers/holders-handler.react.js
new file mode 100644
--- /dev/null
+++ b/lib/handlers/holders-handler.react.js
@@ -0,0 +1,78 @@
+// @flow
+
+import invariant from 'invariant';
+import _throttle from 'lodash/throttle.js';
+import * as React from 'react';
+
+import {
+ processHoldersAction,
+ processHoldersActionTypes,
+ type ProcessHoldersStartedPayload,
+} from '../actions/holder-actions.js';
+import { isLoggedIn } from '../selectors/user-selectors.js';
+import { IdentityClientContext } from '../shared/identity-client-context.js';
+import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
+import { useSelector } from '../utils/redux-utils.js';
+
+const retryInterval = 30000; // ms
+
+function HoldersHandler(): React.Node {
+ const dispatchActionPromise = useDispatchActionPromise();
+ const identityContext = React.useContext(IdentityClientContext);
+ const getAuthMetadata = identityContext?.getAuthMetadata;
+
+ const loggedIn = useSelector(isLoggedIn);
+ const storedHolders = useSelector(state => state.holderStore.storedHolders);
+
+ const itemsToProcess = React.useMemo(() => {
+ const holdersToAdd = [],
+ holdersToRemove = [];
+
+ for (const blobHash in storedHolders) {
+ const { status, holder } = storedHolders[blobHash];
+ if (status === 'NOT_ESTABLISHED') {
+ holdersToAdd.push({ blobHash, holder });
+ } else if (status === 'NOT_REMOVED') {
+ holdersToRemove.push({ blobHash, holder });
+ }
+ }
+ return { holdersToAdd, holdersToRemove };
+ }, [storedHolders]);
+
+ const performHoldersProcessing: (
+ input: ProcessHoldersStartedPayload,
+ ) => Promise<void> = React.useMemo(
+ () =>
+ _throttle(async (input: ProcessHoldersStartedPayload) => {
+ invariant(getAuthMetadata, 'Identity context not set');
+ const authMetadata = await getAuthMetadata();
+
+ void dispatchActionPromise(
+ processHoldersActionTypes,
+ processHoldersAction(input, authMetadata),
+ undefined,
+ input,
+ );
+ }, retryInterval),
+ [getAuthMetadata, dispatchActionPromise],
+ );
+
+ const shouldStartProcessing =
+ itemsToProcess.holdersToAdd.length !== 0 ||
+ itemsToProcess.holdersToRemove.length !== 0;
+
+ React.useEffect(() => {
+ if (!loggedIn || !shouldStartProcessing) {
+ return;
+ }
+
+ void performHoldersProcessing(itemsToProcess);
+ }, [
+ itemsToProcess,
+ loggedIn,
+ performHoldersProcessing,
+ shouldStartProcessing,
+ ]);
+}
+
+export { HoldersHandler };
diff --git a/native/root.react.js b/native/root.react.js
--- a/native/root.react.js
+++ b/native/root.react.js
@@ -36,6 +36,7 @@
import { StaffContextProvider } from 'lib/components/staff-provider.react.js';
import { UserIdentityCacheProvider } from 'lib/components/user-identity-cache.react.js';
import { DBOpsHandler } from 'lib/handlers/db-ops-handler.react.js';
+import { HoldersHandler } from 'lib/handlers/holders-handler.react.js';
import { InitialStateSharingHandler } from 'lib/handlers/initial-state-sharing-handler.react.js';
import { TunnelbrokerDeviceTokenHandler } from 'lib/handlers/tunnelbroker-device-token-handler.react.js';
import { UserInfosHandler } from 'lib/handlers/user-infos-handler.react.js';
@@ -295,6 +296,7 @@
<DBOpsHandler />
<UserInfosHandler />
<TunnelbrokerDeviceTokenHandler />
+ <HoldersHandler />
</>
);
let navigation;
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -25,6 +25,7 @@
import { QRAuthProvider } from 'lib/components/qr-auth-provider.react.js';
import { StaffContextProvider } from 'lib/components/staff-provider.react.js';
import { DBOpsHandler } from 'lib/handlers/db-ops-handler.react.js';
+import { HoldersHandler } from 'lib/handlers/holders-handler.react.js';
import { TunnelbrokerDeviceTokenHandler } from 'lib/handlers/tunnelbroker-device-token-handler.react.js';
import { UserInfosHandler } from 'lib/handlers/user-infos-handler.react.js';
import { IdentitySearchProvider } from 'lib/identity-search/identity-search-context.js';
@@ -258,6 +259,7 @@
<FarcasterDataHandler />
<AutoJoinCommunityHandler />
<DMActivityHandler />
+ <HoldersHandler />
{content}
</ChatMentionContextProvider>
</MessageSearchStateProvider>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 7:01 PM (18 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2695037
Default Alt Text
D13653.id45169.diff (4 KB)
Attached To
Mode
D13653: [lib] Add handler component for retrying holder processing
Attached
Detach File
Event Timeline
Log In to Comment