aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@noreply.codeberg.org>2024-12-09 09:16:36 +0000
committermetamuffin <metamuffin@noreply.codeberg.org>2024-12-09 09:16:36 +0000
commitaee091c28ad99862f8d94665a1efc65288a17d52 (patch)
tree3a02e3509ca166c9e0e8b535dadd6c10e6f7c6c0
parent440c12ac024e84f166eaa4115ef6715c39de2eea (diff)
parent169b675f9d725ae94d9a1fdc6ae67932b4a4a163 (diff)
downloadkeks-meet-aee091c28ad99862f8d94665a1efc65288a17d52.tar
keks-meet-aee091c28ad99862f8d94665a1efc65288a17d52.tar.bz2
keks-meet-aee091c28ad99862f8d94665a1efc65288a17d52.tar.zst
Merge pull request 'add hyperlink support for chat' (#10) from polferov/keks-meet:master into master
Reviewed-on: https://codeberg.org/metamuffin/keks-meet/pulls/10
-rw-r--r--client-web/source/chat.ts15
-rw-r--r--client-web/style/chat.sass3
2 files changed, 16 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)
diff --git a/client-web/style/chat.sass b/client-web/style/chat.sass
index a2f78fe..1e0c1d6 100644
--- a/client-web/style/chat.sass
+++ b/client-web/style/chat.sass
@@ -36,3 +36,6 @@
border-radius: 5px
padding: 0.5em
box-sizing: border-box
+
+ .chat-link
+ color: var(--ac-light) \ No newline at end of file