From 72cb1956b0e5f58d6ab0511d26298458352a75a6 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Fri, 20 Oct 2017 11:26:26 +0200 Subject: [PATCH] Start listening for standard post messages and ignore deprecated ones (#126) New online versions emits both the post messages (the older one with a deprecated flag and newer one without). Ignore if the deprecated flag is mentioned because it means that we would get another post message without deprecated flag. --- js/documents.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/js/documents.js b/js/documents.js index 8d10fd23..709c6b45 100644 --- a/js/documents.js +++ b/js/documents.js @@ -353,13 +353,25 @@ var documentsMain = { } try { - var msg = JSON.parse(e.data).MessageId; + var msg = JSON.parse(e.data); + var msgId = msg.MessageId; + var args = msg.Values; + var deprecated = !!args.Deprecated; } catch(exc) { - msg = e.data; + msgId = e.data; } - if (msg === 'UI_Close' || msg === 'close') { + + if (msgId === 'UI_Close' || msgId === 'close' /* deprecated */) { + // If a postmesage API is deprecated, we must ignore it and wait for the standard postmessage + // (or it might already have been fired) + if (deprecated) + return; + documentsMain.onClose(); - } else if (msg === 'rev-history') { + } else if (msgId === 'UI_FileVersions' || msgId === 'rev-history' /* deprecated */) { + if (deprecated) + return; + documentsMain.UI.showRevHistory(documentsMain.fullPath); } });