From 562575ee02367f3f3ac83d323bfc8a16c70185d1 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 9 Apr 2021 13:23:28 +0200 Subject: [PATCH] Fix calendar errors --- www/common/outer/calendar.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/www/common/outer/calendar.js b/www/common/outer/calendar.js index a44fd93dc..bfabf8134 100644 --- a/www/common/outer/calendar.js +++ b/www/common/outer/calendar.js @@ -554,12 +554,17 @@ ctx.calendars[channel] = { return void cb({error: err.error}); } // Add the calendar and call back - c[cal.channel] = cal; - var pin = store.pin || ctx.pinPads; - pin([cal.channel], function (res) { - if (res && res.error) { console.error(res.error); } + // Wait for the metadata to be stored (channel fully ready) before adding it + // to our store + var ctxCal = ctx.calendars[cal.channel]; + Realtime.whenRealtimeSyncs(ctxCal.lm.realtime, function () { + c[cal.channel] = cal; + var pin = store.pin || ctx.pinPads; + pin([cal.channel], function (res) { + if (res && res.error) { console.error(res.error); } + }); + ctx.Store.onSync(store.id, cb); }); - ctx.Store.onSync(store.id, cb); }); }; var updateCalendar = function (ctx, data, cId, cb) { @@ -635,7 +640,8 @@ ctx.calendars[channel] = { var newC; if (changes.calendarId) { newC = ctx.calendars[changes.calendarId]; - if (!newC || !newC.proxy || !newC.proxy.content) { return void cb({error: "ENOENT"}); } + if (!newC || !newC.proxy) { return void cb({error: "ENOENT"}); } + newC.proxy.content = newC.proxy.content || {}; } Object.keys(changes).forEach(function (key) {