diff --git a/lib/ops/create-replace-thread-operation.js b/lib/ops/create-replace-thread-operation.js --- a/lib/ops/create-replace-thread-operation.js +++ b/lib/ops/create-replace-thread-operation.js @@ -1,7 +1,7 @@ // @flow import type { ReplaceThreadOperation } from './thread-store-ops.js'; -import { threadSpecs } from '../shared/threads/thread-specs.js'; +import { getDataIsBackedUpByThread } from '../shared/threads/protocols/thread-protocols.js'; import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; function createReplaceThreadOperation( @@ -13,7 +13,7 @@ payload: { id, threadInfo, - isBackedUp: threadSpecs[threadInfo.type].protocol.dataIsBackedUp, + isBackedUp: getDataIsBackedUpByThread(id, threadInfo), }, }; } diff --git a/lib/ops/entries-store-ops.js b/lib/ops/entries-store-ops.js --- a/lib/ops/entries-store-ops.js +++ b/lib/ops/entries-store-ops.js @@ -2,7 +2,7 @@ import type { BaseStoreOpsHandlers } from './base-ops.js'; import { daysToEntriesFromEntryInfos } from '../reducers/entry-reducer.js'; -import { threadSpecs } from '../shared/threads/thread-specs.js'; +import { getDataIsBackedUpByThread } from '../shared/threads/protocols/thread-protocols.js'; import type { EntryStore, RawEntryInfo, @@ -141,18 +141,12 @@ threadInfos: RawThreadInfos, ): ReplaceEntryOperation { const threadInfo = threadInfos[entry.threadID]; - if (!threadInfo) { - return { - type: 'replace_entry', - payload: { id, entry, isBackedUp: true }, - }; - } return { type: 'replace_entry', payload: { id, entry, - isBackedUp: threadSpecs[threadInfo.type].protocol.dataIsBackedUp, + isBackedUp: getDataIsBackedUpByThread(entry.threadID, threadInfo), }, }; } diff --git a/lib/ops/message-store-ops.js b/lib/ops/message-store-ops.js --- a/lib/ops/message-store-ops.js +++ b/lib/ops/message-store-ops.js @@ -1,7 +1,7 @@ // @flow import { type BaseStoreOpsHandlers } from './base-ops.js'; -import { threadSpecs } from '../shared/threads/thread-specs.js'; +import { getDataIsBackedUpByThread } from '../shared/threads/protocols/thread-protocols.js'; import type { ClientDBMessageInfo, ClientDBThreadMessageInfo, @@ -265,18 +265,12 @@ threadInfos: MixedRawThreadInfos, ): ReplaceMessageOperation { const threadInfo = threadInfos[messageInfo.threadID]; - if (!threadInfo) { - return { - type: 'replace', - payload: { id, messageInfo, isBackedUp: true }, - }; - } return { type: 'replace', payload: { id, messageInfo, - isBackedUp: threadSpecs[threadInfo.type].protocol.dataIsBackedUp, + isBackedUp: getDataIsBackedUpByThread(messageInfo.threadID, threadInfo), }, }; } @@ -289,7 +283,7 @@ let notBackedUpThreads: MessageStoreThreads = {}; for (const threadID in threads) { const threadInfo = threadInfos[threadID]; - if (!threadInfo || threadSpecs[threadInfo.type].protocol.dataIsBackedUp) { + if (getDataIsBackedUpByThread(threadID, threadInfo)) { backedUpThreads = { ...backedUpThreads, [threadID]: threads[threadID], diff --git a/lib/ops/thread-activity-store-ops.js b/lib/ops/thread-activity-store-ops.js --- a/lib/ops/thread-activity-store-ops.js +++ b/lib/ops/thread-activity-store-ops.js @@ -1,7 +1,7 @@ // @flow import { type BaseStoreOpsHandlers } from './base-ops.js'; -import { threadSpecs } from '../shared/threads/thread-specs.js'; +import { getDataIsBackedUpByThread } from '../shared/threads/protocols/thread-protocols.js'; import type { ThreadActivityStore, ThreadActivityStoreEntry, @@ -144,18 +144,12 @@ threadInfos: RawThreadInfos, ): ReplaceThreadActivityEntryOperation { const threadInfo = threadInfos[id]; - if (!threadInfo) { - return { - type: 'replace_thread_activity_entry', - payload: { id, threadActivityStoreEntry, isBackedUp: true }, - }; - } return { type: 'replace_thread_activity_entry', payload: { id, threadActivityStoreEntry, - isBackedUp: threadSpecs[threadInfo.type].protocol.dataIsBackedUp, + isBackedUp: getDataIsBackedUpByThread(id, threadInfo), }, }; } diff --git a/lib/shared/threads/protocols/thread-protocols.js b/lib/shared/threads/protocols/thread-protocols.js --- a/lib/shared/threads/protocols/thread-protocols.js +++ b/lib/shared/threads/protocols/thread-protocols.js @@ -2,7 +2,10 @@ import { dmThreadProtocol } from './dm-thread-protocol.js'; import { keyserverThreadProtocol } from './keyserver-thread-protocol.js'; -import type { ThreadProtocol } from '../thread-spec.js'; +import type { RawThreadInfo } from '../../../types/minimally-encoded-thread-permissions-types.js'; +import { type LegacyRawThreadInfo } from '../../../types/thread-types.js'; +import { type ThreadProtocol } from '../thread-spec.js'; +import { threadSpecs } from '../thread-specs.js'; const protocols = (): $ReadOnlyArray> => [ dmThreadProtocol, @@ -13,4 +16,14 @@ return protocols().find(p => p.threadIDMatchesProtocol(threadID)); } -export { protocols, getProtocolByThreadID }; +function getDataIsBackedUpByThread( + threadID: string, + threadInfo: ?(LegacyRawThreadInfo | RawThreadInfo), +): boolean { + if (threadInfo) { + return threadSpecs[threadInfo.type].protocol.dataIsBackedUp; + } + return !!getProtocolByThreadID(threadID)?.dataIsBackedUp; +} + +export { protocols, getProtocolByThreadID, getDataIsBackedUpByThread };