[evolution-data-server] ews-I#144 - Calendar: Dismiss of a reminder doesn't provide recurrence ID
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] ews-I#144 - Calendar: Dismiss of a reminder doesn't provide recurrence ID
- Date: Tue, 23 Feb 2021 10:06:23 +0000 (UTC)
commit 7ea69fa1b6d169b651b4fad5c2010dd7289ef38d
Author: Milan Crha <mcrha redhat com>
Date: Tue Feb 23 11:04:21 2021 +0100
ews-I#144 - Calendar: Dismiss of a reminder doesn't provide recurrence ID
Related to https://gitlab.gnome.org/GNOME/evolution-ews/-/issues/144
.../libecal/e-cal-component-alarm-instance.c | 58 ++++++++++++++++++++--
.../libecal/e-cal-component-alarm-instance.h | 5 ++
src/calendar/libecal/e-cal-util.c | 24 +++++++--
src/calendar/libecal/e-reminder-watcher.c | 24 +++++++--
tests/libecal/test-cal-component.c | 16 ++++--
5 files changed, 112 insertions(+), 15 deletions(-)
---
diff --git a/src/calendar/libecal/e-cal-component-alarm-instance.c
b/src/calendar/libecal/e-cal-component-alarm-instance.c
index 8e5328d67..896229679 100644
--- a/src/calendar/libecal/e-cal-component-alarm-instance.c
+++ b/src/calendar/libecal/e-cal-component-alarm-instance.c
@@ -34,6 +34,9 @@ struct _ECalComponentAlarmInstance {
/* UID of the alarm that instanceed */
gchar *uid;
+ /* recurrence ID of the component the alarm was generated from */
+ gchar *rid;
+
/* Instance time, i.e. "5 minutes before the appointment" */
time_t instance_time;
@@ -43,7 +46,7 @@ struct _ECalComponentAlarmInstance {
};
/**
- * e_cal_component_alarm_instance_new_relative:
+ * e_cal_component_alarm_instance_new:
* @uid: (not nullable): UID of the alarm
* @instance_time: instance time, i.e. "5 minutes before the appointment"
* @occur_start: actual event occurrence start to which this instance corresponds
@@ -68,6 +71,7 @@ e_cal_component_alarm_instance_new (const gchar *uid,
instance = g_slice_new0 (ECalComponentAlarmInstance);
instance->uid = g_strdup (uid);
+ instance->rid = NULL;
instance->instance_time = instance_time;
instance->occur_start = occur_start;
instance->occur_end = occur_end;
@@ -89,12 +93,19 @@ e_cal_component_alarm_instance_new (const gchar *uid,
ECalComponentAlarmInstance *
e_cal_component_alarm_instance_copy (const ECalComponentAlarmInstance *instance)
{
+ ECalComponentAlarmInstance *instnc;
+
g_return_val_if_fail (instance != NULL, NULL);
- return e_cal_component_alarm_instance_new (instance->uid,
+ instnc = e_cal_component_alarm_instance_new (instance->uid,
instance->instance_time,
instance->occur_start,
instance->occur_end);
+
+ e_cal_component_alarm_instance_set_rid (instnc,
+ e_cal_component_alarm_instance_get_rid (instance));
+
+ return instnc;
}
/**
@@ -114,6 +125,7 @@ e_cal_component_alarm_instance_free (gpointer instance)
if (instnc) {
g_free (instnc->uid);
+ g_free (instnc->rid);
g_slice_free (ECalComponentAlarmInstance, instnc);
}
}
@@ -136,7 +148,7 @@ e_cal_component_alarm_instance_get_uid (const ECalComponentAlarmInstance *instan
/**
* e_cal_component_alarm_instance_set_uid:
- * @instance: an ECalComponentAlarmInstance
+ * @instance: an #ECalComponentAlarmInstance
* @uid: (not nullable): alarm UID to set
*
* Set the alarm UID.
@@ -156,6 +168,46 @@ e_cal_component_alarm_instance_set_uid (ECalComponentAlarmInstance *instance,
}
}
+/**
+ * e_cal_component_alarm_instance_get_rid:
+ * @instance: an #ECalComponentAlarmInstance
+ *
+ * Returns: (nullable): the Recurrence ID of the component this @instance was generated for.
+ *
+ * Since: 3.40
+ **/
+const gchar *
+e_cal_component_alarm_instance_get_rid (const ECalComponentAlarmInstance *instance)
+{
+ g_return_val_if_fail (instance != NULL, NULL);
+
+ return instance->rid;
+}
+
+/**
+ * e_cal_component_alarm_instance_set_rid:
+ * @instance: an #ECalComponentAlarmInstance
+ * @rid: (nullable): recurrence UID to set, or %NULL
+ *
+ * Set the Recurrence ID of the component this @instance was generated for.
+ *
+ * Since: 3.40
+ **/
+void
+e_cal_component_alarm_instance_set_rid (ECalComponentAlarmInstance *instance,
+ const gchar *rid)
+{
+ g_return_if_fail (instance != NULL);
+
+ if (rid && !*rid)
+ rid = NULL;
+
+ if (g_strcmp0 (instance->rid, rid) != 0) {
+ g_free (instance->rid);
+ instance->rid = g_strdup (rid);
+ }
+}
+
/**
* e_cal_component_alarm_instance_get_time:
* @instance: an #ECalComponentAlarmInstance
diff --git a/src/calendar/libecal/e-cal-component-alarm-instance.h
b/src/calendar/libecal/e-cal-component-alarm-instance.h
index 15fa56e8a..8f93a6309 100644
--- a/src/calendar/libecal/e-cal-component-alarm-instance.h
+++ b/src/calendar/libecal/e-cal-component-alarm-instance.h
@@ -54,6 +54,11 @@ const gchar * e_cal_component_alarm_instance_get_uid
void e_cal_component_alarm_instance_set_uid
(ECalComponentAlarmInstance *instance,
const gchar *uid);
+const gchar * e_cal_component_alarm_instance_get_rid
+ (const ECalComponentAlarmInstance *instance);
+void e_cal_component_alarm_instance_set_rid
+ (ECalComponentAlarmInstance *instance,
+ const gchar *rid);
time_t e_cal_component_alarm_instance_get_time
(const ECalComponentAlarmInstance *instance);
void e_cal_component_alarm_instance_set_time
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index d18fbbabf..9e87a6526 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -401,6 +401,7 @@ struct alarm_occurrence_data {
static void
add_trigger (struct alarm_occurrence_data *aod,
const gchar *auid,
+ const gchar *rid,
time_t instance_time,
time_t occur_start,
time_t occur_end)
@@ -409,6 +410,9 @@ add_trigger (struct alarm_occurrence_data *aod,
instance = e_cal_component_alarm_instance_new (auid, instance_time, occur_start, occur_end);
+ if (rid && *rid)
+ e_cal_component_alarm_instance_set_rid (instance, rid);
+
aod->triggers = g_slist_prepend (aod->triggers, instance);
aod->n_triggers++;
}
@@ -427,10 +431,17 @@ add_alarm_occurrences_cb (ICalComponent *icalcomp,
struct alarm_occurrence_data *aod;
time_t start, end;
GSList *link;
+ gchar *rid;
aod = user_data;
start = i_cal_time_as_timet_with_zone (instance_start, i_cal_time_get_timezone (instance_start));
end = i_cal_time_as_timet_with_zone (instance_end, i_cal_time_get_timezone (instance_end));
+ rid = e_cal_util_component_get_recurid_as_string (icalcomp);
+
+ if (!rid || !*rid) {
+ g_clear_pointer (&rid, g_free);
+ rid = i_cal_time_as_ical_string (instance_start);
+ }
for (link = aod->alarm_uids; link; link = g_slist_next (link)) {
const gchar *auid;
@@ -503,18 +514,20 @@ add_alarm_occurrences_cb (ICalComponent *icalcomp,
t = trigger_time + (ii + 1) * repeat_time;
if (t >= aod->start && t < aod->end)
- add_trigger (aod, auid, t, start, end);
+ add_trigger (aod, auid, rid, t, start, end);
}
}
/* Add the trigger itself */
if (trigger_time >= aod->start && trigger_time < aod->end)
- add_trigger (aod, auid, trigger_time, start, end);
+ add_trigger (aod, auid, rid, trigger_time, start, end);
e_cal_component_alarm_free (alarm);
}
+ g_free (rid);
+
return TRUE;
}
@@ -529,9 +542,11 @@ generate_absolute_triggers (ECalComponent *comp,
GSList *link;
ECalComponentDateTime *dtstart, *dtend;
time_t occur_start, occur_end;
+ gchar *rid;
dtstart = e_cal_component_get_dtstart (comp);
dtend = e_cal_component_get_dtend (comp);
+ rid = e_cal_component_get_recurid_as_string (comp);
/* No particular occurrence, so just use the times from the
* component */
@@ -631,20 +646,21 @@ generate_absolute_triggers (ECalComponent *comp,
tt = abs_time + (ii + 1) * repeat_time;
if (tt >= aod->start && tt < aod->end)
- add_trigger (aod, auid, tt, occur_start, occur_end);
+ add_trigger (aod, auid, rid, tt, occur_start, occur_end);
}
}
/* Add the trigger itself */
if (abs_time >= aod->start && abs_time < aod->end)
- add_trigger (aod, auid, abs_time, occur_start, occur_end);
+ add_trigger (aod, auid, rid, abs_time, occur_start, occur_end);
e_cal_component_alarm_free (alarm);
}
e_cal_component_datetime_free (dtstart);
e_cal_component_datetime_free (dtend);
+ g_free (rid);
}
/* Compares two alarm instances; called from g_slist_sort() */
diff --git a/src/calendar/libecal/e-reminder-watcher.c b/src/calendar/libecal/e-reminder-watcher.c
index e98972af5..90c2f3f8b 100644
--- a/src/calendar/libecal/e-reminder-watcher.c
+++ b/src/calendar/libecal/e-reminder-watcher.c
@@ -690,6 +690,12 @@ e_reminder_data_to_string (const EReminderData *rd)
if (rd->instance && e_cal_component_alarm_instance_get_uid (rd->instance))
g_string_append (str, e_cal_component_alarm_instance_get_uid (rd->instance));
+
+ if (rd->instance && e_cal_component_alarm_instance_get_rid (rd->instance)) {
+ g_string_append_c (str, '\t');
+ g_string_append (str, e_cal_component_alarm_instance_get_rid (rd->instance));
+ }
+
g_string_append_c (str, '\n');
g_string_append_printf (str, "%" G_GINT64_FORMAT, (gint64) (rd->instance ?
e_cal_component_alarm_instance_get_time (rd->instance) : -1));
@@ -711,7 +717,7 @@ e_reminder_data_to_string (const EReminderData *rd)
static EReminderData *
e_reminder_data_from_string (const gchar *str)
{
- gchar **strv;
+ gchar **strv, *tab;
EReminderData *rd;
ECalComponent *component;
ECalComponentAlarmInstance *instance;
@@ -733,12 +739,23 @@ e_reminder_data_from_string (const gchar *str)
return NULL;
}
+ tab = strchr (strv[1], '\t');
+
+ if (tab)
+ *tab = '\0';
+
instance = e_cal_component_alarm_instance_new (
(*(strv[1])) ? strv[1] : NULL,
g_ascii_strtoll (strv[2], NULL, 10),
g_ascii_strtoll (strv[3], NULL, 10),
g_ascii_strtoll (strv[4], NULL, 10));
+ if (tab) {
+ e_cal_component_alarm_instance_set_rid (instance, tab + 1);
+
+ *tab = '\t';
+ }
+
rd = e_reminder_data_new_take_component (strv[0], component, instance);
e_cal_component_alarm_instance_free (instance);
@@ -3320,7 +3337,7 @@ e_reminder_watcher_dismiss_one_sync (ECalClient *client,
success = e_cal_client_discard_alarm_sync (client,
e_cal_component_id_get_uid (id),
- e_cal_component_id_get_rid (id),
+ e_cal_component_id_get_rid (id) ? e_cal_component_id_get_rid (id) :
e_cal_component_alarm_instance_get_rid (rd->instance),
e_cal_component_alarm_instance_get_uid (rd->instance),
E_CAL_OPERATION_FLAG_NONE,
cancellable, &local_error);
@@ -3328,7 +3345,8 @@ e_reminder_watcher_dismiss_one_sync (ECalClient *client,
e_reminder_watcher_debug_print ("Discard alarm for '%s' from %s (uid:%s rid:%s auid:%s)
%s%s%s%s\n",
i_cal_component_get_summary (e_cal_component_get_icalcomponent (rd->component)),
rd->source_uid, e_cal_component_id_get_uid (id),
- e_cal_component_id_get_rid (id) ? e_cal_component_id_get_rid (id) : "null",
+ e_cal_component_id_get_rid (id) ? e_cal_component_id_get_rid (id) : (
+ e_cal_component_alarm_instance_get_rid (rd->instance) ?
e_cal_component_alarm_instance_get_rid (rd->instance) : "null"),
e_cal_component_alarm_instance_get_uid (rd->instance),
success ? "succeeded" : "failed",
(!success || local_error) ? " (" : "",
diff --git a/tests/libecal/test-cal-component.c b/tests/libecal/test-cal-component.c
index 3af1c2e96..3c2368afb 100644
--- a/tests/libecal/test-cal-component.c
+++ b/tests/libecal/test-cal-component.c
@@ -459,6 +459,7 @@ verify_struct_alarm_instance_equal (const ECalComponentAlarmInstance *expected,
g_assert_nonnull (received);
g_assert_cmpstr (e_cal_component_alarm_instance_get_uid (expected), ==,
e_cal_component_alarm_instance_get_uid (received));
+ g_assert_cmpstr (e_cal_component_alarm_instance_get_rid (expected), ==,
e_cal_component_alarm_instance_get_rid (received));
g_assert_cmpint (e_cal_component_alarm_instance_get_time (expected), ==,
e_cal_component_alarm_instance_get_time (received));
g_assert_cmpint (e_cal_component_alarm_instance_get_occur_start (expected), ==,
e_cal_component_alarm_instance_get_occur_start (received));
g_assert_cmpint (e_cal_component_alarm_instance_get_occur_end (expected), ==,
e_cal_component_alarm_instance_get_occur_end (received));
@@ -781,6 +782,7 @@ test_component_struct_alarms (void)
e_cal_component_alarms_free (received);
instance = e_cal_component_alarm_instance_new ("2", (time_t) 2, (time_t) 3, (time_t) 4);
+ e_cal_component_alarm_instance_set_rid (instance, "r1");
e_cal_component_alarms_take_instance (expected, instance);
g_assert_cmpint (2, ==, g_slist_length (e_cal_component_alarms_get_instances (expected)));
@@ -834,15 +836,16 @@ test_component_struct_alarm_instance (void)
{
struct _values {
const gchar *uid;
+ const gchar *rid;
gint instance_time;
gint occur_start;
gint occur_end;
} values[] = {
- { "1", 1, 2, 3 },
- { "2", 2, 3, 4 },
- { "3", 3, 4, 6 },
- { "4", 4, 5, 6 },
- { "5", 5, 6, 7 }
+ { "1", NULL, 1, 2, 3 },
+ { "2", "r1", 2, 3, 4 },
+ { "3", "r2", 3, 4, 6 },
+ { "4", NULL, 4, 5, 6 },
+ { "5", "r3", 5, 6, 7 }
};
gint ii;
@@ -862,9 +865,12 @@ test_component_struct_alarm_instance (void)
e_cal_component_alarm_instance_set_occur_end (expected, (time_t)
values[ii].occur_end);
}
+ e_cal_component_alarm_instance_set_rid (expected, values[ii].rid);
+
g_assert_nonnull (expected);
g_assert_cmpstr (e_cal_component_alarm_instance_get_uid (expected), ==, values[ii].uid);
+ g_assert_cmpstr (e_cal_component_alarm_instance_get_rid (expected), ==, values[ii].rid);
g_assert_cmpint (e_cal_component_alarm_instance_get_time (expected), ==, (time_t)
values[ii].instance_time);
g_assert_cmpint (e_cal_component_alarm_instance_get_occur_start (expected), ==, (time_t)
values[ii].occur_start);
g_assert_cmpint (e_cal_component_alarm_instance_get_occur_end (expected), ==, (time_t)
values[ii].occur_end);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]