From: Andrew Gundersen Date: Thu, 24 Mar 2022 12:50:48 +0000 (-0500) Subject: working notifications and content updates X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=35fea9945c79895f51c533b0b34a941d4342452a;p=mime-chat working notifications and content updates --- diff --git a/src/render/components/bubble.js b/src/render/components/bubble.js index feafdc2..a42364c 100644 --- a/src/render/components/bubble.js +++ b/src/render/components/bubble.js @@ -20,6 +20,8 @@ const Bubble = }); + if (!props.text) props.text = "..."; + return { getUrl }; }, diff --git a/src/render/components/control/scroll.js b/src/render/components/control/scroll.js index 4666ea1..3e9a0bf 100644 --- a/src/render/components/control/scroll.js +++ b/src/render/components/control/scroll.js @@ -1,24 +1,20 @@ let el; -const initScroll = (elementId) => { - el = document.getElementById(elementId); - el.addEventListener('adjust-scroll', adjustScroll); - window.addEventListener('resize', adjustScroll); -} - -const isBottom = () => { - if (el) { - return el.scrollHeight - el.clientHeight <= el.scrollTop + 1; - } -} - -const adjustScroll = () => { - if (el) { +const scroll = () => { + if (!el) { + el = document.getElementById("messenger"); + window.addEventListener('resize', scroll); + } el.scrollTo({ top: el.scrollHeight - el.clientHeight, behavior: 'smooth' }); - } } -export default initScroll; \ No newline at end of file +export default scroll; + +// const isBottom = () => { +// if (el) { +// return el.scrollHeight - el.clientHeight <= el.scrollTop + 1; +// } +// } \ No newline at end of file diff --git a/src/render/components/messenger.js b/src/render/components/messenger.js index 8391ac8..572613d 100644 --- a/src/render/components/messenger.js +++ b/src/render/components/messenger.js @@ -1,5 +1,5 @@ import onDrop from "./control/drop.js"; -import initScroll from "./control/scroll.js"; +import scroll from "./control/scroll.js"; import WS from "./ws.js"; import Input from "./input.js"; @@ -20,6 +20,8 @@ const Messenger = { const person = Vue.ref(""); const messages = Vue.ref([]); + let current = Vue.ref(); + Vue.onMounted(() => { window.mainApi.on("message", (update) => { @@ -28,6 +30,7 @@ const Messenger = { { person.value = update.person; messages.value = update.messages; + current.value = messages.value.at(-1); } else if (update.name) { @@ -35,21 +38,29 @@ const Messenger = { } else if (update.modifier) { - messages.value.push(update); + messages.value.push(update); + current.value = update; + } + else if (update.category) + { + current.value.content.push(update); + } + else if (update.context) + { + current.value.context = update.context; } else { - messages.at(-1).content.push(update); + current.value.content.at(-1).text = update.text; } + + setTimeout(scroll, 10); }); - initScroll("messenger"); window.mainApi.send("messenger"); }); - const search = (id) => messages.value.find(m => m.id == id); - return { person, messages, onDrop }; }, @@ -69,7 +80,7 @@ const Messenger = { v-bind="message" /> - ` + ` } export default Messenger; diff --git a/src/session.js b/src/session.js index 866debb..8634812 100644 --- a/src/session.js +++ b/src/session.js @@ -6,7 +6,9 @@ const { connectToPlatform, disconnectFromPlatform } = require("./io"); const { initAudio, terminateAudio, playback, streamState } = require("./audio"); const util = require('util'); + let ui; +let current; const messageQueue = []; @@ -28,10 +30,12 @@ function handleMessageQueue() const update = messageQueue.shift(); if (update) - { + { + console.log(update); + if (update.person) { - ui = update; + ui = update; current = update.messages.at(-1); } else if (update.name) { @@ -39,17 +43,36 @@ function handleMessageQueue() } else if (update.modifier) { - ui.messages.push(update); + ui.messages.push(update); current = update; } else if (update.category) { - ui.messages.at(-1).content.push(update) + current.content.push(update); } - else if (update.title) + else if (update.context) { - new Notification(update).show(); return; + current.context = update.context; + } + else if (update.text) + { + current.content.at(-1).text = update.text; + } + else + { + const content = current.content.at(-1); + + new Notification({ + title: current.context, + body: content.text + }).show(); + + if (content.category == "audio") + { + playback(current.id, content.blob); + } + + return; } - else playback(...update); return; ipcEmit("message", update); }