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 @@ -24,7 +24,7 @@ type NewUpdatesRedisMessage, } from 'lib/types/redis-types.js'; import type { RawThreadInfo } from 'lib/types/thread-types.js'; -import { updateTypes, type UpdateType } from 'lib/types/update-types-enum.js'; +import type { UpdateType } from 'lib/types/update-types-enum.js'; import { type ServerUpdateInfo, type UpdateData, @@ -536,21 +536,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 @@ -87,4 +87,8 @@ params: UpdateInfoFromRawInfoParams, ) => ?UpdateInfo, +deleteCondition: ?('all_types' | $ReadOnlySet), + +typesOfReplacedUpdatesForMatchingKey: ?( + | 'all_types' + | $ReadOnlySet + ), }; 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, });