Page MenuHomePhabricator

D9801.id33338.diff
No OneTemporary

D9801.id33338.diff

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

Mime Type
text/plain
Expires
Sun, Dec 22, 8:04 AM (12 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690613
Default Alt Text
D9801.id33338.diff (3 KB)

Event Timeline