[gnome-shell/4592-calendar-correct-handling-of-recurring-events] calendar: Correct handling of recurring events



commit 5bba79a2dccdf694527df5a3ef5dab0fe4853772
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jun 6 17:33:21 2022 +0200

    calendar: Correct handling of recurring events
    
    When a recurring event has deleted a single instance, it's received
    as an event modification, thus make sure all of the old instances
    are removed before adding the event to the list of events.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4592

 js/ui/calendar.js | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index f0b8c97f53..87c9f7329d 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -273,6 +273,15 @@ class DBusEventSource extends EventSourceBase {
         this._lastRequestEnd = null;
     }
 
+    _removeMatching(uidPrefix) {
+        let changed = false;
+        for (const id of this._events.keys()) {
+            if (id.startsWith(uidPrefix))
+                changed = this._events.delete(id) || changed;
+        }
+        return changed;
+    }
+
     _onNameAppeared() {
         this._initialized = true;
         this._resetCache();
@@ -287,12 +296,21 @@ class DBusEventSource extends EventSourceBase {
     _onEventsAddedOrUpdated(dbusProxy, nameOwner, argArray) {
         const [appointments = []] = argArray;
         let changed = false;
+        let handledRemovals = new Map();
 
         for (let n = 0; n < appointments.length; n++) {
             const [id, summary, startTime, endTime] = appointments[n];
             const date = new Date(startTime * 1000);
             const end = new Date(endTime * 1000);
             let event = new CalendarEvent(id, date, end, summary);
+            /* It's a recurring event */
+            if (!id.endsWith("\n")) {
+                let parentId = id.substr(0, id.lastIndexOf('\n') + 1);
+                if (!handledRemovals.has(parentId)) {
+                    handledRemovals.set(parentId, parentId);
+                    this._removeMatching(parentId);
+                }
+            }
             this._events.set(event.id, event);
 
             changed = true;
@@ -307,7 +325,7 @@ class DBusEventSource extends EventSourceBase {
 
         let changed = false;
         for (const id of ids)
-            changed ||= this._events.delete(id);
+            changed = this._removeMatching(id) || changed;
 
         if (changed)
             this.emit('changed');
@@ -317,13 +335,7 @@ class DBusEventSource extends EventSourceBase {
         let [sourceUid = ''] = argArray;
         sourceUid += '\n';
 
-        let changed = false;
-        for (const id of this._events.keys()) {
-            if (id.startsWith(sourceUid))
-                changed ||= this._events.delete(id);
-        }
-
-        if (changed)
+        if (_removeMatching(sourceUid))
             this.emit('changed');
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]