diff --git a/src/snek/service/chat.py b/src/snek/service/chat.py index 9346e40..1de149c 100644 --- a/src/snek/service/chat.py +++ b/src/snek/service/chat.py @@ -13,7 +13,7 @@ class ChatService(BaseService): channel["last_message_on"] = now() await self.services.channel.save(channel) await self.services.socket.broadcast( - channel_uid, + channel['uid'], { "message": channel_message["message"], "html": channel_message["html"], diff --git a/src/snek/static/app.js b/src/snek/static/app.js index 8810952..b839ddb 100644 --- a/src/snek/static/app.js +++ b/src/snek/static/app.js @@ -160,11 +160,15 @@ export class App extends EventHandler { typeLock = null; typeListener = null; typeEventChannelUid = null; - async set_typing(channel_uid) { + _debug = false + async set_typing(channel_uid) { this.typeEventChannel_uid = channel_uid; } - - async ping(...args) { + debug() { + this._debug = !this._debug; + this.ws._debug = this._debug; + } + async ping(...args) { if (this.is_pinging) return false; this.is_pinging = true; await this.rpc.ping(...args); @@ -202,8 +206,10 @@ export class App extends EventHandler { this.ws.addEventListener("channel-message", (data) => { me.emit("channel-message", data); }); - this.ws.addEventListener("event", (data) => { - console.info("aaaa"); + this.ws.addEventListener("data", (data) => { + if(this._debug){ + console.debug(data) + } }); this.rpc.getUser(null).then((user) => { me.user = user; diff --git a/src/snek/static/chat-input.js b/src/snek/static/chat-input.js index cab4285..9e6fa03 100644 --- a/src/snek/static/chat-input.js +++ b/src/snek/static/chat-input.js @@ -179,9 +179,6 @@ levenshteinDistance(a, b) { if (e.key === "Enter" && !e.shiftKey) { this.value = ""; e.target.value = ""; - if(this.messageUid){ - app.rpc.finalizeMessage(this.messageUid) - } return; } this.value = e.target.value; @@ -220,7 +217,7 @@ levenshteinDistance(a, b) { } this.updateMessage() - + app.rpc.finalizeMessage(this.messageUid) this.value = ""; this.previousValue = ""; this.messageUid = null; diff --git a/src/snek/static/message-list.js b/src/snek/static/message-list.js index 5cc8756..70c3573 100644 --- a/src/snek/static/message-list.js +++ b/src/snek/static/message-list.js @@ -51,8 +51,6 @@ class MessageList extends HTMLElement { return this.isElementVisible(this.querySelector(".message-list-bottom")); } scrollToBottom(force) { - console.info("Scrolling down") - // if (force) { this.scrollTop = this.scrollHeight; this.querySelector(".message-list-bottom").scrollIntoView(); @@ -61,7 +59,6 @@ class MessageList extends HTMLElement { this.scrollTop = this.scrollHeight; this.querySelector(".message-list-bottom").scrollIntoView(); },200) - // } } updateMessageText(uid, message) { const messageDiv = this.querySelector('div[data-uid="' + uid + '"]'); @@ -69,12 +66,15 @@ class MessageList extends HTMLElement { if (!messageDiv) { return; } + const scrollToBottom = this.isScrolledToBottom(); const receivedHtml = document.createElement("div"); receivedHtml.innerHTML = message.html; const html = receivedHtml.querySelector(".text").innerHTML; const textElement = messageDiv.querySelector(".text"); textElement.innerHTML = html; textElement.style.display = message.text == "" ? "none" : "block"; + if(scrollToBottom) + this.scrollToBottom(true) } triggerGlow(uid,color) { app.starField.glowColor(color) diff --git a/src/snek/static/socket.js b/src/snek/static/socket.js index 77fbd3c..1131e8f 100644 --- a/src/snek/static/socket.js +++ b/src/snek/static/socket.js @@ -17,6 +17,8 @@ export class Socket extends EventHandler { shouldReconnect = true; + _debug = false; + get isConnected() { return this.ws && this.ws.readyState === WebSocket.OPEN; } @@ -112,7 +114,12 @@ export class Socket extends EventHandler { get(_, prop) { return (...args) => { const functionName = me._camelToSnake(prop); - return me.call(functionName, ...args); + if(me._debug){ + const call = {} + call[functionName] = args + console.debug(call) + } + return me.call(functionName, ...args); }; }, }, diff --git a/src/snek/templates/web.html b/src/snek/templates/web.html index 6a1fe10..03b9444 100644 --- a/src/snek/templates/web.html +++ b/src/snek/templates/web.html @@ -13,7 +13,7 @@ {% endfor %}
-