From 685be534ec14ea7b08d3cc0f83dbe00ca68a9957 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 24 Apr 2020 11:37:35 +0200 Subject: [PATCH] Clear ghost data on ready if you're alone --- www/pad/comments.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/www/pad/comments.js b/www/pad/comments.js index cf946e4d0..514c1aae7 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -462,6 +462,22 @@ define([ var ready = function (Env) { Env.ready = 0; + + // If you're the only edit user online, clear "deleted" comments + if (!Env.common.isLoggedIn()) { return; } + var users = Env.metadataMgr.getMetadata().users || {}; + var isNotAlone = Object.keys(users).length > 1; + if (isNotAlone) { return; } + + // Clear data + var data = (Env.comments && Env.comments.data) || {}; + Object.keys(data).forEach(function (uid) { + if (data[uid].deleted) { delete data[uid]; } + }); + + // Commit + updateMetadata(Env); + Env.framework.localChange(); }; Comments.create = function (cfg) {