From 99fc9118b37f8564cd6e211d3d77ef997592f361 Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 2 Feb 2025 23:14:00 +0100 Subject: [PATCH] Fixed audio notification --- pyproject.toml | 3 +- src/snek/static/app.js | 82 ++-------------------------------- src/snek/static/chat-window.js | 11 +++-- 3 files changed, 13 insertions(+), 83 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 98207fd..423a69d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ dependencies = [ "cryptography", "requests", "asyncssh", - "emoji" + "emoji", + "pywebpush" ] diff --git a/src/snek/static/app.js b/src/snek/static/app.js index 44853f1..46df3df 100644 --- a/src/snek/static/app.js +++ b/src/snek/static/app.js @@ -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 { debug = false @@ -378,7 +302,8 @@ class App extends EventHandler { rest = rest ws = null rpc = null - audio = null + audio = null + user = {} constructor() { super() this.rooms.push(new Room("General")) @@ -389,6 +314,7 @@ class App extends EventHandler { this.ws.addEventListener("channel-message", (data) => { me.emit(data.channel_uid, data) }) + this.user = await this.rpc.getUser(null) } playSound(index){ this.audio.play(index) @@ -417,4 +343,4 @@ class App extends EventHandler { } -const app = new App() \ No newline at end of file +const app = new App() diff --git a/src/snek/static/chat-window.js b/src/snek/static/chat-window.js index 58845b4..ce02fd3 100644 --- a/src/snek/static/chat-window.js +++ b/src/snek/static/chat-window.js @@ -6,10 +6,12 @@ class ChatWindowElement extends HTMLElement { super(); this.attachShadow({ mode: 'open' }); this.component = document.createElement('section'); - + this.app = app this.shadowRoot.appendChild(this.component); } - + get user() { + return this.app.user + } async connectedCallback() { const link = document.createElement('link') link.rel = 'stylesheet' @@ -61,7 +63,8 @@ class ChatWindowElement extends HTMLElement { }) const me = this channelElement.addEventListener("message",(message)=>{ - app.playSound(0) + if(me.user.uid != message.detail.user_uid) + app.playSound(0) message.detail.element.scrollIntoView() }) @@ -72,4 +75,4 @@ class ChatWindowElement extends HTMLElement { } -customElements.define('chat-window', ChatWindowElement); \ No newline at end of file +customElements.define('chat-window', ChatWindowElement);