Page MenuHomePhabricator

D11525.diff
No OneTemporary

D11525.diff

diff --git a/lib/actions/aux-user-actions.js b/lib/actions/aux-user-actions.js
new file mode 100644
--- /dev/null
+++ b/lib/actions/aux-user-actions.js
@@ -0,0 +1,5 @@
+// @flow
+
+const setFarcasterFriendsFIDActionType = 'SET_FARCASTER_FRIENDS_FID';
+
+export { setFarcasterFriendsFIDActionType };
diff --git a/lib/reducers/aux-user-reducer.js b/lib/reducers/aux-user-reducer.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/aux-user-reducer.js
@@ -0,0 +1,46 @@
+// @flow
+
+import { setFarcasterFriendsFIDActionType } from '../actions/aux-user-actions.js';
+import {
+ auxUserStoreOpsHandlers,
+ type AuxUserStoreOperation,
+ type ReplaceAuxUserInfoOperation,
+} from '../ops/aux-user-store-ops.js';
+import type { AuxUserStore } from '../types/aux-user-types.js';
+import type { BaseAction } from '../types/redux-types';
+
+const { processStoreOperations: processStoreOps } = auxUserStoreOpsHandlers;
+
+function reduceAuxUserStore(
+ state: AuxUserStore,
+ action: BaseAction,
+): {
+ +auxUserStore: AuxUserStore,
+ +auxUserStoreOperations: $ReadOnlyArray<AuxUserStoreOperation>,
+} {
+ if (action.type === setFarcasterFriendsFIDActionType) {
+ const replaceOperations: ReplaceAuxUserInfoOperation[] = [];
+ action.payload.farcasterUsers.map(farcasterUser => {
+ replaceOperations.push({
+ type: 'replace_aux_user_info',
+ payload: {
+ id: farcasterUser.userID,
+ auxUserInfo: {
+ ...state.auxUserInfos[farcasterUser.userID],
+ fid: farcasterUser.farcasterID,
+ },
+ },
+ });
+ });
+ return {
+ auxUserStore: processStoreOps(state, replaceOperations),
+ auxUserStoreOperations: replaceOperations,
+ };
+ }
+ return {
+ auxUserStore: state,
+ auxUserStoreOperations: [],
+ };
+}
+
+export { reduceAuxUserStore };
diff --git a/lib/reducers/aux-user-reducer.test.js b/lib/reducers/aux-user-reducer.test.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/aux-user-reducer.test.js
@@ -0,0 +1,38 @@
+// @flow
+
+import { reduceAuxUserStore } from './aux-user-reducer.js';
+import { setFarcasterFriendsFIDActionType } from '../actions/aux-user-actions.js';
+
+jest.mock('../utils/config.js');
+
+describe('reduceAuxUserStore', () => {
+ it('should update aux user store with new thread hash', () => {
+ const oldAuxUserStore = {
+ auxUserInfos: {},
+ };
+
+ const updateAuxUserInfosAction = {
+ type: setFarcasterFriendsFIDActionType,
+ payload: {
+ farcasterUsers: [
+ {
+ userID: 'userID_1',
+ username: 'username_1',
+ farcasterID: 'farcasterID_1',
+ },
+ ],
+ },
+ };
+
+ expect(
+ reduceAuxUserStore(oldAuxUserStore, updateAuxUserInfosAction)
+ .auxUserStore,
+ ).toEqual({
+ auxUserInfos: {
+ userID_1: {
+ fid: 'farcasterID_1',
+ },
+ },
+ });
+ });
+});
diff --git a/lib/types/aux-user-types.js b/lib/types/aux-user-types.js
--- a/lib/types/aux-user-types.js
+++ b/lib/types/aux-user-types.js
@@ -1,5 +1,7 @@
// @flow
+import type { FarcasterUser } from './identity-service-types';
+
export type AuxUserInfo = { +fid: string };
export type AuxUserInfos = { +[userID: string]: AuxUserInfo };
@@ -7,3 +9,7 @@
export type AuxUserStore = {
+auxUserInfos: AuxUserInfos,
};
+
+export type SetFarcasterFriendsFIDPayload = {
+ +farcasterUsers: $ReadOnlyArray<FarcasterUser>,
+};
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -15,6 +15,7 @@
QueueActivityUpdatesPayload,
SetThreadUnreadStatusPayload,
} from './activity-types.js';
+import type { SetFarcasterFriendsFIDPayload } from './aux-user-types.js';
import type {
UpdateUserAvatarRequest,
UpdateUserAvatarResponse,
@@ -1366,6 +1367,10 @@
+type: 'SET_ACTIVE_SESSION_RECOVERY',
+payload: SetActiveSessionRecoveryPayload,
}
+ | {
+ +type: 'SET_FARCASTER_FRIENDS_FID',
+ +payload: SetFarcasterFriendsFIDPayload,
+ }
| {
+type: 'OPS_PROCESSING_FINISHED_ACTION_TYPE',
+payload?: void,

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 5:37 PM (4 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612538
Default Alt Text
D11525.diff (4 KB)

Event Timeline