mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 07:12:40 +02:00
Message embedding toggle.
This commit is contained in:
parent
624ceefc24
commit
30bfe0d038
3 changed files with 48 additions and 20 deletions
|
@ -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;
|
||||
|
||||
|
@ -110,7 +111,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.
|
||||
|
@ -248,9 +249,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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue