diff --git a/keyserver/src/creators/update-creator.js b/keyserver/src/creators/update-creator.js --- a/keyserver/src/creators/update-creator.js +++ b/keyserver/src/creators/update-creator.js @@ -10,7 +10,7 @@ } from 'lib/shared/update-utils.js'; import type { UpdateInfosRawData, - DeleteConditionType, + UpdateTypes, } from 'lib/shared/updates/update-spec.js'; import { updateSpecs } from 'lib/shared/updates/update-specs.js'; import { @@ -27,7 +27,6 @@ type NewUpdatesRedisMessage, } from 'lib/types/redis-types.js'; import type { RawThreadInfo } from 'lib/types/thread-types.js'; -import { updateTypes } from 'lib/types/update-types-enum.js'; import { type ServerUpdateInfo, type UpdateData, @@ -72,7 +71,7 @@ type DeleteCondition = { +userID: string, +target: ?string, - +types: DeleteConditionType, + +types: UpdateTypes, }; export type ViewerInfo = @@ -539,21 +538,13 @@ mergedUpdates.push(updateInfo); continue; } + const typesOfReplacedUpdatesForMatchingKey = + updateSpecs[updateInfo.type].typesOfReplacedUpdatesForMatchingKey; const currentUpdateInfo = updateForKey.get(key); if ( !currentUpdateInfo || - updateInfo.type === updateTypes.DELETE_THREAD || - updateInfo.type === updateTypes.JOIN_THREAD || - updateInfo.type === updateTypes.DELETE_ACCOUNT || - updateInfo.type === updateTypes.UPDATE_ENTRY || - updateInfo.type === updateTypes.UPDATE_CURRENT_USER - ) { - updateForKey.set(key, updateInfo); - } else if ( - (updateInfo.type === updateTypes.UPDATE_THREAD && - currentUpdateInfo.type === updateTypes.UPDATE_THREAD_READ_STATUS) || - (updateInfo.type === updateTypes.UPDATE_THREAD_READ_STATUS && - currentUpdateInfo.type === updateTypes.UPDATE_THREAD_READ_STATUS) + typesOfReplacedUpdatesForMatchingKey === 'all_types' || + typesOfReplacedUpdatesForMatchingKey?.has(currentUpdateInfo.type) ) { updateForKey.set(key, updateInfo); } diff --git a/lib/shared/updates/bad-device-token-spec.js b/lib/shared/updates/bad-device-token-spec.js --- a/lib/shared/updates/bad-device-token-spec.js +++ b/lib/shared/updates/bad-device-token-spec.js @@ -35,4 +35,5 @@ }; }, deleteCondition: null, + typesOfReplacedUpdatesForMatchingKey: null, }); 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 @@ -73,4 +73,5 @@ updateTypes.DELETE_ACCOUNT, updateTypes.UPDATE_USER, ]), + typesOfReplacedUpdatesForMatchingKey: 'all_types', }); diff --git a/lib/shared/updates/delete-thread-spec.js b/lib/shared/updates/delete-thread-spec.js --- a/lib/shared/updates/delete-thread-spec.js +++ b/lib/shared/updates/delete-thread-spec.js @@ -61,4 +61,5 @@ }; }, deleteCondition: 'all_types', + typesOfReplacedUpdatesForMatchingKey: 'all_types', }); diff --git a/lib/shared/updates/join-thread-spec.js b/lib/shared/updates/join-thread-spec.js --- a/lib/shared/updates/join-thread-spec.js +++ b/lib/shared/updates/join-thread-spec.js @@ -140,4 +140,5 @@ }; }, deleteCondition: 'all_types', + typesOfReplacedUpdatesForMatchingKey: 'all_types', }); diff --git a/lib/shared/updates/update-current-user-spec.js b/lib/shared/updates/update-current-user-spec.js --- a/lib/shared/updates/update-current-user-spec.js +++ b/lib/shared/updates/update-current-user-spec.js @@ -53,4 +53,5 @@ }; }, deleteCondition: new Set([updateTypes.UPDATE_CURRENT_USER]), + typesOfReplacedUpdatesForMatchingKey: 'all_types', }); diff --git a/lib/shared/updates/update-entry-spec.js b/lib/shared/updates/update-entry-spec.js --- a/lib/shared/updates/update-entry-spec.js +++ b/lib/shared/updates/update-entry-spec.js @@ -69,4 +69,5 @@ }; }, deleteCondition: 'all_types', + typesOfReplacedUpdatesForMatchingKey: 'all_types', }); 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 @@ -43,7 +43,7 @@ }, }; -export type DeleteConditionType = 'all_types' | $ReadOnlySet; +export type UpdateTypes = 'all_types' | $ReadOnlySet; export type UpdateSpec< UpdateInfo: ClientUpdateInfo, @@ -88,5 +88,6 @@ info: RawInfo, params: UpdateInfoFromRawInfoParams, ) => ?UpdateInfo, - +deleteCondition: ?DeleteConditionType, + +deleteCondition: ?UpdateTypes, + +typesOfReplacedUpdatesForMatchingKey: ?UpdateTypes, }; diff --git a/lib/shared/updates/update-thread-read-status-spec.js b/lib/shared/updates/update-thread-read-status-spec.js --- a/lib/shared/updates/update-thread-read-status-spec.js +++ b/lib/shared/updates/update-thread-read-status-spec.js @@ -69,4 +69,7 @@ }; }, deleteCondition: new Set([updateTypes.UPDATE_THREAD_READ_STATUS]), + typesOfReplacedUpdatesForMatchingKey: new Set([ + updateTypes.UPDATE_THREAD_READ_STATUS, + ]), }); diff --git a/lib/shared/updates/update-thread-spec.js b/lib/shared/updates/update-thread-spec.js --- a/lib/shared/updates/update-thread-spec.js +++ b/lib/shared/updates/update-thread-spec.js @@ -88,4 +88,7 @@ updateTypes.UPDATE_THREAD, updateTypes.UPDATE_THREAD_READ_STATUS, ]), + typesOfReplacedUpdatesForMatchingKey: new Set([ + updateTypes.UPDATE_THREAD_READ_STATUS, + ]), }); diff --git a/lib/shared/updates/update-user-spec.js b/lib/shared/updates/update-user-spec.js --- a/lib/shared/updates/update-user-spec.js +++ b/lib/shared/updates/update-user-spec.js @@ -40,4 +40,5 @@ }; }, deleteCondition: new Set([updateTypes.UPDATE_USER]), + typesOfReplacedUpdatesForMatchingKey: null, });