]> Repos - mime-chat/commitdiff
working notifications and content updates
authorAndrew Gundersen <gundersena@xavier.edu>
Thu, 24 Mar 2022 12:50:48 +0000 (07:50 -0500)
committerAndrew Gundersen <gundersena@xavier.edu>
Thu, 24 Mar 2022 12:50:48 +0000 (07:50 -0500)
src/render/components/bubble.js
src/render/components/control/scroll.js
src/render/components/messenger.js
src/session.js

index feafdc20403ea5ce8bf2877295eba8f06a39c873..a42364c3e90fd5089b2b6076fc0e63fb3eecbfc1 100644 (file)
@@ -20,6 +20,8 @@ const Bubble =
 
         });
 
+        if (!props.text) props.text = "..."; 
+
         return { getUrl };
     },
 
index 4666ea151a9572f9623189b6fcef3c3320caa4ee..3e9a0bf1bb6d88c3b533a2caf6a11510b92b5950 100644 (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;
\ 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
index 8391ac887edb8815f96fcac281ad8101612239bf..572613db563a7f1f41806f0c01b9e8699083c8a8 100644 (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;
index 866debb12f8cf3e379f830e921aa02c35c31fee7..86348123da8580c7b7f785b6ba1454eee4cde811 100644 (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);
         }