From e8526aa6b75458918d2161a1a321a2f416c5b32e Mon Sep 17 00:00:00 2001 From: Kalila L Date: Thu, 27 Aug 2020 05:28:07 -0400 Subject: [PATCH] Update chat to accept system notifications. --- scripts/communityScripts/chat/FloofChat.js | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/scripts/communityScripts/chat/FloofChat.js b/scripts/communityScripts/chat/FloofChat.js index d1324bd560..b558e52bf8 100644 --- a/scripts/communityScripts/chat/FloofChat.js +++ b/scripts/communityScripts/chat/FloofChat.js @@ -23,6 +23,7 @@ var CONTROL_KEY = 67108864; var SHIFT_KEY = 33554432; var FLOOF_CHAT_CHANNEL = "Chat"; var FLOOF_NOTIFICATION_CHANNEL = "Floof-Notif"; +var SYSTEM_NOTIFICATION_CHANNEL = "System-Notifications"; var MAIN_CHAT_WINDOW_HEIGHT = 450; var MAIN_CHAT_WINDOW_WIDTH = 750; @@ -79,6 +80,7 @@ init(); function init() { Messages.subscribe(FLOOF_CHAT_CHANNEL); + Messages.subscribe(SYSTEM_NOTIFICATION_CHANNEL); historyLog = []; try { historyLog = JSON.parse(Settings.getValue(settingsRoot + "/HistoryLog", "[]")); @@ -435,8 +437,8 @@ function replaceFormatting(text) { } } -function messageReceived(channel, message) { - if (channel === "Chat") { +function messageReceived(channel, message, sender) { + if (channel === FLOOF_CHAT_CHANNEL) { var cmd = {FAILED: true}; try { cmd = JSON.parse(message); @@ -518,6 +520,26 @@ function messageReceived(channel, message) { } } } + + if (channel === SYSTEM_NOTIFICATION_CHANNEL && sender == MyAvatar.sessionUUID) { + var cmd = {FAILED: true}; + try { + cmd = JSON.parse(message); + } catch (e) { + // + } + if (!cmd.FAILED) { + if (cmd.type === "Update-Notification") { + addToLog(cmd.message, cmd.category, cmd.colour, cmd.channel); + + Messages.sendLocalMessage(FLOOF_NOTIFICATION_CHANNEL, JSON.stringify({ + sender: "(" + cmd.category + ")", + text: replaceFormatting(cmd.message), + colour: {text: cmd.colour} + })); + } + } + } } function time() { @@ -569,7 +591,9 @@ function fromQml(message) { cmd = processChat(cmd); if (cmd.message === "") return; Messages.sendMessage(FLOOF_CHAT_CHANNEL, JSON.stringify({ - type: "TransmitChatMessage", channel: "Domain", colour: chatColour("Domain"), + type: "TransmitChatMessage", + channel: "Domain", + colour: chatColour("Domain"), message: cmd.message, displayName: cmd.avatarName }));