Fixed audio notification

This commit is contained in:
retoor 2025-02-02 23:14:00 +01:00
parent a06e3f404a
commit 99fc9118b3
3 changed files with 13 additions and 83 deletions

View File

@ -26,6 +26,7 @@ dependencies = [
"cryptography", "cryptography",
"requests", "requests",
"asyncssh", "asyncssh",
"emoji" "emoji",
"pywebpush"
] ]

View File

@ -1,81 +1,5 @@
/*class Message {
uid = null
author = null
avatar = null
text = null
time = null
constructor(uid,avatar,author,text,time){
this.uid = uid
this.avatar = avatar
this.author = author
this.text = text
this.time = time
}
get links() {
if(!this.text)
return []
let result = []
for(let part in this.text.split(/[,; ]/)){
if(part.startsWith("http") || part.startsWith("www.") || part.indexOf(".com") || part.indexOf(".net") || part.indexOf(".io") || part.indexOf(".nl")){
result.push(part)
}
}
return result
}
get mentions() {
if(!this.text)
return []
let result = []
for(let part in this.text.split(/[,; ]/)){
if(part.startsWith("@")){
result.push(part)
}
}
return result
}
}*/
class Messages {
}
class Room {
name = null
messages = []
constructor(name) {
this.name = name
}
setMessages(list) {
}
}
class InlineAppElement extends HTMLElement {
constructor() {
// this.
}
}
class Page {
elements = []
}
class RESTClient { class RESTClient {
debug = false debug = false
@ -378,7 +302,8 @@ class App extends EventHandler {
rest = rest rest = rest
ws = null ws = null
rpc = null rpc = null
audio = null audio = null
user = {}
constructor() { constructor() {
super() super()
this.rooms.push(new Room("General")) this.rooms.push(new Room("General"))
@ -389,6 +314,7 @@ class App extends EventHandler {
this.ws.addEventListener("channel-message", (data) => { this.ws.addEventListener("channel-message", (data) => {
me.emit(data.channel_uid, data) me.emit(data.channel_uid, data)
}) })
this.user = await this.rpc.getUser(null)
} }
playSound(index){ playSound(index){
this.audio.play(index) this.audio.play(index)
@ -417,4 +343,4 @@ class App extends EventHandler {
} }
const app = new App() const app = new App()

View File

@ -6,10 +6,12 @@ class ChatWindowElement extends HTMLElement {
super(); super();
this.attachShadow({ mode: 'open' }); this.attachShadow({ mode: 'open' });
this.component = document.createElement('section'); this.component = document.createElement('section');
this.app = app
this.shadowRoot.appendChild(this.component); this.shadowRoot.appendChild(this.component);
} }
get user() {
return this.app.user
}
async connectedCallback() { async connectedCallback() {
const link = document.createElement('link') const link = document.createElement('link')
link.rel = 'stylesheet' link.rel = 'stylesheet'
@ -61,7 +63,8 @@ class ChatWindowElement extends HTMLElement {
}) })
const me = this const me = this
channelElement.addEventListener("message",(message)=>{ channelElement.addEventListener("message",(message)=>{
app.playSound(0) if(me.user.uid != message.detail.user_uid)
app.playSound(0)
message.detail.element.scrollIntoView() message.detail.element.scrollIntoView()
}) })
@ -72,4 +75,4 @@ class ChatWindowElement extends HTMLElement {
} }
customElements.define('chat-window', ChatWindowElement); customElements.define('chat-window', ChatWindowElement);