Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3178178
D9801.id33338.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9801.id33338.diff
View Options
diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js
--- a/lib/reducers/user-reducer.js
+++ b/lib/reducers/user-reducer.js
@@ -36,6 +36,7 @@
} from '../types/socket-types.js';
import { updateTypes } from '../types/update-types-enum.js';
import { processUpdatesActionType } from '../types/update-types.js';
+import type { ClientUpdateInfo } from '../types/update-types.js';
import type {
CurrentUserInfo,
UserInfos,
@@ -158,6 +159,18 @@
const { processStoreOperations: processUserStoreOps } = userStoreOpsHandlers;
+function generateOpsForUserUpdates(payload: {
+ +updatesResult: { +newUpdates: $ReadOnlyArray<ClientUpdateInfo>, ... },
+ ...
+}): $ReadOnlyArray<UserStoreOperation> {
+ return payload.updatesResult.newUpdates
+ .map(update =>
+ updateSpecs[update.type].generateOpsForUserInfoUpdates?.(update),
+ )
+ .filter(Boolean)
+ .flat();
+}
+
function reduceUserInfos(
state: UserStore,
action: BaseAction,
@@ -241,6 +254,10 @@
const newUserInfos = _keyBy(userInfo => userInfo.id)(
action.payload.userInfos,
);
+ const userStoreOps: UserStoreOperation[] = [
+ ...convertUserInfosToReplaceUserOps(newUserInfos),
+ ...generateOpsForUserUpdates(action.payload),
+ ];
const updated = action.payload.updatesResult.newUpdates.reduce(
(reducedState, update) => {
const { reduceUserInfos: reduceUserInfosUpdate } =
@@ -251,6 +268,17 @@
},
{ ...state.userInfos, ...newUserInfos },
);
+
+ const processedUserInfos: UserInfos = processUserStoreOps(
+ state.userInfos,
+ userStoreOps,
+ );
+ assertUserStoresAreEqual(
+ processedUserInfos,
+ updated,
+ action.type,
+ onStateDifference,
+ );
if (!_isEqual(state.userInfos)(updated)) {
return [
{
diff --git a/lib/shared/updates/delete-account-spec.js b/lib/shared/updates/delete-account-spec.js
--- a/lib/shared/updates/delete-account-spec.js
+++ b/lib/shared/updates/delete-account-spec.js
@@ -91,6 +91,9 @@
return info.deletedUserID;
},
typesOfReplacedUpdatesForMatchingKey: 'all_types',
+ generateOpsForUserInfoUpdates(update: AccountDeletionUpdateInfo) {
+ return [{ type: 'remove_users', payload: { ids: [update.deletedUserID] } }];
+ },
infoValidator: tShape<AccountDeletionUpdateInfo>({
type: tNumber(updateTypes.DELETE_ACCOUNT),
id: t.String,
diff --git a/lib/shared/updates/update-spec.js b/lib/shared/updates/update-spec.js
--- a/lib/shared/updates/update-spec.js
+++ b/lib/shared/updates/update-spec.js
@@ -3,6 +3,7 @@
import type { TType } from 'tcomb';
import type { ThreadStoreOperation } from '../../ops/thread-store-ops.js';
+import type { UserStoreOperation } from '../../ops/user-store-ops.js';
import type {
FetchEntryInfosBase,
RawEntryInfo,
@@ -96,4 +97,7 @@
+keyForUpdateInfo?: (info: UpdateInfo) => string,
+typesOfReplacedUpdatesForMatchingKey: ?UpdateTypes,
+infoValidator: TType<UpdateInfo>,
+ +generateOpsForUserInfoUpdates?: (
+ update: UpdateInfo,
+ ) => ?$ReadOnlyArray<UserStoreOperation>,
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 1:06 AM (20 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2446463
Default Alt Text
D9801.id33338.diff (3 KB)
Attached To
Mode
D9801: [lib] refactor processing updates in `UserStore` to ops
Attached
Detach File
Event Timeline
Log In to Comment