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 @@ -1,6 +1,7 @@ // @flow import { reduceThreadActivity } from './thread-activity-reducer.js'; +import { messageStorePruneActionType } from '../actions/message-actions.js'; import { deleteKeyserverAccountActionTypes } from '../actions/user-actions.js'; import { updateThreadLastNavigatedActionType } from '../types/thread-activity-types.js'; @@ -39,6 +40,41 @@ expect(result).toEqual(expectedState); }); + test('should create new thread activity entry with only lastNavigatedTo field', () => { + const initialState = {}; + const action = { + type: updateThreadLastNavigatedActionType, + payload: { + threadID: 'thread1', + time: 1639522317443, + }, + }; + const expectedState = { + thread1: { + lastNavigatedTo: 1639522317443, + }, + }; + const result = reduceThreadActivity(initialState, action); + expect(result).toEqual(expectedState); + }); + + test('should create new thread activity entry with only lastPruned field', () => { + const initialState = {}; + const action = { + type: messageStorePruneActionType, + payload: { + threadIDs: ['thread1'], + }, + }; + const expectedState = { + thread1: { + lastPruned: expect.any(Number), + }, + }; + const result = reduceThreadActivity(initialState, action); + expect(result).toEqual(expectedState); + }); + test('returns the initial state if the action type is not recognized', () => { const initialState = { thread1: { diff --git a/lib/types/thread-activity-types.js b/lib/types/thread-activity-types.js --- a/lib/types/thread-activity-types.js +++ b/lib/types/thread-activity-types.js @@ -3,10 +3,16 @@ export const updateThreadLastNavigatedActionType = 'UPDATE_THREAD_LAST_NAVIGATED'; -export type ThreadActivityStoreEntry = { - +lastNavigatedTo: number, // millisecond timestamp - +lastPruned: number, // millisecond timestamp -}; +export type ThreadActivityStoreEntry = + | { + +lastNavigatedTo: number, // millisecond timestamp + +lastPruned?: number, // millisecond timestamp + } + | { + +lastNavigatedTo?: number, + +lastPruned: number, + }; + export type ThreadActivityStore = { +[threadID: string]: ThreadActivityStoreEntry, };