From 37cdbacf684665eebe0a47cbe25d3aa534a00a39 Mon Sep 17 00:00:00 2001 From: armored-dragon Date: Wed, 1 Jan 2025 07:35:04 -0600 Subject: [PATCH] Message embedding toggle. --- scripts/system/domainChat/domainChat.js | 11 ++++---- scripts/system/domainChat/domainChat.qml | 25 ++++++++++++++++++ scripts/system/domainChat/formatting.js | 32 +++++++++++++----------- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/scripts/system/domainChat/domainChat.js b/scripts/system/domainChat/domainChat.js index e1e73bd6cb..5a97c4dee9 100644 --- a/scripts/system/domainChat/domainChat.js +++ b/scripts/system/domainChat/domainChat.js @@ -19,7 +19,8 @@ external_window: false, maximum_messages: 200, join_notification: true, - switchToInternalOnHeadsetUsed: true + switchToInternalOnHeadsetUsed: true, + enableEmbedding: false // Prevents information leakage, default false }; let temporaryChangeModeToVirtual = false; @@ -109,7 +110,7 @@ if (message.channel == "local" && isTooFar(message.position)) return; // If message is local, and if player is too far away from location, do nothing. let formattedMessagePacket = { ...message }; - formattedMessagePacket.message = await formatting.parseMessage(message.message) + formattedMessagePacket.message = await formatting.parseMessage(message.message, settings.enableEmbedding) _emitEvent({ type: "show_message", ...formattedMessagePacket }); // Update qml view of to new message. _notificationCoreMessage(message.displayName, message.message) // Show a new message on screen. @@ -247,9 +248,9 @@ if (messageHistory) { // Load message history for (message of messageHistory) { - messagePacket = { ...message }; // Create new variable - messagePacket = formatting.addTimeAndDateStringToPacket(messagePacket); // Add timestamp - messagePacket.message = await formatting.parseMessage(messagePacket.message); // Parse the message for the UI + messagePacket = { ...message }; // Create new variable + messagePacket = formatting.addTimeAndDateStringToPacket(messagePacket); // Add timestamp + messagePacket.message = await formatting.parseMessage(messagePacket.message, settings.enableEmbedding); // Parse the message for the UI _emitEvent({ type: "show_message", ...messagePacket }); // Send message to UI } diff --git a/scripts/system/domainChat/domainChat.qml b/scripts/system/domainChat/domainChat.qml index 287bb1a825..ef5860587a 100644 --- a/scripts/system/domainChat/domainChat.qml +++ b/scripts/system/domainChat/domainChat.qml @@ -392,6 +392,29 @@ Rectangle { } } } + // Toggle media embedding + Rectangle { + width: parent.width + height: 40 + color: "transparent" + + Text { + text: "Enable media embedding" + color: "white" + font.pointSize: 12 + anchors.verticalCenter: parent.verticalCenter + } + + CheckBox { + id: s_enable_embedding + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + + onCheckedChanged: { + toScript({type: 'setting_change', setting: 'enableEmbedding', value: checked}) + } + } + } } } @@ -456,11 +479,13 @@ Rectangle { domain.clear(); break; case "initial_settings": + print(JSON.stringify(message.settings)); if (message.settings.external_window) s_external_window.checked = true; if (message.settings.maximum_messages) s_maximum_messages.value = message.settings.maximum_messages; if (message.settings.join_notification) s_join_notification.checked = true; if (message.settings.switchToInternalOnHeadsetUsed) s_force_vw_in_vr.checked = true; + if (message.settings.enableEmbedding) s_enable_embedding.checked = true; break; } } diff --git a/scripts/system/domainChat/formatting.js b/scripts/system/domainChat/formatting.js index 5e1458db8d..24662e4ff1 100644 --- a/scripts/system/domainChat/formatting.js +++ b/scripts/system/domainChat/formatting.js @@ -38,7 +38,7 @@ const formatting = { }; return newPacket; }, - parseMessage: async function(message) { + parseMessage: async function(message, enableEmbedding) { const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/; const overteLocationRegex = /hifi:\/\/[a-zA-Z0-9_-]+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+\/[-+]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+,[+-]?\d*\.?\d+/; @@ -67,23 +67,25 @@ const formatting = { } // Embed images in the message array. - for (dataChunk of messageArray){ - if (dataChunk.type == 'url'){ - let url = dataChunk.value; + if (enableEmbedding) { + for (dataChunk of messageArray){ + if (dataChunk.type == 'url'){ + let url = dataChunk.value; - const res = await formatting.helpers.fetch(url, {method: 'GET'}); // TODO: Replace with 'HEAD' method. https://github.com/overte-org/overte/issues/1273 - const contentType = res.getResponseHeader("content-type"); + const res = await formatting.helpers.fetch(url, {method: 'GET'}); // TODO: Replace with 'HEAD' method. https://github.com/overte-org/overte/issues/1273 + const contentType = res.getResponseHeader("content-type"); - if (contentType.startsWith('image/')) { - messageArray.push({type: 'imageEmbed', value: url}); - continue; - } - if (contentType.startsWith('video/')){ - messageArray.push({type: 'videoEmbed', value: url}); - continue; + if (contentType.startsWith('image/')) { + messageArray.push({type: 'imageEmbed', value: url}); + continue; + } + if (contentType.startsWith('video/')){ + messageArray.push({type: 'videoEmbed', value: url}); + continue; + } } - } - } + } + } return messageArray;