From d795e228045a53a4670e40a5b79848970e01473d Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 3 May 2024 16:27:26 +0200 Subject: [PATCH] FIX: adds support for location and details in ICS calendar (#26862) --- .../app/components/modal/download-calendar.js | 2 ++ .../discourse/app/lib/download-calendar.js | 2 ++ .../tests/unit/lib/download-calendar-test.js | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/modal/download-calendar.js b/app/assets/javascripts/discourse/app/components/modal/download-calendar.js index 152241d9880..0b7fc223ec8 100644 --- a/app/assets/javascripts/discourse/app/components/modal/download-calendar.js +++ b/app/assets/javascripts/discourse/app/components/modal/download-calendar.js @@ -25,6 +25,8 @@ export default class DownloadCalendar extends Component { this.args.model.calendar.dates, { recurrenceRule: this.args.model.calendar.recurrenceRule, + location: this.args.model.calendar.location, + details: this.args.model.calendar.details, } ); } else { diff --git a/app/assets/javascripts/discourse/app/lib/download-calendar.js b/app/assets/javascripts/discourse/app/lib/download-calendar.js index e98c0c0fd4f..3fd2951a5e4 100644 --- a/app/assets/javascripts/discourse/app/lib/download-calendar.js +++ b/app/assets/javascripts/discourse/app/lib/download-calendar.js @@ -89,6 +89,8 @@ export function generateIcsData(title, dates, options = {}) { `DTSTART:${startDate.utc().format("YMMDDTHHmmss")}Z\n` + `DTEND:${endDate.utc().format("YMMDDTHHmmss")}Z\n` + (options.recurrenceRule ? `RRULE:${options.recurrenceRule}\n` : ``) + + (options.location ? `LOCATION:${options.location}\n` : ``) + + (options.details ? `DESCRIPTION:${options.details}\n` : ``) + `SUMMARY:${title}\n` + "END:VEVENT\n" ); diff --git a/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js b/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js index 764279e43f2..c2171f6fe61 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/download-calendar-test.js @@ -24,12 +24,21 @@ module("Unit | Utility | download-calendar", function (hooks) { shouldAdvanceTime: true, shouldClearNativeTimers: true, }); - const data = generateIcsData("event test", [ + const data = generateIcsData( + "event test", + [ + { + startsAt: "2021-10-12T15:00:00.000Z", + endsAt: "2021-10-12T16:00:00.000Z", + }, + ], { - startsAt: "2021-10-12T15:00:00.000Z", - endsAt: "2021-10-12T16:00:00.000Z", - }, - ]); + recurrenceRule: "FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR", + location: "Paris", + details: "Good soup", + } + ); + assert.equal( data, `BEGIN:VCALENDAR @@ -40,6 +49,9 @@ UID:1634050800000_1634054400000 DTSTAMP:20220404T211500Z DTSTART:20211012T150000Z DTEND:20211012T160000Z +RRULE:FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR +LOCATION:Paris +DESCRIPTION:Good soup SUMMARY:event test END:VEVENT END:VCALENDAR`