Skip to content

Commit 33805cd

Browse files
committed
Support email calendar property
1 parent 9f3a75c commit 33805cd

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

calendar/api/ext-calendar-utils.jsm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var EXPORTED_SYMBOLS = [
1212
"propsToItem",
1313
"convertItem",
1414
"convertAlarm",
15+
"findIdentityKey",
1516
];
1617

1718
var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -21,6 +22,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
2122
ICAL: "resource:///modules/calendar/Ical.jsm",
2223
CalEvent: "resource:///modules/CalEvent.jsm",
2324
CalTodo: "resource:///modules/CalTodo.jsm",
25+
MailServices: "resource:///modules/MailServices.jsm",
2426
});
2527

2628
var { ExtensionError } = ChromeUtils.import(
@@ -79,6 +81,7 @@ function convertCalendar(extension, calendar) {
7981
readOnly: calendar.readOnly,
8082
enabled: !calendar.getProperty("disabled"),
8183
color: calendar.getProperty("color") || "#A8C2E1",
84+
email: calendar.getProperty("imip.identity")?.email,
8285
};
8386

8487
if (isOwnCalendar(calendar, extension)) {
@@ -218,3 +221,15 @@ function convertAlarm(item, alarm) {
218221
related: ALARM_RELATED_MAP[alarm.related],
219222
};
220223
}
224+
225+
function findIdentityKey(email) {
226+
if (!email) {
227+
return null;
228+
}
229+
for (let identity of MailServices.accounts.allIdentities) {
230+
if (identity.email == email) {
231+
return identity.key;
232+
}
233+
}
234+
throw new ExtensionError(`Email address ${email} is unknown`);
235+
}

calendar/api/parent/ext-calendar-calendars.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ this.calendar_calendars = class extends ExtensionAPI {
1818
getResolvedCalendarById,
1919
isOwnCalendar,
2020
convertCalendar,
21+
findIdentityKey,
2122
} = ChromeUtils.import("resource://ext-calendar-draft/api/ext-calendar-utils.jsm");
2223

2324
return {
@@ -73,6 +74,8 @@ this.calendar_calendars = class extends ExtensionAPI {
7374
}
7475
},
7576
create: async function(createProperties) {
77+
let key = findIdentityKey(createProperties.email);
78+
7679
let calendar = calmgr.createCalendar(
7780
createProperties.type,
7881
Services.io.newURI(createProperties.url)
@@ -82,9 +85,12 @@ this.calendar_calendars = class extends ExtensionAPI {
8285
}
8386

8487
calendar.name = createProperties.name;
85-
if (typeof createProperties.color != "undefined") {
88+
if (createProperties.color != null) {
8689
calendar.setProperty("color", createProperties.color);
8790
}
91+
if (key) {
92+
calendar.setProperty("imip.identity.key", key);
93+
}
8894

8995
calmgr.registerCalendar(calendar);
9096

@@ -118,6 +124,10 @@ this.calendar_calendars = class extends ExtensionAPI {
118124
}
119125
}
120126

127+
if (updateProperties.email != null) {
128+
calendar.setProperty("imip.identity.key", findIdentityKey(updateProperties.email));
129+
}
130+
121131
// TODO capabilities merging
122132
},
123133
remove: async function(id) {
@@ -204,6 +214,10 @@ this.calendar_calendars = class extends ExtensionAPI {
204214
case "disabled":
205215
fire.sync(converted, { enabled: !value });
206216
break;
217+
case "imip.identity.key":
218+
let identity = calendar.getProperty("imip.identity");
219+
fire.sync(converted, { email: identity?.email });
220+
break;
207221
}
208222
},
209223
});

calendar/api/parent/ext-calendar-provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var { cal } = ChromeUtils.import("resource:///modules/calendar/calUtils.jsm");
99
var { ExtensionAPI, EventManager } = ExtensionCommon;
1010

1111
class ExtCalendarProvider extends cal.provider.BaseClass {
12-
QueryInterface = ChromeUtils.generateQI(["calICalendar", "calIChangeLog"]);
12+
QueryInterface = ChromeUtils.generateQI(["calICalendar", "calIChangeLog", "calISchedulingSupport"]);
1313

1414
static register(extension) {
1515
let calmgr = cal.getCalendarManager();

calendar/api/schema/calendar-calendars.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"url": { "type": "string" },
1414
"readOnly": { "type": "boolean" },
1515
"enabled": { "type": "boolean" },
16+
"email": { "type": "string", "optional": true },
1617
"color": { "type": "string", "optional": true },
1718
"capabilities": { "$ref": "CalendarCapabilities", "optional": true }
1819
}
@@ -25,6 +26,7 @@
2526
"url": { "type": "string" },
2627
"readOnly": { "type": "boolean" },
2728
"enabled": { "type": "boolean" },
29+
"email": { "type": "string", "optional": true },
2830
"color": { "type": "string", "optional": true }
2931
}
3032
},
@@ -128,6 +130,7 @@
128130
"url": { "type": "string" },
129131
"readOnly": { "type": "boolean", "optional": true },
130132
"enabled": { "type": "boolean", "optional": true },
133+
"email": { "type": "string", "optional": true },
131134
"color": { "type": "string", "optional": true },
132135
"capabilities": { "$ref": "CalendarCapabilities", "optional": true }
133136
}
@@ -148,6 +151,7 @@
148151
"url": { "type": "string", "optional": true },
149152
"readOnly": { "type": "boolean", "optional": true },
150153
"enabled": { "type": "boolean", "optional": true },
154+
"email": { "type": "string", "optional": true },
151155
"color": { "type": "string", "optional": true },
152156
"capabilities": { "$ref": "CalendarCapabilities", "optional": true }
153157
}

0 commit comments

Comments
 (0)