Skip to content

Commit

Permalink
feat: Readonly support for attachments
Browse files Browse the repository at this point in the history
[fixes #22]
  • Loading branch information
kewisch committed Nov 4, 2019
1 parent e97caf4 commit ec9998e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/components/calGoogleCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ calGoogleCalendar.prototype = {
case "cache.always":
return true;
case "capabilities.timezones.floating.supported":
case "capabilities.attachments.supported":
case "capabilities.priority.supported":
return false;
case "capabilities.privacy.values":
Expand Down
14 changes: 14 additions & 0 deletions src/modules/gdataUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,20 @@ function JSONToEvent(aEntry, aCalendar, aDefaultReminders, aReferenceItem, aMeta
let categories = cal.category.stringToArray(sharedProps["X-MOZ-CATEGORIES"]);
item.setCategories(categories.length, categories);

// Attachments
if (aEntry.attachments) {
for (let attachEntry of aEntry.attachments) {
let attachItem = cal.createAttachment();
attachItem.uri = Services.io.newURI(attachEntry.fileUrl);
attachItem.formatType = attachEntry.mimeType;

attachItem.setParameter("MANAGED-ID", attachEntry.fileId);
attachItem.setParameter("FILENAME", attachEntry.title);

item.addAttachment(attachItem);
}
}

// updated (This must be set last!)
if (aEntry.updated) {
let updated = cal.dtz.fromRFC3339(aEntry.updated, calendarZone).getInTimezone(cal.dtz.UTC);
Expand Down
67 changes: 67 additions & 0 deletions test/xpcshell/test_gdata_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2146,3 +2146,70 @@ add_task(async function test_incremental_reset() {

gServer.resetClient(client);
});

add_task(async function test_attachments() {
gServer.events = [
{
kind: "calendar#event",
etag: '"1"',
id: "go6ijb0b46hlpbu4eeu92njevo",
created: "2006-06-08T21:04:52.000Z",
updated: "2006-06-08T21:05:49.138Z",
summary: "With Attachment",
creator: gServer.creator,
organizer: gServer.creator,
start: { dateTime: "2006-06-10T18:00:00+02:00" },
end: { dateTime: "2006-06-10T20:00:00+02:00" },
iCalUID: "[email protected]",
reminders: { useDefault: true },
attachments: [
{
fileId: 123,
fileUrl: "https://example.com/file",
iconLink: "https://example.com/unused",
mimeType: "application/octet-stream",
title: "Binary attachment",
},
{
fileId: 234,
fileUrl: "https://example.com/file2",
iconLink: "https://example.com/unused",
mimeType: "text/plain",
title: "Plain text attachment",
},
],
},
];

let client = await gServer.getClient();
let pclient = cal.async.promisifyCalendar(client);

let items = await pclient.getAllItems();
equal(items.length, 1);
let item = items[0];

let attachments = item.getAttachments({});
equal(attachments.length, 2);

let processed = new Set();

for (let attach of attachments) {
let id = attach.getParameter("MANAGED-ID");

if (processed.has(id)) {
ok(false, `ID ${id} has already been processed`);
} else if (id == 123) {
equal(attach.uri.spec, "https://example.com/file");
equal(attach.formatType, "application/octet-stream");
equal(attach.getParameter("FILENAME"), "Binary attachment");
} else if (id == 234) {
equal(attach.uri.spec, "https://example.com/file2");
equal(attach.formatType, "text/plain");
equal(attach.getParameter("FILENAME"), "Plain text attachment");
} else {
ok(false, "Invalid attachment id " + id);
}

processed.add(id);
}
});

0 comments on commit ec9998e

Please sign in to comment.