From 8b93be823b5af57623349a48e2358094aec924bb Mon Sep 17 00:00:00 2001 From: Neil Rashbrook Date: Mon, 2 Nov 2020 16:33:47 +0000 Subject: [PATCH 1/3] Ability to get all metadata --- calendar/experiments/calendar/ext-calendar-utils.jsm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/calendar/experiments/calendar/ext-calendar-utils.jsm b/calendar/experiments/calendar/ext-calendar-utils.jsm index 139a866..6568d79 100644 --- a/calendar/experiments/calendar/ext-calendar-utils.jsm +++ b/calendar/experiments/calendar/ext-calendar-utils.jsm @@ -85,6 +85,18 @@ function convertCalendar(extension, calendar) { // TODO find a better way to define the cache id props.cacheId = calendar.superCalendar.id + "#cache"; props.capabilities = unwrapCalendar(calendar.superCalendar).capabilities; // TODO needs deep clone? + if (calendar instanceof Ci.calISyncWriteCalendar) { + props.metadata = { + ids: calendar.getAllMetaDataIds(), + values: calendar.getAllMetaDataValues().map(value => { + try { + return JSON.parse(value) ?? {}; + } catch (ex) { + return {}; + } + }), + }; + } } return props; From 4496e872f8b55acaffed593b28944db40fe5018c Mon Sep 17 00:00:00 2001 From: Neil Rashbrook Date: Wed, 9 Dec 2020 16:54:18 +0000 Subject: [PATCH 2/3] Return metadata as an object with the ids as keys --- .../calendar/ext-calendar-utils.jsm | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/calendar/experiments/calendar/ext-calendar-utils.jsm b/calendar/experiments/calendar/ext-calendar-utils.jsm index 6568d79..d17183d 100644 --- a/calendar/experiments/calendar/ext-calendar-utils.jsm +++ b/calendar/experiments/calendar/ext-calendar-utils.jsm @@ -86,16 +86,15 @@ function convertCalendar(extension, calendar) { props.cacheId = calendar.superCalendar.id + "#cache"; props.capabilities = unwrapCalendar(calendar.superCalendar).capabilities; // TODO needs deep clone? if (calendar instanceof Ci.calISyncWriteCalendar) { - props.metadata = { - ids: calendar.getAllMetaDataIds(), - values: calendar.getAllMetaDataValues().map(value => { - try { - return JSON.parse(value) ?? {}; - } catch (ex) { - return {}; - } - }), - }; + let ids = calendar.getAllMetaDataIds(); + props.metadata = {}; + for (let [index, value] of calendar.getAllMetaDataValues().entries()) { + try { + props.metadata[ids[index]] = JSON.parse(value) ?? {}; + } catch (ex) { + props.metadata[ids[index]] = {}; + } + } } } From 21fe681baefce6f8c5f09e1a49486ff4e3639f03 Mon Sep 17 00:00:00 2001 From: Neil Rashbrook Date: Wed, 11 Aug 2021 16:43:32 +0100 Subject: [PATCH 3/3] Separate method getAllMetadata --- .../experiments/calendar/ext-calendar-utils.jsm | 11 ----------- .../calendar/parent/ext-calendar-provider.js | 17 +++++++++++++++++ .../calendar/schema/calendar-provider.json | 10 ++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/calendar/experiments/calendar/ext-calendar-utils.jsm b/calendar/experiments/calendar/ext-calendar-utils.jsm index d17183d..139a866 100644 --- a/calendar/experiments/calendar/ext-calendar-utils.jsm +++ b/calendar/experiments/calendar/ext-calendar-utils.jsm @@ -85,17 +85,6 @@ function convertCalendar(extension, calendar) { // TODO find a better way to define the cache id props.cacheId = calendar.superCalendar.id + "#cache"; props.capabilities = unwrapCalendar(calendar.superCalendar).capabilities; // TODO needs deep clone? - if (calendar instanceof Ci.calISyncWriteCalendar) { - let ids = calendar.getAllMetaDataIds(); - props.metadata = {}; - for (let [index, value] of calendar.getAllMetaDataValues().entries()) { - try { - props.metadata[ids[index]] = JSON.parse(value) ?? {}; - } catch (ex) { - props.metadata[ids[index]] = {}; - } - } - } } return props; diff --git a/calendar/experiments/calendar/parent/ext-calendar-provider.js b/calendar/experiments/calendar/parent/ext-calendar-provider.js index 5558af0..c4f452e 100644 --- a/calendar/experiments/calendar/parent/ext-calendar-provider.js +++ b/calendar/experiments/calendar/parent/ext-calendar-provider.js @@ -303,11 +303,28 @@ this.calendar_provider = class extends ExtensionAPI { propsToItem, convertItem, convertCalendar, + unwrapCalendar, } = ChromeUtils.import(this.extension.rootURI.resolve("experiments/calendar/ext-calendar-utils.jsm")); return { calendar: { provider: { + getAllMetadata: async function(id) { + let calendar = unwrapCalendar(calmgr.getCalendarById(id)); + if (calendar.offlineStorage && isOwnCalendar(calendar, context.extension)) { + let ids = calendar.offlineStorage.getAllMetaDataIds(); + let metadata = {}; + for (let [index, value] of calendar.getAllMetaDataValues().entries()) { + try { + props.metadata[ids[index]] = JSON.parse(value) ?? {}; + } catch (ex) { + props.metadata[ids[index]] = {}; + } + } + return metadata; + } + return null; + }, onItemCreated: new EventManager({ context, name: "calendar.provider.onItemCreated", diff --git a/calendar/experiments/calendar/schema/calendar-provider.json b/calendar/experiments/calendar/schema/calendar-provider.json index abad693..08c0733 100644 --- a/calendar/experiments/calendar/schema/calendar-provider.json +++ b/calendar/experiments/calendar/schema/calendar-provider.json @@ -22,6 +22,16 @@ }, { "namespace": "calendar.provider", + "functions": [ + { + "name": "getAllMetadata", + "async": true, + "type": "function", + "parameters": [ + { "type": "string", "name": "id" } + ] + } + ], "events": [ { "name": "onItemCreated",