From 1c797565b7645a094f57d3aa713e0e27c8a0c048 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 22 Jan 2024 13:12:14 +0000 Subject: [PATCH] Cleaned up compatibility declarations. --- src/mami.js/compat.js | 44 +++++++++++++++++++++---------------- src/mami.js/settings.js | 2 -- src/mami.js/sockchat_old.js | 1 - 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/mami.js/compat.js b/src/mami.js/compat.js index 349e08b..f21d9cf 100644 --- a/src/mami.js/compat.js +++ b/src/mami.js/compat.js @@ -1,26 +1,32 @@ #include server.js -// backwards compat for scripts -if(!Umi) window.Umi = {}; +const MamiCompat = (current, path, handler) => { + if(typeof path !== 'string') + throw 'path must be a string'; + if(typeof handler !== 'function') + throw 'handler must be a function'; -if(!Umi.Server) Umi.Server = {}; -if(!Umi.Server.sendMessage) Umi.Server.sendMessage = function() { console.log('Umi.Server.sendMessage called'); }; -if(!Umi.Server.SendMessage) Umi.Server.SendMessage = Umi.Server.sendMessage.bind(Umi.Server); + path = path.split('.'); -if(!Umi.Protocol) Umi.Protocol = {}; -if(!Umi.Protocol.SockLegacy) Umi.Protocol.SockLegacy = {}; -if(!Umi.Protocol.SockLegacy.Protocol) Umi.Protocol.SockLegacy.Protocol = {}; -if(!Umi.Protocol.SockLegacy.Protocol.Instance) Umi.Protocol.SockLegacy.Protocol.Instance = {}; -if(!Umi.Protocol.SockLegacy.Protocol.Instance.SendMessage) Umi.Protocol.SockLegacy.Protocol.Instance.SendMessage = Umi.Server.sendMessage.bind(Umi.Server); + const final = path.pop(); + if(final === undefined) + throw 'invalid path'; -if(!Umi.Parser) Umi.Parser = {}; -if(!Umi.Parser.SockChatBBcode) Umi.Parser.SockChatBBcode = {}; -if(!Umi.Parser.SockChatBBcode.EmbedStub) Umi.Parser.SockChatBBcode.EmbedStub = function() {}; + for(const part of path) { + if(!(part in current)) + current[part] = {}; + current = current[part]; + } -if(!Umi.UI) Umi.UI = {}; -if(!Umi.UI.View) Umi.UI.View = {}; -if(!Umi.UI.View.SetText) Umi.UI.View.SetText = function() { console.log('Umi.UI.View.SetText called'); }; + if(!(final in current)) + current[final] = handler; +}; -if(!Umi.UI.Menus) Umi.UI.Menus = {}; -if(!Umi.UI.Menus.Add) Umi.UI.Menus.Add = function() { console.log('Umi.UI.Menus.Add called'); }; -if(!Umi.UI.Menus.Get) Umi.UI.Menus.Get = function() { console.log('Umi.UI.Menus.Get called'); }; +// Backwards compat for scripts +// Keep in sync with for as long as possible +MamiCompat(Umi, 'Server.SendMessage', Umi.Server.sendMessage.bind(Umi.Server)); +MamiCompat(Umi, 'Protocol.SockLegacy.Protocol.Instance.SendMessage', Umi.Server.sendMessage.bind(Umi.Server)); +MamiCompat(Umi, 'Parser.SockChatBBcode.EmbedStub', function() {}); // intentionally a no-op +MamiCompat(Umi, 'UI.View.SetText', function() { console.log('Umi.UI.View.SetText called'); }); +MamiCompat(Umi, 'UI.Menus.Add', function() { console.log('Umi.UI.Menus.Add called'); }); +MamiCompat(Umi, 'UI.Menus.Get', function() { console.log('Umi.UI.Menus.Get called'); }); diff --git a/src/mami.js/settings.js b/src/mami.js/settings.js index 3f00950..a2c13a6 100644 --- a/src/mami.js/settings.js +++ b/src/mami.js/settings.js @@ -702,8 +702,6 @@ Umi.Settings = function(metaData) { localStorage.removeItem(prefix + name); }; - removeRaw('cookiesMigrated'); - const hasValue = function(name) { if(!mutable.includes(name)) return false; diff --git a/src/mami.js/sockchat_old.js b/src/mami.js/sockchat_old.js index c3ff9ae..1b89a3d 100644 --- a/src/mami.js/sockchat_old.js +++ b/src/mami.js/sockchat_old.js @@ -19,7 +19,6 @@ #include ui/loading-overlay.jsx #include sound/umisound.js -if(!Umi) window.Umi = {}; if(!Umi.Protocol) Umi.Protocol = {}; if(!Umi.Protocol.SockChat) Umi.Protocol.SockChat = {}; if(!Umi.Protocol.SockChat.Protocol) Umi.Protocol.SockChat.Protocol = {};