Page MenuHomePhabricator

D10425.id34906.diff
No OneTemporary

D10425.id34906.diff

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
@@ -42,7 +42,10 @@
type ClientUpdateInfo,
processUpdatesActionType,
} from '../types/update-types.js';
-import { setNewSessionActionType } from '../utils/action-utils.js';
+import {
+ extractKeyserverIDFromID,
+ setNewSessionActionType,
+} from '../utils/action-utils.js';
import { filterThreadIDsBelongingToCommunity } from '../utils/drawer-utils.react.js';
export default function reduceCalendarFilters(
@@ -156,17 +159,16 @@
return state;
}
-function removeDeletedThreadIDsFromFilterList(
+function filterThreadIDsInFilterList(
state: $ReadOnlyArray<CalendarFilter>,
- threadInfos: RawThreadInfos,
+ filterCondition: (threadID: string) => boolean,
): $ReadOnlyArray<CalendarFilter> {
const currentlyFilteredIDs = filteredThreadIDs(state);
if (!currentlyFilteredIDs) {
return state;
}
- const filtered = [...currentlyFilteredIDs].filter(threadID =>
- threadInFilterList(threadInfos[threadID]),
- );
+ const filtered = [...currentlyFilteredIDs].filter(filterCondition);
+
if (filtered.length < currentlyFilteredIDs.size) {
return [
...nonThreadCalendarFilters(state),
@@ -175,3 +177,29 @@
}
return state;
}
+
+function removeDeletedThreadIDsFromFilterList(
+ state: $ReadOnlyArray<CalendarFilter>,
+ threadInfos: RawThreadInfos,
+): $ReadOnlyArray<CalendarFilter> {
+ const filterCondition = (threadID: string) =>
+ threadInFilterList(threadInfos[threadID]);
+
+ return filterThreadIDsInFilterList(state, filterCondition);
+}
+
+function removeKeyserverThreadIDsFromFilterList(
+ state: $ReadOnlyArray<CalendarFilter>,
+ keyserverIDs: $ReadOnlyArray<string>,
+): $ReadOnlyArray<CalendarFilter> {
+ const keyserverIDsSet = new Set<string>(keyserverIDs);
+ const filterCondition = (threadID: string) =>
+ !keyserverIDsSet.has(extractKeyserverIDFromID(threadID));
+
+ return filterThreadIDsInFilterList(state, filterCondition);
+}
+
+export {
+ removeDeletedThreadIDsFromFilterList,
+ removeKeyserverThreadIDsFromFilterList,
+};
diff --git a/lib/reducers/calendar-filters-reducer.test.js b/lib/reducers/calendar-filters-reducer.test.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/calendar-filters-reducer.test.js
@@ -0,0 +1,173 @@
+// @flow
+
+import {
+ removeDeletedThreadIDsFromFilterList,
+ removeKeyserverThreadIDsFromFilterList,
+} from './calendar-filters-reducer.js';
+import type { ThreadStore } from '../types/thread-types';
+
+const calendarFilters = [
+ { type: 'threads', threadIDs: ['256|1', '256|83815'] },
+];
+
+const threadStore: ThreadStore = {
+ threadInfos: {
+ '256|1': {
+ id: '256|1',
+ type: 12,
+ name: 'GENESIS',
+ description: '',
+ color: '648caa',
+ creationTime: 1689091732528,
+ parentThreadID: null,
+ repliesCount: 0,
+ containingThreadID: null,
+ community: null,
+ pinnedCount: 0,
+ minimallyEncoded: true,
+ members: [
+ {
+ id: '256',
+ role: '256|83796',
+ permissions: '3f73ff',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83810',
+ role: '256|83795',
+ permissions: '3',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '256|83795': {
+ id: '256|83795',
+ name: 'Members',
+ permissions: ['000', '010', '005', '015', '0a7'],
+ isDefault: true,
+ minimallyEncoded: true,
+ },
+ '256|83796': {
+ id: '256|83796',
+ name: 'Admins',
+ permissions: ['000', '010', '005', '015', '0a7'],
+ isDefault: false,
+ minimallyEncoded: true,
+ },
+ },
+ currentUser: {
+ role: '256|83795',
+ permissions: '3',
+ subscription: {
+ home: true,
+ pushNotifs: true,
+ },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ },
+ '256|83815': {
+ id: '256|83815',
+ type: 7,
+ name: '',
+ description:
+ 'This is your private chat, where you can set reminders and jot notes in private!',
+ color: '57697f',
+ creationTime: 1689248242797,
+ parentThreadID: '256|1',
+ repliesCount: 0,
+ containingThreadID: '256|1',
+ community: '256|1',
+ pinnedCount: 0,
+ minimallyEncoded: true,
+ members: [
+ {
+ id: '256',
+ role: null,
+ permissions: '2c7fff',
+ isSender: false,
+ minimallyEncoded: true,
+ },
+ {
+ id: '83810',
+ role: '256|83816',
+ permissions: '3026f',
+ isSender: true,
+ minimallyEncoded: true,
+ },
+ ],
+ roles: {
+ '256|83816': {
+ id: '256|83816',
+ name: 'Members',
+ permissions: ['000', '010', '005', '015', '0a7'],
+ isDefault: true,
+ minimallyEncoded: true,
+ },
+ },
+ currentUser: {
+ role: null,
+ permissions: '3026f',
+ subscription: {
+ home: true,
+ pushNotifs: true,
+ },
+ unread: false,
+ minimallyEncoded: true,
+ },
+ },
+ },
+};
+
+describe('removeDeletedThreadIDsFromFilterList', () => {
+ it('Removes threads the user is not a member of anymore', () => {
+ expect(
+ removeDeletedThreadIDsFromFilterList(
+ calendarFilters,
+ threadStore.threadInfos,
+ ),
+ ).toEqual([{ type: 'threads', threadIDs: ['256|1'] }]);
+ });
+});
+
+const threadIDsToStay = [
+ '256|1',
+ '256|2',
+ '200|4',
+ '300|5',
+ '300|6',
+ '256|100',
+];
+const threadToRemove1 = '100';
+const threadToRemove2 = '400';
+const threadIDsToRemove = [
+ threadToRemove1 + '|3',
+ threadToRemove1 + '|7',
+ threadToRemove2 + '|8',
+];
+const calendarFiltersState = [
+ { type: 'not_deleted' },
+ {
+ type: 'threads',
+ threadIDs: [...threadIDsToStay, ...threadIDsToRemove],
+ },
+];
+
+describe('removeKeyserverThreadIDsFromFilterList', () => {
+ it('Removes threads from the given keyserver', () => {
+ expect(
+ removeKeyserverThreadIDsFromFilterList(calendarFiltersState, [
+ threadToRemove1,
+ threadToRemove2,
+ ]),
+ ).toEqual([
+ { type: 'not_deleted' },
+ {
+ type: 'threads',
+ threadIDs: threadIDsToStay,
+ },
+ ]);
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 4:23 AM (21 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2587947
Default Alt Text
D10425.id34906.diff (6 KB)

Event Timeline