aboutsummaryrefslogtreecommitdiff
path: root/client-web/source/chat.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client-web/source/chat.ts')
-rw-r--r--client-web/source/chat.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/client-web/source/chat.ts b/client-web/source/chat.ts
index 1eb9fa5..4531a76 100644
--- a/client-web/source/chat.ts
+++ b/client-web/source/chat.ts
@@ -93,9 +93,20 @@ export class Chat {
el.scrollIntoView({ block: "end", behavior: "smooth", inline: "end" })
}
+ create_text_message(text: string) : HTMLElement {
+ const div = document.createElement("div")
+ div.classList.add("text")
+
+ // test for uris and make them clickable
+ const regex = (/(\b[a-z]{2,15}:\/\/\S+\b)/ig)
+ div.innerText = text // assigning to innerText will escape the html
+ div.innerHTML = div.innerHTML.replaceAll(regex, '<a href="$1" target="_blank" class="chat-link">$1</a>')
+ return div
+ }
+
add_message(sender: User, message: ChatMessage) {
- const els = []
- if (message.text) els.push(e("span", { class: "text" }, message.text))
+ const els : HTMLElement[] = []
+ if (message.text) els.push(this.create_text_message(message.text))
if (message.image) els.push(image_view(message.image, { class: "image" }))
chat_control(true)