Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3398810
D12105.id40624.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D12105.id40624.diff
View Options
diff --git a/lib/actions/aux-user-actions.js b/lib/actions/aux-user-actions.js
--- a/lib/actions/aux-user-actions.js
+++ b/lib/actions/aux-user-actions.js
@@ -2,12 +2,15 @@
const setAuxUserFIDsActionType = 'SET_AUX_USER_FIDS';
+const addAuxUserFIDsActionType = 'ADD_AUX_USER_FIDS';
+
const clearAuxUserFIDsActionType = 'CLEAR_AUX_USER_FIDS';
const setPeerDeviceListsActionType = 'SET_PEER_DEVICE_LISTS';
export {
setAuxUserFIDsActionType,
+ addAuxUserFIDsActionType,
clearAuxUserFIDsActionType,
setPeerDeviceListsActionType,
};
diff --git a/lib/reducers/aux-user-reducer.js b/lib/reducers/aux-user-reducer.js
--- a/lib/reducers/aux-user-reducer.js
+++ b/lib/reducers/aux-user-reducer.js
@@ -2,6 +2,7 @@
import {
setAuxUserFIDsActionType,
+ addAuxUserFIDsActionType,
clearAuxUserFIDsActionType,
setPeerDeviceListsActionType,
} from '../actions/aux-user-actions.js';
@@ -24,6 +25,44 @@
+auxUserStoreOperations: $ReadOnlyArray<AuxUserStoreOperation>,
} {
if (action.type === setAuxUserFIDsActionType) {
+ const toUpdateUserIDs = new Set(
+ action.payload.farcasterUsers.map(farcasterUser => farcasterUser.userID),
+ );
+ const replaceOperations: ReplaceAuxUserInfoOperation[] = [];
+ for (const userID in state.auxUserInfos) {
+ if (
+ state.auxUserInfos[userID].fid !== null &&
+ !toUpdateUserIDs.has(userID)
+ ) {
+ replaceOperations.push({
+ type: 'replace_aux_user_info',
+ payload: {
+ id: userID,
+ auxUserInfo: {
+ ...state.auxUserInfos[userID],
+ fid: null,
+ },
+ },
+ });
+ }
+ }
+ for (const farcasterUser of action.payload.farcasterUsers) {
+ 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,
+ };
+ } else if (action.type === addAuxUserFIDsActionType) {
const replaceOperations: ReplaceAuxUserInfoOperation[] = [];
for (const farcasterUser of action.payload.farcasterUsers) {
replaceOperations.push({
diff --git a/lib/reducers/aux-user-reducer.test.js b/lib/reducers/aux-user-reducer.test.js
--- a/lib/reducers/aux-user-reducer.test.js
+++ b/lib/reducers/aux-user-reducer.test.js
@@ -2,6 +2,7 @@
import { reduceAuxUserStore } from './aux-user-reducer.js';
import {
+ addAuxUserFIDsActionType,
setAuxUserFIDsActionType,
setPeerDeviceListsActionType,
} from '../actions/aux-user-actions.js';
@@ -10,19 +11,23 @@
jest.mock('../utils/config.js');
describe('reduceAuxUserStore', () => {
- it('should update aux user store with farcaster data for user', () => {
+ it('should update aux user store with farcaster data for user2', () => {
const oldAuxUserStore = {
- auxUserInfos: {},
+ auxUserInfos: {
+ userID_1: {
+ fid: 'farcasterID_1',
+ },
+ },
};
const updateAuxUserInfosAction = {
- type: setAuxUserFIDsActionType,
+ type: addAuxUserFIDsActionType,
payload: {
farcasterUsers: [
{
- userID: 'userID_1',
- username: 'username_1',
- farcasterID: 'farcasterID_1',
+ userID: 'userID_2',
+ username: 'username_2',
+ farcasterID: 'farcasterID_2',
},
],
},
@@ -36,6 +41,46 @@
userID_1: {
fid: 'farcasterID_1',
},
+ userID_2: {
+ fid: 'farcasterID_2',
+ },
+ },
+ });
+ });
+
+ it('should set aux user store user1 fid to null and add user2', () => {
+ const oldAuxUserStore = {
+ auxUserInfos: {
+ userID_1: {
+ fid: 'farcasterID_1',
+ },
+ },
+ };
+
+ const updateAuxUserInfosAction = {
+ type: setAuxUserFIDsActionType,
+ payload: {
+ farcasterUsers: [
+ {
+ userID: 'userID_2',
+ username: 'username_2',
+ farcasterID: 'farcasterID_2',
+ },
+ ],
+ },
+ };
+
+ expect(
+ reduceAuxUserStore(oldAuxUserStore, updateAuxUserInfosAction)
+ .auxUserStore,
+ ).toEqual({
+ auxUserInfos: {
+ userID_1: {
+ fid: null,
+ },
+ userID_2: {
+ fid: 'farcasterID_2',
+ },
},
});
});
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
@@ -18,6 +18,10 @@
+farcasterUsers: $ReadOnlyArray<FarcasterUser>,
};
+export type AddAuxUserFIDsPayload = {
+ +farcasterUsers: $ReadOnlyArray<FarcasterUser>,
+};
+
export type SetPeerDeviceListsPayload = {
+deviceLists: UsersRawDeviceLists,
};
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
@@ -19,6 +19,7 @@
import type {
AuxUserStore,
SetAuxUserFIDsPayload,
+ AddAuxUserFIDsPayload,
SetPeerDeviceListsPayload,
} from './aux-user-types.js';
import type {
@@ -1390,6 +1391,10 @@
+type: 'SET_AUX_USER_FIDS',
+payload: SetAuxUserFIDsPayload,
}
+ | {
+ +type: 'ADD_AUX_USER_FIDS',
+ +payload: AddAuxUserFIDsPayload,
+ }
| {
+type: 'CLEAR_AUX_USER_FIDS',
+payload?: void,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 12:34 AM (20 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609476
Default Alt Text
D12105.id40624.diff (5 KB)
Attached To
Mode
D12105: [lib] modify set aux user fids and replace old behavior with add aux user fids action type
Attached
Detach File
Event Timeline
Log In to Comment