diff --git a/lib/reducers/calendar-filters-reducer.js b/lib/reducers/calendar-filters-reducer.js --- a/lib/reducers/calendar-filters-reducer.js +++ b/lib/reducers/calendar-filters-reducer.js @@ -12,10 +12,12 @@ deleteThreadActionTypes, } from '../actions/thread-actions.js'; import { + keyserverAuthActionTypes, logOutActionTypes, deleteKeyserverAccountActionTypes, logInActionTypes, registerActionTypes, + tempIdentityLoginActionTypes, } from '../actions/user-actions.js'; import { filteredThreadIDs, @@ -54,6 +56,7 @@ threadStore: ThreadStore, ): $ReadOnlyArray { if ( + action.type === tempIdentityLoginActionTypes.success || action.type === logOutActionTypes.success || action.type === deleteKeyserverAccountActionTypes.success || action.type === logInActionTypes.success || @@ -63,6 +66,9 @@ action.payload.sessionChange.cookieInvalidated) ) { return defaultCalendarFilters; + } else if (action.type === keyserverAuthActionTypes.success) { + const keyserverIDs = Object.keys(action.payload.updatesCurrentAsOf); + return removeKeyserverThreadIDsFromFilterList(state, keyserverIDs); } else if (action.type === updateCalendarThreadFilter) { const nonThreadFilters = nonThreadCalendarFilters(state); return [ diff --git a/lib/reducers/calendar-filters-reducer.test.js b/lib/reducers/calendar-filters-reducer.test.js --- a/lib/reducers/calendar-filters-reducer.test.js +++ b/lib/reducers/calendar-filters-reducer.test.js @@ -1,9 +1,11 @@ // @flow -import { +import reduceCalendarFilters, { removeDeletedThreadIDsFromFilterList, removeKeyserverThreadIDsFromFilterList, } from './calendar-filters-reducer.js'; +import { keyserverAuthActionTypes } from '../actions/user-actions.js'; +import type { RawMessageInfo } from '../types/message-types.js'; import type { ThreadStore } from '../types/thread-types'; const calendarFilters = [ @@ -171,3 +173,49 @@ ]); }); }); + +describe('reduceCalendarFilters', () => { + it('Removes from filters thread ids of the keyservers that were logged into', () => { + const messageInfos: RawMessageInfo[] = []; + const payload = { + currentUserInfo: { id: '5', username: 'me' }, + threadInfos: {}, + messagesResult: { + currentAsOf: {}, + messageInfos, + truncationStatus: {}, + watchedIDsAtRequestTime: [], + }, + userInfos: [], + calendarResult: { + rawEntryInfos: [], + calendarQuery: { startDate: '0', endDate: '0', filters: [] }, + }, + // only updatesCurrentAsOf is relevant to this test + updatesCurrentAsOf: { [keyserverToRemove1]: 5, [keyserverToRemove2]: 5 }, + logInActionSource: 'SOCKET_AUTH_ERROR_RESOLUTION_ATTEMPT', + }; + + expect( + reduceCalendarFilters( + calendarFiltersState, + { + type: keyserverAuthActionTypes.success, + payload, + loadingInfo: { + customKeyName: null, + trackMultipleRequests: false, + fetchIndex: 1, + }, + }, + { threadInfos: {} }, + ), + ).toEqual([ + { type: 'not_deleted' }, + { + type: 'threads', + threadIDs: threadIDsToStay, + }, + ]); + }); +});