From eb7e00a908b914033882662148558e43167a01b2 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 27 Jul 2020 10:13:13 -0600 Subject: [PATCH] Calendar: Fix existing event filtering on push changes Fixes new events did not show up --- calendar/inc/class.calendar_uiforms.inc.php | 4 ++-- calendar/js/app.js | 15 ++++++++++----- calendar/js/app.ts | 17 +++++++++++------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index 5989fca723..a36c7fe104 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -995,7 +995,7 @@ class calendar_uiforms extends calendar_ui } $response = Api\Json\Response::get(); - if($response && $update_type != 'delete') + if($response && $update_type != 'delete' && !$client_updated) { $client_updated = $this->update_client($event['id']); } @@ -1110,7 +1110,7 @@ class calendar_uiforms extends calendar_ui } // New event, send data before updating so it's there $response = Api\Json\Response::get(); - if($response && !$content['id'] && $event['id']) + if($response && !$content['id'] && $event['id'] && !$client_updated) { $client_updated = $this->update_client($event['id']); } diff --git a/calendar/js/app.js b/calendar/js/app.js index 67aac36507..c5e3eb6475 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -578,17 +578,22 @@ var CalendarApp = /** @class */ (function (_super) { // The event is outside our current view return; } - // Ask for the real data + // Do we already have "fresh" data? Most user actions give fresh data in response + var existing = egw.dataGetUIDdata('calendar::' + pushData.id); + if (existing && Math.abs(existing.timestamp - new Date().valueOf()) < 1000) { + // Update directly + this._update_events(this.state, ['calendar::' + pushData.id]); + return; + } + ; + // Ask for the real data, we don't have it egw.json("calendar.calendar_ui.ajax_get", [[pushData.id]], function (data) { if (data && data.data && data.data.data) return; - var unknown = (typeof egw.dataGetUIDdata(data.uid) === "undefined"); // Store it, which will call all registered listeners egw.dataStoreUID(data.uid, data.data); // Any existing events were updated. Run this to catch new events or events moved into view - if (unknown) { - this._update_events(this.state, [data.uid]); - } + this._update_events(this.state, [data.uid]); }.bind(this)).sendRequest(true); }; /** diff --git a/calendar/js/app.ts b/calendar/js/app.ts index d3a31c8437..8354b9aeb6 100644 --- a/calendar/js/app.ts +++ b/calendar/js/app.ts @@ -520,19 +520,24 @@ class CalendarApp extends EgwApp return; } - // Ask for the real data + // Do we already have "fresh" data? Most user actions give fresh data in response + let existing = egw.dataGetUIDdata('calendar::'+pushData.id); + if(existing && Math.abs(existing.timestamp - new Date().valueOf()) < 1000) + { + // Update directly + this._update_events(this.state, ['calendar::'+pushData.id]); + return; + }; + + // Ask for the real data, we don't have it egw.json("calendar.calendar_ui.ajax_get", [[pushData.id]], function(data) { if(data && data.data && data.data.data) return; - let unknown = (typeof egw.dataGetUIDdata(data.uid) === "undefined"); // Store it, which will call all registered listeners egw.dataStoreUID(data.uid, data.data); // Any existing events were updated. Run this to catch new events or events moved into view - if(unknown) - { - this._update_events(this.state, [data.uid]); - } + this._update_events(this.state, [data.uid]); }.bind(this)).sendRequest(true); }