Page MenuHomePhabricator

D11841.diff
No OneTemporary

D11841.diff

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
@@ -4,4 +4,10 @@
const clearAuxUserFIDsActionType = 'CLEAR_AUX_USER_FIDS';
-export { setFarcasterFriendsFIDActionType, clearAuxUserFIDsActionType };
+const setPeerDeviceListsActionType = 'SET_PEER_DEVICE_LISTS';
+
+export {
+ setFarcasterFriendsFIDActionType,
+ 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
@@ -3,6 +3,7 @@
import {
setFarcasterFriendsFIDActionType,
clearAuxUserFIDsActionType,
+ setPeerDeviceListsActionType,
} from '../actions/aux-user-actions.js';
import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js';
import {
@@ -80,6 +81,25 @@
auxUserStore: newAuxUserStore,
auxUserStoreOperations: [],
};
+ } else if (action.type === setPeerDeviceListsActionType) {
+ const replaceOperations: ReplaceAuxUserInfoOperation[] = [];
+ for (const userID in action.payload.deviceLists) {
+ replaceOperations.push({
+ type: 'replace_aux_user_info',
+ payload: {
+ id: userID,
+ auxUserInfo: {
+ ...state.auxUserInfos[userID],
+ fid: state.auxUserInfos[userID]?.fid ?? null,
+ deviceList: action.payload.deviceLists[userID],
+ },
+ },
+ });
+ }
+ return {
+ auxUserStore: processStoreOps(state, replaceOperations),
+ auxUserStoreOperations: replaceOperations,
+ };
}
return {
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
@@ -1,7 +1,11 @@
// @flow
import { reduceAuxUserStore } from './aux-user-reducer.js';
-import { setFarcasterFriendsFIDActionType } from '../actions/aux-user-actions.js';
+import {
+ setFarcasterFriendsFIDActionType,
+ setPeerDeviceListsActionType,
+} from '../actions/aux-user-actions.js';
+import type { RawDeviceList } from '../types/identity-service-types.js';
jest.mock('../utils/config.js');
@@ -35,4 +39,49 @@
},
});
});
+
+ it('should update aux user store with device lists for users', () => {
+ const oldAuxUserStore = {
+ auxUserInfos: {
+ userID_1: {
+ fid: 'farcasterID_1',
+ },
+ },
+ };
+
+ const deviceList1: RawDeviceList = {
+ devices: ['D1', 'D2'],
+ timestamp: 1,
+ };
+ const deviceList2: RawDeviceList = {
+ devices: ['D3'],
+ timestamp: 1,
+ };
+
+ const updateAuxUserInfosAction = {
+ type: setPeerDeviceListsActionType,
+ payload: {
+ deviceLists: {
+ userID_1: deviceList1,
+ userID_2: deviceList2,
+ },
+ },
+ };
+
+ expect(
+ reduceAuxUserStore(oldAuxUserStore, updateAuxUserInfosAction)
+ .auxUserStore,
+ ).toEqual({
+ auxUserInfos: {
+ userID_1: {
+ fid: 'farcasterID_1',
+ deviceList: deviceList1,
+ },
+ userID_2: {
+ fid: null,
+ deviceList: deviceList2,
+ },
+ },
+ });
+ });
});
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,6 +1,10 @@
// @flow
-import type { FarcasterUser, RawDeviceList } from './identity-service-types.js';
+import type {
+ FarcasterUser,
+ RawDeviceList,
+ UsersRawDeviceLists,
+} from './identity-service-types.js';
export type AuxUserInfo = { +fid: ?string, deviceList?: RawDeviceList };
@@ -13,3 +17,7 @@
export type SetFarcasterFriendsFIDPayload = {
+farcasterUsers: $ReadOnlyArray<FarcasterUser>,
};
+
+export type SetPeerDeviceListsPayload = {
+ +deviceLists: UsersRawDeviceLists,
+};
diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js
--- a/lib/types/identity-service-types.js
+++ b/lib/types/identity-service-types.js
@@ -221,6 +221,10 @@
+timestamp: number,
};
+export type UsersRawDeviceLists = {
+ +[userID: string]: RawDeviceList,
+};
+
export type SignedDeviceList = {
// JSON-stringified RawDeviceList
+rawDeviceList: string,
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,
SetFarcasterFriendsFIDPayload,
+ SetPeerDeviceListsPayload,
} from './aux-user-types.js';
import type {
UpdateUserAvatarRequest,
@@ -1393,6 +1394,10 @@
+type: 'CLEAR_AUX_USER_FIDS',
+payload?: void,
}
+ | {
+ +type: 'SET_PEER_DEVICE_LISTS',
+ +payload: SetPeerDeviceListsPayload,
+ }
| {
+type: 'OPS_PROCESSING_FINISHED_ACTION_TYPE',
+payload?: void,

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 5:25 AM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2597535
Default Alt Text
D11841.diff (4 KB)

Event Timeline