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 @@ -17,4 +17,5 @@ }, }; } + export { createReplaceThreadOperation }; 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,10 +1,12 @@ // @flow import { type BaseStoreOpsHandlers } from './base-ops.js'; +import { threadSpecs } from '../shared/threads/thread-specs.js'; import type { ThreadActivityStore, ThreadActivityStoreEntry, } from '../types/thread-activity-types.js'; +import type { RawThreadInfos } from '../types/thread-types.js'; // client types export type ReplaceThreadActivityEntryOperation = { @@ -12,6 +14,7 @@ +payload: { +id: string, +threadActivityStoreEntry: ThreadActivityStoreEntry, + +isBackedUp: boolean, }, }; @@ -133,7 +136,30 @@ }, }; +function createReplaceThreadActivityEntryOperation( + id: string, + threadActivityStoreEntry: ThreadActivityStoreEntry, + 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, + }, + }; +} + export { threadActivityStoreOpsHandlers, convertThreadActivityEntryToClientDBThreadActivityEntry, + createReplaceThreadActivityEntryOperation, }; diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -192,6 +192,7 @@ reduceThreadActivity( state.threadActivityStore, action, + threadInfos, onStateDifferenceForStaff, ); diff --git a/lib/reducers/thread-activity-reducer.js b/lib/reducers/thread-activity-reducer.js --- a/lib/reducers/thread-activity-reducer.js +++ b/lib/reducers/thread-activity-reducer.js @@ -22,6 +22,7 @@ import { threadActivityStoreOpsHandlers, type ThreadActivityStoreOperation, + createReplaceThreadActivityEntryOperation, } from '../ops/thread-activity-store-ops.js'; import { isWebPlatform } from '../types/device-types.js'; import { processDMOpsActionType } from '../types/dm-ops.js'; @@ -32,6 +33,7 @@ } from '../types/socket-types.js'; import type { ThreadActivityStore } from '../types/thread-activity-types.js'; import { updateThreadLastNavigatedActionType } from '../types/thread-activity-types.js'; +import type { RawThreadInfos } from '../types/thread-types.js'; import { updateTypes } from '../types/update-types-enum.js'; import type { ClientUpdateInfo } from '../types/update-types.js'; import { processUpdatesActionType } from '../types/update-types.js'; @@ -116,20 +118,19 @@ function reduceThreadActivity( state: ThreadActivityStore, action: BaseAction, + threadInfos: RawThreadInfos, onStateDifference?: (message: string) => mixed, ): ReduceThreadActivityResult { if (action.type === updateThreadLastNavigatedActionType) { const { threadID, time } = action.payload; - const replaceOperation = { - type: 'replace_thread_activity_entry', - payload: { - id: threadID, - threadActivityStoreEntry: { - ...state[threadID], - lastNavigatedTo: time, - }, + const replaceOperation = createReplaceThreadActivityEntryOperation( + threadID, + { + ...state[threadID], + lastNavigatedTo: time, }, - }; + threadInfos, + ); return { threadActivityStore: processStoreOps(state, [replaceOperation]), threadActivityStoreOperations: [replaceOperation], @@ -138,16 +139,14 @@ const now = Date.now(); const replaceOperations = []; for (const threadID: string of action.payload.threadIDs) { - const replaceOperation = { - type: 'replace_thread_activity_entry', - payload: { - id: threadID, - threadActivityStoreEntry: { - ...state[threadID], - lastPruned: now, - }, + const replaceOperation = createReplaceThreadActivityEntryOperation( + threadID, + { + ...state[threadID], + lastPruned: now, }, - }; + threadInfos, + ); replaceOperations.push(replaceOperation); } return { diff --git a/lib/reducers/thread-activity-reducer.test.js b/lib/reducers/thread-activity-reducer.test.js --- a/lib/reducers/thread-activity-reducer.test.js +++ b/lib/reducers/thread-activity-reducer.test.js @@ -36,7 +36,7 @@ lastPruned: 1639522314170, }, }; - const result = reduceThreadActivity(initialState, action); + const result = reduceThreadActivity(initialState, action, {}); expect(result.threadActivityStore).toEqual(expectedState); }); @@ -54,7 +54,7 @@ lastNavigatedTo: 1639522317443, }, }; - const result = reduceThreadActivity(initialState, action); + const result = reduceThreadActivity(initialState, action, {}); expect(result.threadActivityStore).toEqual(expectedState); }); @@ -71,7 +71,7 @@ lastPruned: expect.any(Number), }, }; - const result = reduceThreadActivity(initialState, action); + const result = reduceThreadActivity(initialState, action, {}); expect(result.threadActivityStore).toEqual(expectedState); }); @@ -100,7 +100,7 @@ lastPruned: 1639522314170, }, }; - const result = reduceThreadActivity(initialState, action); + const result = reduceThreadActivity(initialState, action, {}); expect(result.threadActivityStore).toEqual(expectedState); }); @@ -142,8 +142,8 @@ }, }; - expect(reduceThreadActivity(threads, action).threadActivityStore).toEqual( - threads3, - ); + expect( + reduceThreadActivity(threads, action, {}).threadActivityStore, + ).toEqual(threads3); }); }); diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -1285,6 +1285,11 @@ payload: { id: threadID, threadActivityStoreEntry: entry, + // Adding `isBackedUp` only to support types, when this migration was + // implemented, backup was not yet supported, because of that, + // this migration should maintain the default behaviour. + // Migrating DM threads to be supported by backup is added later. + isBackedUp: false, }, })); diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js --- a/web/redux/redux-setup.js +++ b/web/redux/redux-setup.js @@ -17,6 +17,7 @@ keyserverStoreOpsHandlers, } from 'lib/ops/keyserver-store-ops.js'; import { + createReplaceThreadActivityEntryOperation, type ReplaceThreadActivityEntryOperation, threadActivityStoreOpsHandlers, } from 'lib/ops/thread-activity-store-ops.js'; @@ -496,16 +497,15 @@ state.messageStore.threads[activeThread] ) { const now = Date.now(); - const replaceOperation: ReplaceThreadActivityEntryOperation = { - type: 'replace_thread_activity_entry', - payload: { - id: activeThread, - threadActivityStoreEntry: { + const replaceOperation: ReplaceThreadActivityEntryOperation = + createReplaceThreadActivityEntryOperation( + activeThread, + { ...state[activeThread], lastNavigatedTo: now, }, - }, - }; + state.threadStore.threadInfos, + ); const threadActivityStore = threadActivityStoreOpsHandlers.processStoreOperations(