Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33360402
D9644.1768942821.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D9644.1768942821.diff
View Options
diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js
--- a/lib/utils/action-utils.js
+++ b/lib/utils/action-utils.js
@@ -22,6 +22,7 @@
} from '../types/account-types.js';
import type { PlatformDetails } from '../types/device-types.js';
import type { Endpoint, SocketAPIHandler } from '../types/endpoints.js';
+import type { CalendarQuery } from '../types/entry-types.js';
import type { LoadingOptions, LoadingInfo } from '../types/loading-types.js';
import type {
ActionPayload,
@@ -476,6 +477,40 @@
return results;
}
+function sortCalendarQueryPerKeyserver(calendarQuery: CalendarQuery): {
+ +[keyserverID: string]: CalendarQuery,
+} {
+ const { startDate, endDate } = calendarQuery;
+ const results = {};
+ let includesNotDeletedFilter = false;
+ for (const filter of calendarQuery.filters) {
+ if (!filter.threadIDs) {
+ includesNotDeletedFilter = true;
+ continue;
+ }
+ for (const threadID of filter.threadIDs) {
+ const keyserverID = extractKeyserverIDFromID(threadID);
+ if (results[keyserverID] === undefined) {
+ results[keyserverID] = {
+ startDate,
+ endDate,
+ filters: [{ type: 'threads', threadIDs: [] }],
+ };
+ }
+ results[keyserverID].filters[0].threadIDs.push(threadID);
+ }
+ }
+ if (includesNotDeletedFilter) {
+ for (const keyserverID in results) {
+ results[keyserverID].filters.push({ type: 'not_deleted' });
+ }
+ }
+
+ console.log(results);
+
+ return results;
+}
+
export {
useDispatchActionPromise,
setNewSessionActionType,
@@ -486,4 +521,5 @@
bindCookieAndUtilsIntoCallServerEndpoint,
extractKeyserverIDFromID,
sortThreadIDsPerKeyserver,
+ sortCalendarQueryPerKeyserver,
};
diff --git a/lib/utils/action-utils.test.js b/lib/utils/action-utils.test.js
--- a/lib/utils/action-utils.test.js
+++ b/lib/utils/action-utils.test.js
@@ -1,6 +1,10 @@
// @flow
-import { extractKeyserverIDFromID } from './action-utils.js';
+import {
+ extractKeyserverIDFromID,
+ sortCalendarQueryPerKeyserver,
+} from './action-utils.js';
+import type { CalendarQuery } from '../types/entry-types';
describe('extractKeyserverIDFromID', () => {
it('should return <keyserverID> for <keyserverID>|<number>', () => {
@@ -9,3 +13,46 @@
expect(extractKeyserverIDFromID(id)).toBe(keyserverID);
});
});
+
+describe('sortCalendarQueryPerKeyserver', () => {
+ it('should split the calendar query into multiple queries, one for every \
+ keyserver, that have all the properties of the original one, \
+ but only the thread ids that the keyserver should get', () => {
+ const query: CalendarQuery = {
+ startDate: '1463588881886',
+ endDate: '1463588889886',
+ filters: [
+ { type: 'not_deleted' },
+ {
+ type: 'threads',
+ threadIDs: ['256|1', '256|2', '100|100', '100|101'],
+ },
+ ],
+ };
+ const queriesPerKeyserver = {
+ ['256']: {
+ startDate: '1463588881886',
+ endDate: '1463588889886',
+ filters: [
+ {
+ type: 'threads',
+ threadIDs: ['256|1', '256|2'],
+ },
+ { type: 'not_deleted' },
+ ],
+ },
+ ['100']: {
+ startDate: '1463588881886',
+ endDate: '1463588889886',
+ filters: [
+ {
+ type: 'threads',
+ threadIDs: ['100|100', '100|101'],
+ },
+ { type: 'not_deleted' },
+ ],
+ },
+ };
+ expect(sortCalendarQueryPerKeyserver(query)).toEqual(queriesPerKeyserver);
+ });
+});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 20, 9:00 PM (8 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5964107
Default Alt Text
D9644.1768942821.diff (3 KB)
Attached To
Mode
D9644: [lib] Add function for splitting calendar query per keyserver
Attached
Detach File
Event Timeline
Log In to Comment