Skip to content

Commit

Permalink
Message embedding toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Armored-Dragon committed Jan 1, 2025
1 parent cf4ec3f commit 37cdbac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
11 changes: 6 additions & 5 deletions scripts/system/domainChat/domainChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions scripts/system/domainChat/domainChat.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
}
}
}
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
32 changes: 17 additions & 15 deletions scripts/system/domainChat/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+/;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 37cdbac

Please sign in to comment.