working notifications and content updates

This commit is contained in:
Andrew Gundersen 2022-03-24 07:50:48 -05:00
commit 35fea9945c
4 changed files with 62 additions and 30 deletions

View file

@ -20,6 +20,8 @@ const Bubble =
});
if (!props.text) props.text = "...";
return { getUrl };
},

View file

@ -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;
export default scroll;
// const isBottom = () => {
// if (el) {
// return el.scrollHeight - el.clientHeight <= el.scrollTop + 1;
// }
// }

View file

@ -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"
/>
</div> `
</div>`
}
export default Messenger;

View file

@ -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);
}