diff --git a/NEWS b/NEWS index b76a0789..26f0a4e6 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,11 @@ Major Changes in 52.alpha: * Show a Join button for Jitsi links and CONFERENCE properties in events * Keep showing an event's location in its popover when the event also has an online meeting +* Fix invitations to events with a video conference, which Gmail couldn't + load, so it showed no Yes / No / Maybe buttons +* Send new events' invitations at SEQUENCE 0, raise it at most once per + save, and stamp each save's time in DTSTAMP, so that mail apps can tell + an update from an invitation they've already seen Major Changes in 51.0: * Preparations for further keyboard navigation improvements diff --git a/PLAN.md b/PLAN.md index 70dae1ed..b4f11b3e 100644 --- a/PLAN.md +++ b/PLAN.md @@ -40,12 +40,12 @@ event get the link in their invitation, and the event popover already shows a and a `CONFERENCE` property to the event's iCalendar component, so that it reaches attendees in the invitation. Keep it stable across later edits and updates, and take both out again on Remove. -- [ ] Check that Nextcloud keeps the `CONFERENCE` property and puts it in - the invitations it sends. Its source says it stores events as they - are and attaches the whole event as `event.ics`, but the email body - shows only the description (with our link), location and `URL`, not - `CONFERENCE`. Still to see on a Core: whether sabre/vobject's iTip - broker keeps `CONFERENCE` in that attachment. +- [x] Check that Nextcloud keeps the `CONFERENCE` property and puts it in + the invitations it sends. It does: the `event.ics` attachment has it + as we wrote it. But with `FEATURE=AUDIO,VIDEO` Gmail showed "Unable + to load event" and no RSVP buttons, and Google Calendar wouldn't + import the file. A bare `CONFERENCE;VALUE=URI:` works, so we write + only that. - [x] Reading: detect Jitsi links in existing events (`CONFERENCE`, description and location) so that the editor shows "conference added" rather than offering to add a second one, and so that the popover's Join diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c index 6df6178f..b9b7f15f 100644 --- a/src/core/gcal-event.c +++ b/src/core/gcal-event.c @@ -860,7 +860,6 @@ gcal_event_new_from_event (GcalEvent *self) g_return_val_if_fail (GCAL_IS_EVENT (self), NULL); component = e_cal_component_clone (self->component); - e_cal_component_commit_sequence (component); return gcal_event_new (self->calendar, component, NULL); } @@ -999,7 +998,6 @@ gcal_event_set_date_end (GcalEvent *self, component_dt = build_component_from_datetime (self, dt); e_cal_component_set_dtend (self->component, component_dt); - e_cal_component_commit_sequence (self->component); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_END]); @@ -1045,7 +1043,6 @@ gcal_event_set_date_start (GcalEvent *self, component_dt = build_component_from_datetime (self, dt); e_cal_component_set_dtstart (self->component, component_dt); - e_cal_component_commit_sequence (self->component); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DATE_START]); @@ -1133,8 +1130,6 @@ gcal_event_set_description (GcalEvent *self, e_cal_component_set_descriptions (self->component, NULL); } - e_cal_component_commit_sequence (self->component); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DESCRIPTION]); } } @@ -1245,8 +1240,6 @@ gcal_event_remove_all_alarms (GcalEvent *self) g_hash_table_iter_remove (&iter); } - e_cal_component_commit_sequence (self->component); - GCAL_EXIT; } @@ -1291,8 +1284,6 @@ gcal_event_add_alarm (GcalEvent *self, e_cal_component_alarm_free (new_alarm); - e_cal_component_commit_sequence (self->component); - GCAL_EXIT; } @@ -1323,7 +1314,6 @@ gcal_event_remove_alarm (GcalEvent *self, g_hash_table_remove (self->alarms, GINT_TO_POINTER (type)); - e_cal_component_commit_sequence (self->component); } } @@ -1364,7 +1354,6 @@ gcal_event_set_location (GcalEvent *self, if (g_strcmp0 (current_location, location) != 0) { e_cal_component_set_location (self->component, (location && *location) ? location : NULL); - e_cal_component_commit_sequence (self->component); g_clear_pointer (&self->location, g_free); self->location = g_strdup (location ? location : ""); @@ -1467,7 +1456,6 @@ gcal_event_set_summary (GcalEvent *self, text_component = e_cal_component_text_new (summary ? summary : "", NULL); e_cal_component_set_summary (self->component, text_component); - e_cal_component_commit_sequence (self->component); e_cal_component_text_free (text_component); @@ -1858,8 +1846,6 @@ gcal_event_set_recurrence (GcalEvent *self, i_cal_component_add_property (icalcomp, prop); } - e_cal_component_commit_sequence (self->component); - g_clear_object (&rrule); g_clear_object (&prop); } @@ -2045,7 +2031,6 @@ set_component_attendees (GcalEvent *self, GSList *ecal_attendees) { e_cal_component_set_attendees (self->component, ecal_attendees); - e_cal_component_commit_sequence (self->component); g_list_store_remove_all (self->attendees); load_attendees (self); @@ -2080,7 +2065,6 @@ gcal_event_set_organizer (GcalEvent *self, } e_cal_component_set_organizer (self->component, organizer); - e_cal_component_commit_sequence (self->component); e_cal_component_organizer_free (organizer); } @@ -2324,15 +2308,17 @@ gcal_event_dup_conference_url (GcalEvent *self) * gcal_event_add_conference: * @self: a #GcalEvent * @url: the URL of a video conference - * @label: (nullable): a name for the conference to show people * * Adds a CONFERENCE property (RFC 7986) for the video conference at @url * to @self, unless it has one already. + * + * The property has only the VALUE=URI parameter. Gmail can't load an + * invitation whose CONFERENCE has a FEATURE parameter, like + * FEATURE=AUDIO,VIDEO, and Google Calendar won't import the event at all. */ void gcal_event_add_conference (GcalEvent *self, - const gchar *url, - const gchar *label) + const gchar *url) { g_autoptr (GPtrArray) props = NULL; ICalComponent *icalcomp; @@ -2351,11 +2337,6 @@ gcal_event_add_conference (GcalEvent *self, prop = i_cal_property_new_conference (url); i_cal_property_take_parameter (prop, i_cal_parameter_new_value (I_CAL_VALUE_URI)); - /* Parsed, because libical 3 can't make a FEATURE with several values */ - i_cal_property_take_parameter (prop, i_cal_parameter_new_from_string ("FEATURE=AUDIO,VIDEO")); - - if (label && *label) - i_cal_property_take_parameter (prop, i_cal_parameter_new_label (label)); icalcomp = e_cal_component_get_icalcomponent (self->component); i_cal_component_take_property (icalcomp, prop); @@ -2454,3 +2435,38 @@ gcal_event_conferences_equal (GcalEvent *event1, return TRUE; } + +/** + * gcal_event_prepare_to_save: + * @self: a #GcalEvent + * @new_event: whether @self is being created, rather than updated + * + * Gets @self's SEQUENCE and DTSTAMP ready for saving it. The server emails + * them to the people invited, whose mail apps use them to tell an update + * from an invitation they've already seen. + * + * A new event starts at SEQUENCE 0. An updated one goes up by one if its + * date, time or recurrence changed since it was loaded, however many times + * they were changed in the editor. DTSTAMP is the time of saving. + */ +void +gcal_event_prepare_to_save (GcalEvent *self, + gboolean new_event) +{ + g_autoptr (ICalTime) now = NULL; + + g_return_if_fail (GCAL_IS_EVENT (self)); + + if (new_event) + { + e_cal_component_abort_sequence (self->component); + e_cal_component_set_sequence (self->component, 0); + } + else + { + e_cal_component_commit_sequence (self->component); + } + + now = i_cal_time_new_current_with_zone (i_cal_timezone_get_utc_timezone ()); + e_cal_component_set_dtstamp (self->component, now); +} diff --git a/src/core/gcal-event.h b/src/core/gcal-event.h index ced69910..d7d04830 100644 --- a/src/core/gcal-event.h +++ b/src/core/gcal-event.h @@ -174,8 +174,7 @@ gboolean gcal_event_strings_equal (GcalEvent gchar* gcal_event_dup_conference_url (GcalEvent *self); void gcal_event_add_conference (GcalEvent *self, - const gchar *url, - const gchar *label); + const gchar *url); void gcal_event_remove_conference (GcalEvent *self, const gchar *url); @@ -186,6 +185,9 @@ void gcal_event_copy_conferences (GcalEvent gboolean gcal_event_conferences_equal (GcalEvent *event1, GcalEvent *event2); +void gcal_event_prepare_to_save (GcalEvent *self, + gboolean new_event); + G_END_DECLS #endif /* GCAL_EVENT_H */ diff --git a/src/core/gcal-manager.c b/src/core/gcal-manager.c index ecf4efbc..d0b87215 100644 --- a/src/core/gcal-manager.c +++ b/src/core/gcal-manager.c @@ -1013,6 +1013,8 @@ gcal_manager_create_event (GcalManager *self, g_return_if_fail (GCAL_IS_MANAGER (self)); g_return_if_fail (GCAL_IS_EVENT (event)); + gcal_event_prepare_to_save (event, TRUE); + component = gcal_event_get_component (event); calendar = gcal_event_get_calendar (event); @@ -1053,6 +1055,8 @@ gcal_manager_update_event (GcalManager *self, g_return_if_fail (GCAL_IS_MANAGER (self)); g_return_if_fail (GCAL_IS_EVENT (event)); + gcal_event_prepare_to_save (event, FALSE); + calendar = gcal_event_get_calendar (event); component = gcal_event_get_component (event); diff --git a/src/federated/gcal-jitsi.c b/src/federated/gcal-jitsi.c index c61bc77b..ac30d842 100644 --- a/src/federated/gcal-jitsi.c +++ b/src/federated/gcal-jitsi.c @@ -396,7 +396,7 @@ gcal_jitsi_add_conference (GcalEvent *event, g_return_if_fail (GCAL_IS_EVENT (event)); g_return_if_fail (url != NULL); - gcal_event_add_conference (event, url, _("Jitsi Video Conference")); + gcal_event_add_conference (event, url); description = gcal_jitsi_add_to_description (gcal_event_get_description (event), url); gcal_event_set_description (event, description); diff --git a/src/gui/event-editor/gcal-schedule-section.c b/src/gui/event-editor/gcal-schedule-section.c index 32a9f52e..a36f3139 100644 --- a/src/gui/event-editor/gcal-schedule-section.c +++ b/src/gui/event-editor/gcal-schedule-section.c @@ -252,7 +252,6 @@ remove_recurrence_properties (GcalEvent *event) e_cal_component_set_recurid (comp, NULL); e_cal_component_set_rrules (comp, NULL); - e_cal_component_commit_sequence (comp); } static void diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c index 3a94ef9f..fb9f0597 100644 --- a/src/utils/gcal-utils.c +++ b/src/utils/gcal-utils.c @@ -352,8 +352,6 @@ gcal_util_build_component_from_details (const gchar *summary, e_cal_component_set_summary (event, summ); e_cal_component_text_free (summ); - e_cal_component_commit_sequence (event); - return event; } diff --git a/tests/test-event.c b/tests/test-event.c index 836b8666..1951ec83 100644 --- a/tests/test-event.c +++ b/tests/test-event.c @@ -697,10 +697,10 @@ event_add_conference (void) g_assert_null (gcal_event_dup_conference_url (event)); - gcal_event_add_conference (event, ROOM_URL, "Jitsi"); + gcal_event_add_conference (event, ROOM_URL); /* Adding the same conference again doesn't duplicate it */ - gcal_event_add_conference (event, ROOM_URL, "Jitsi"); + gcal_event_add_conference (event, ROOM_URL); url = gcal_event_dup_conference_url (event); g_assert_cmpstr (url, ==, ROOM_URL); @@ -717,8 +717,9 @@ event_add_conference (void) g_assert_nonnull (strstr (string, "CONFERENCE;")); g_assert_nonnull (strstr (string, "VALUE=URI")); - g_assert_nonnull (strstr (string, "FEATURE=AUDIO,VIDEO")); - g_assert_nonnull (strstr (string, "LABEL=Jitsi")); + /* Gmail can't load invitations with these */ + g_assert_null (strstr (string, "FEATURE=")); + g_assert_null (strstr (string, "LABEL=")); g_assert_nonnull (strstr (string, ":" ROOM_URL)); g_assert_null (strstr (strstr (string, "CONFERENCE;") + 1, "CONFERENCE;")); @@ -781,7 +782,7 @@ event_copy_conferences (void) event = create_event_for_string (STUB_EVENT, &error); g_assert_no_error (error); - gcal_event_add_conference (event, ROOM_URL, "Jitsi"); + gcal_event_add_conference (event, ROOM_URL); g_assert_false (gcal_event_conferences_equal (event, with_conference)); /* Copying replaces the conferences, rather than adding to them */ @@ -798,6 +799,80 @@ event_copy_conferences (void) /*********************************************************************************************************************/ +#define STUB_EVENT_SEQUENCE "BEGIN:VEVENT\n" \ + "SUMMARY:Stub event\n" \ + "UID:example@uid\n" \ + "DTSTAMP:19970114T170000Z\n" \ + "SEQUENCE:3\n" \ + "DTSTART:20180714T170000Z\n" \ + "DTEND:20180715T035959Z\n" \ + "END:VEVENT\n" + +static gint64 +get_dtstamp_unix (GcalEvent *event) +{ + g_autoptr (ICalTime) dtstamp = NULL; + + dtstamp = e_cal_component_get_dtstamp (gcal_event_get_component (event)); + g_assert_nonnull (dtstamp); + + return i_cal_time_as_timet (dtstamp); +} + +static void +move_event (GcalEvent *event, + gint hours) +{ + g_autoptr (GDateTime) start = g_date_time_add_hours (gcal_event_get_date_start (event), hours); + g_autoptr (GDateTime) end = g_date_time_add_hours (gcal_event_get_date_end (event), hours); + + gcal_event_set_date_start (event, start); + gcal_event_set_date_end (event, end); +} + +static void +event_prepare_to_save (void) +{ + g_autoptr (GcalEvent) original = NULL; + g_autoptr (GcalEvent) edited = NULL; + g_autoptr (GcalEvent) renamed = NULL; + g_autoptr (GcalEvent) created = NULL; + g_autoptr (GError) error = NULL; + gint64 before; + + original = create_event_for_string (STUB_EVENT_SEQUENCE, &error); + g_assert_no_error (error); + + before = g_get_real_time () / G_USEC_PER_SEC; + + /* Moving the time around in the editor only counts once */ + edited = gcal_event_new_from_event (original); + move_event (edited, 1); + move_event (edited, 1); + move_event (edited, 1); + g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (edited)), ==, 3); + gcal_event_prepare_to_save (edited, FALSE); + g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (edited)), ==, 4); + g_assert_cmpint (get_dtstamp_unix (edited), >=, before); + + /* Renaming isn't a significant change, but the event is stamped anew */ + renamed = gcal_event_new_from_event (original); + gcal_event_set_summary (renamed, "Renamed"); + gcal_event_prepare_to_save (renamed, FALSE); + g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (renamed)), ==, 3); + g_assert_cmpint (get_dtstamp_unix (renamed), >=, before); + + /* A new event starts at 0, however much it was edited before saving */ + created = gcal_event_new_from_event (original); + move_event (created, 2); + move_event (created, 2); + gcal_event_prepare_to_save (created, TRUE); + g_assert_cmpint (e_cal_component_get_sequence (gcal_event_get_component (created)), ==, 0); + g_assert_cmpint (get_dtstamp_unix (created), >=, before); +} + +/*********************************************************************************************************************/ + gint main (gint argc, gchar *argv[]) @@ -825,6 +900,7 @@ main (gint argc, g_test_add_func ("/event/conference/add", event_add_conference); g_test_add_func ("/event/conference/remove", event_remove_conference); g_test_add_func ("/event/conference/copy", event_copy_conferences); + g_test_add_func ("/event/prepare-to-save", event_prepare_to_save); return g_test_run (); }