From 51c4ad8ed7f89f92399537bda0c7d087fc65379a Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Fri, 25 Jun 2021 18:28:29 -0500 Subject: [PATCH 1/6] new message anim --- src/account.ts | 3 +- src/messages.ts | 24 ++ src/render/components/bubble.vue | 395 +++++------------- src/render/components/controllers/helpers.ts | 49 ++- .../controllers/inputItem.control.audio.ts | 2 +- .../controllers/inputItem.control.text.ts | 11 +- src/render/components/message.vue | 142 +++++++ src/render/components/messenger.vue | 11 +- src/render/ipc.ts | 2 +- src/render/shared/messages.ts | 40 +- src/session.ts | 49 +-- src/types.ts | 16 +- 12 files changed, 377 insertions(+), 367 deletions(-) create mode 100644 src/messages.ts create mode 100644 src/render/components/message.vue diff --git a/src/account.ts b/src/account.ts index 581da0e..ac53b23 100644 --- a/src/account.ts +++ b/src/account.ts @@ -4,6 +4,7 @@ import { endSession, launchSession } from "@/session"; import { getToken, setToken, setProfile, getProfile, clearStore } from "./store"; import { parseAuthRes } from "./auth"; import { ipcEmit } from "@/composables/useEmitter"; +import { messages } from "@/messages"; export const accountAuth = async (): Promise => { @@ -89,7 +90,7 @@ export const updateAppState = (): void => { ipcEmit("set-profile", profile); - // ipcEmit('messages') etc + ipcEmit("init-messages", messages) } diff --git a/src/messages.ts b/src/messages.ts new file mode 100644 index 0000000..fdd9d15 --- /dev/null +++ b/src/messages.ts @@ -0,0 +1,24 @@ +import { ipcEmit } from "@/composables/useEmitter"; + +export let messages: Message[] = []; + +export const setMessages = (init: {messages: Message[]}) => { + messages = init.messages; + ipcEmit("init-messages", messages); +} + +export const newMessage = (message: Message) => { + messages.push(message); + ipcEmit("add-message", message); +} + +export const annotateMessage = (annotation: Annotation) => { + for (let i in messages) { + if (messages[i].uid == annotation.uid) { + messages[i].context = annotation.context; + ipcEmit("update-message", annotation) + break; + } + } +} + diff --git a/src/render/components/bubble.vue b/src/render/components/bubble.vue index 982cef3..a3ca4f7 100644 --- a/src/render/components/bubble.vue +++ b/src/render/components/bubble.vue @@ -1,19 +1,6 @@ @@ -24,27 +11,16 @@ export default defineComponent({ name: "Bubble", - props: ["text", "context", "type", "position"], + props: ["modifier", "content", "child"], - setup() { - - const seen = ref(false); - /* initialize seen state */ - if (document.visibilityState === "visible") { - seen.value = true; - } else seen.value = false; + setup(props) { onMounted(() => { - if(seen.value) - document.addEventListener("visibilitychange", () => { - seen.value = true - }); - }); return { - seen + }; } @@ -55,277 +31,92 @@ - - +} + +.ai-bubble { + background-color: #FFFFFF; +} + +.client-bubble { + color: white; + background-color: #58C4FD; +} + +.ai-first-child { + border-bottom-left-radius: 9px; +} + +.ai-middle-child { + border-top-left-radius: 9px; + border-bottom-left-radius: 9px; +} + +.ai-last-child { + border-top-left-radius: 9px; +} + +.client-first-child { + border-bottom-right-radius: 9px; +} + +.client-middle-child { + border-top-right-radius: 9px; + border-bottom-right-radius: 9px; +} + +.client-last-child { + border-top-right-radius: 9px; +} + +.ai-none-child, .client-none-child { + border-top-right-radius: 9px; +} + + +// .notify { +// position: absolute; +// width: 12px; +// height: 12px; +// border-radius: 50%; +// background-color: #58D9FF; +// top: -5px; +// left: -5px; +// border: 2px solid #EBEBEB; +// transform: scale(0); + +// animation-name: notify-anim; +// animation-duration: 5s; +// } + +// @keyframes notify-anim { +// 0%, 90% { +// transform: scale(1); +// } +// 100% { +// transform: scale(0); +// } +// } + + \ No newline at end of file diff --git a/src/render/components/controllers/helpers.ts b/src/render/components/controllers/helpers.ts index 23976a8..f20a11a 100644 --- a/src/render/components/controllers/helpers.ts +++ b/src/render/components/controllers/helpers.ts @@ -1,4 +1,4 @@ -import { ref } from "vue"; +import { ref, Ref } from "vue"; import anime from "animejs"; import { v4 as uuidv4 } from 'uuid'; @@ -86,17 +86,40 @@ export function animateAudioInput () { } +// animate a message annotation. +//! probably could be improved. +export function annotateAnim (uid: string, val: string, contextRef: Ref) { -export function newMessage ({ - text=false, - audio=false, - context=false, - uid=uuidv4() -}) { - return { - text: text, - audio: audio, - context: context, - uid: uid - }; + anime({ + targets: `#${uid} span`, + opacity: [1, 0], + duration: 500, + easing: 'easeOutExpo' + }) + + .finished.then(() => { + contextRef.value = val; + }) + + .then(() => { + anime({ + targets: `#${uid} span`, + opacity: [0, 1], + duration: 500, + easing: 'easeOutExpo' + }) + }) } + +// Given index and length of content, return message child status. +export function calcChild (index: number, len: number) { + if (len === 1) { + return "none"; + } else if (index === 0) { + return "first-child"; + } else if (index === len - 1) { + return "last-child"; + } else { + return "middle-child"; + } +} \ No newline at end of file diff --git a/src/render/components/controllers/inputItem.control.audio.ts b/src/render/components/controllers/inputItem.control.audio.ts index facf30c..9852e53 100644 --- a/src/render/components/controllers/inputItem.control.audio.ts +++ b/src/render/components/controllers/inputItem.control.audio.ts @@ -1,6 +1,6 @@ import { onMounted, onUnmounted, ref, Ref } from "vue"; import { postMessage } from "@/render/ipc"; -import { newMessage, animateAudioInput } from "./helpers"; +import { animateAudioInput } from "./helpers"; import { invokeReturnAudio, postAudioChunk } from "@/render/ipc"; export default function useAudioInputController (typing: Ref) { diff --git a/src/render/components/controllers/inputItem.control.text.ts b/src/render/components/controllers/inputItem.control.text.ts index 941ae89..51edfe0 100644 --- a/src/render/components/controllers/inputItem.control.text.ts +++ b/src/render/components/controllers/inputItem.control.text.ts @@ -1,6 +1,6 @@ import { Ref, ref, watch, onMounted, onUnmounted } from "vue"; import { postMessage } from "@/render/ipc"; -import { newMessage, animateTextInput } from "./helpers"; +import { animateTextInput } from "./helpers"; export default function useTextInputController(elementX: Ref) { @@ -36,11 +36,12 @@ export default function useTextInputController(elementX: Ref) { if (textInput) { // Send it to the backend for processing. - const message = newMessage({ - text: false - }); + const message: Raw = { + text: textInput.value, + audio: false + }; - // postMessage(message); + postMessage(message); clearInput() } diff --git a/src/render/components/message.vue b/src/render/components/message.vue new file mode 100644 index 0000000..d27df6e --- /dev/null +++ b/src/render/components/message.vue @@ -0,0 +1,142 @@ + + + + + + + diff --git a/src/render/components/messenger.vue b/src/render/components/messenger.vue index 8a7f6ad..619eeff 100644 --- a/src/render/components/messenger.vue +++ b/src/render/components/messenger.vue @@ -7,11 +7,12 @@
-
@@ -22,7 +23,7 @@ import { defineComponent, onMounted, onUnmounted } from "vue"; import InputItem from "@/render/components/inputItem.vue"; import Settings from "@/render/components/settings.vue"; -import Bubble from "@/render/components/bubble.vue"; +import Message from "@/render/components/message.vue"; import { profile } from "@/render/shared/profile"; import { messages } from "@/render/shared/messages"; @@ -33,7 +34,7 @@ export default defineComponent({ components: { InputItem, Settings, - Bubble + Message }, setup() { diff --git a/src/render/ipc.ts b/src/render/ipc.ts index 6601dde..cb14778 100644 --- a/src/render/ipc.ts +++ b/src/render/ipc.ts @@ -41,7 +41,7 @@ export const invokeReturnAudio = async (): Promise => ( * */ -export const postMessage = (payload: Message): void => ( +export const postMessage = (payload: Raw): void => ( post('post-session-send', payload) ); diff --git a/src/render/shared/messages.ts b/src/render/shared/messages.ts index f731584..cd8fa26 100644 --- a/src/render/shared/messages.ts +++ b/src/render/shared/messages.ts @@ -5,26 +5,54 @@ import useScroll from "@/render/composables/useScroll"; export const messages: Ref> = ref([]); export const setMessages: IpcListenerCallback> = (payload) => { - messages.value = payload as Array; + // messages.value = payload as Array; } export const addMessage: IpcListenerCallback = (payload) => { messages.value.push(payload as Message); } -export const updateMessage: IpcListenerCallback = (payload) => { - const message = payload as Message; +export const updateMessage: IpcListenerCallback = (payload) => { + const annotation = payload as Annotation; let targetMessage = messages.value.filter((m: Message) => { - return m.uid = message.uid; + return m.uid === annotation.uid; })[0]; if (targetMessage) { - targetMessage = message; + targetMessage.content = annotation.content; + targetMessage.context = annotation.context; } - } +messages.value = [ +{ + content: ["Welcome Andrew"], + context: "Crimata", + modifier: "ai", + uid: "b5dd3d1b-cef0-4057-aa0f-c72e5c4cd67d" +}, +{ + content: ["show contacts"], + context: "show contacts", + modifier: "client", + uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" +}] + +setTimeout(() => { + + console.log("updating message"); + + updateMessage({ + content: ["show contacts", "msg"], + context: "show contacts", + uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" + }); + + + +}, 2000); + export default { messages, setMessages, diff --git a/src/session.ts b/src/session.ts index 01a105c..df0c122 100644 --- a/src/session.ts +++ b/src/session.ts @@ -3,60 +3,53 @@ // import useAudio from "@/audio"; -import { ipcEmit } from "@/composables/useEmitter"; +import { setMessages, newMessage, annotateMessage } from "./messages"; import useWebsockets from "./composables/useWebsockets"; import {config} from "@/config"; -/* data structure of messages that's tied to the UI */ -const uiState: any | null = null; - /* start and stop audio functionality */ // const { initAudio, closeAudio } = useAudio(); -const isInitMessage = (message: any): boolean => { - return true; +const isInitMessage = (object: any): object is Message[] => { + return 'messages' in object; +}; + +const isNewMessage = (object: any): object is Message => { + return 'content' in object; +}; + +const isAnnotation = (object: any): object is Annotation => { + return 'messages' in object; }; const deauthenticate = (): void => { console.log('deauthenticating') }; -const isAddMessage = (message: any): boolean => { - return true; -}; - /** * Controls for interfacing with the platform. * Takes an onMessage callback which we define below. */ - const onMessageCallback = (payload: string) => { - const message = JSON.parse(payload); + const message = JSON.parse(payload); - /* if the platform fails to authenticate, we must back down */ if (message === "CLOSE_AUTH_FAIL") { deauthenticate(); - return; } - ipcEmit("add-message", message) - return + else if (isInitMessage(message)) { + setMessages(message); + } - /* on init, platform sends state, used to init canvas */ - // if (isInitMessage(message)) { - // ipcEmit("init-messages", message) - // } + else if (isNewMessage(message)) { + newMessage(message); + } - - // else if (isAddMessage(message)) { - // ipcEmit("add-messages", message) - // } - - // else { - // ipcEmit("update-messages", message) - // } + else if (isAnnotation(message)) { + annotateMessage(message); + } } diff --git a/src/types.ts b/src/types.ts index 2139a86..7b6d964 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,14 +1,20 @@ interface Message { - text: boolean | string; + modifier: string; + content: string[]; context: boolean | string; - audio: boolean | string; - type: 1 | 2 | 3; uid: string; } -interface ViewMessage extends Message { - child: string; +interface Annotation { + content: string[]; + context: string; + uid: string; +} + +interface Raw { + text: string | boolean; + audio: string | boolean; } interface WindowState { From cb40a811faa1390e7ef64ea7e0c3b548434af086 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Sun, 27 Jun 2021 09:30:31 -0500 Subject: [PATCH 2/6] message anim --- src/render/components/bubble.vue | 4 ++-- src/render/shared/messages.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/render/components/bubble.vue b/src/render/components/bubble.vue index a3ca4f7..7084a75 100644 --- a/src/render/components/bubble.vue +++ b/src/render/components/bubble.vue @@ -41,8 +41,8 @@ margin-left: 15px; margin-right: 15px; margin-bottom: 4px; - animation-name: bubble-init-anim; - animation-duration: 0.5s; + // animation-name: bubble-init-anim; + // animation-duration: 0.5s; } @keyframes bubble-init-anim { diff --git a/src/render/shared/messages.ts b/src/render/shared/messages.ts index cd8fa26..8d87534 100644 --- a/src/render/shared/messages.ts +++ b/src/render/shared/messages.ts @@ -39,19 +39,19 @@ messages.value = [ uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" }] -setTimeout(() => { +// setTimeout(() => { - console.log("updating message"); +// console.log("updating message"); - updateMessage({ - content: ["show contacts", "msg"], - context: "show contacts", - uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" - }); +// updateMessage({ +// content: ["show contacts", "msg"], +// context: "show contacts", +// uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" +// }); -}, 2000); +// }, 2000); export default { messages, From af421e6bfb9cbfdfdf586c5e3c3b0708435447f3 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Mon, 28 Jun 2021 11:32:45 -0500 Subject: [PATCH 3/6] more updates --- src/messages.ts | 20 ++++++- .../controllers/messenger.control.ts | 38 ------------- src/render/composables/useIpcRend.ts | 2 +- src/render/listeners.ts | 1 - src/render/shared/messages.ts | 55 +++++++++++-------- src/session.ts | 2 +- src/types.ts | 9 ++- 7 files changed, 60 insertions(+), 67 deletions(-) delete mode 100644 src/render/components/controllers/messenger.control.ts diff --git a/src/messages.ts b/src/messages.ts index fdd9d15..fa2ab22 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -3,21 +3,37 @@ import { ipcEmit } from "@/composables/useEmitter"; export let messages: Message[] = []; export const setMessages = (init: {messages: Message[]}) => { + console.log("setMessages", init); messages = init.messages; ipcEmit("init-messages", messages); } export const newMessage = (message: Message) => { + console.log("newMessage", message); messages.push(message); ipcEmit("add-message", message); } export const annotateMessage = (annotation: Annotation) => { + console.log("annotateMessage", annotation); + for (let i in messages) { + if (messages[i].uid == annotation.uid) { - messages[i].context = annotation.context; - ipcEmit("update-message", annotation) + + if (annotation.data.hasOwnProperty("content")) { + const data = annotation.data as ContentData; + messages[i].content = data.content; + } + + if (annotation.data.hasOwnProperty("context")) { + const data = annotation.data as ContextData; + messages[i].context = data.context; + } + + ipcEmit("update-message", annotation); break; + } } } diff --git a/src/render/components/controllers/messenger.control.ts b/src/render/components/controllers/messenger.control.ts deleted file mode 100644 index b9c3a96..0000000 --- a/src/render/components/controllers/messenger.control.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ref } from 'vue'; -import useScroll from "@/render/composables/useScroll"; - -const messagesRef = ref(); - -/* seed the canvas with messages */ -const seedCanvas = (messages: Message[]) => { - messagesRef.value = messages; -} - -const addMessage = (message: Message) => { - messagesRef.value.push(message); -} - -const updateMessage = (message: Message) => { - - let target_message = messagesRef.value.filter((m: Message) => { - return m.uid = message.uid; - })[0]; - - if (target_message) { - target_message = message; - } - -} - -export default function useMessages() { - - const { updateScrollRef, adjustScroll } = useScroll("messenger"); - - return { - messagesRef, - seedCanvas, - addMessage, - updateMessage - }; - -} diff --git a/src/render/composables/useIpcRend.ts b/src/render/composables/useIpcRend.ts index bbfb4e1..477289f 100644 --- a/src/render/composables/useIpcRend.ts +++ b/src/render/composables/useIpcRend.ts @@ -25,7 +25,7 @@ export class IpcRendererListener implements IIpcListener } private _onPost = (_e: IpcRendererEvent, payload: InputParam): void => { - console.log(`[IPC] Post: ${this.channel}`); + console.log(`[IPC] Post: ${this.channel}`, payload); this._listenerCallback(payload); } diff --git a/src/render/listeners.ts b/src/render/listeners.ts index 0a05208..62f7cb7 100644 --- a/src/render/listeners.ts +++ b/src/render/listeners.ts @@ -38,4 +38,3 @@ export const connectionStatusListener = new IpcRendererListener({ channel: UPDATE_MESSAGE_CHANNEL, listenerCallback: setConnectionStatus }); - diff --git a/src/render/shared/messages.ts b/src/render/shared/messages.ts index 8d87534..79b8fe7 100644 --- a/src/render/shared/messages.ts +++ b/src/render/shared/messages.ts @@ -5,39 +5,55 @@ import useScroll from "@/render/composables/useScroll"; export const messages: Ref> = ref([]); export const setMessages: IpcListenerCallback> = (payload) => { - // messages.value = payload as Array; + console.log("setMessages", payload); + messages.value = payload as Array; } export const addMessage: IpcListenerCallback = (payload) => { + console.log("addMessage", payload); messages.value.push(payload as Message); } export const updateMessage: IpcListenerCallback = (payload) => { + console.log("updateMessage", payload); const annotation = payload as Annotation; + /* find the target message */ let targetMessage = messages.value.filter((m: Message) => { return m.uid === annotation.uid; })[0]; if (targetMessage) { - targetMessage.content = annotation.content; - targetMessage.context = annotation.context; + + /* update the content (add a new bubble) */ + if (annotation.data.hasOwnProperty("content")) { + const data = annotation.data as ContentData; + targetMessage.content = data.content; + } + + /* and/or update the context */ + if (annotation.data.hasOwnProperty("context")) { + const data = annotation.data as ContextData; + targetMessage.context = data.context; + } + } + } -messages.value = [ -{ - content: ["Welcome Andrew"], - context: "Crimata", - modifier: "ai", - uid: "b5dd3d1b-cef0-4057-aa0f-c72e5c4cd67d" -}, -{ - content: ["show contacts"], - context: "show contacts", - modifier: "client", - uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" -}] +// messages.value = [ +// { +// content: ["Welcome Andrew"], +// context: "Crimata", +// modifier: "ai", +// uid: "b5dd3d1b-cef0-4057-aa0f-c72e5c4cd67d" +// }, +// { +// content: ["show contacts"], +// context: "false", +// modifier: "client", +// uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" +// }] // setTimeout(() => { @@ -52,10 +68,3 @@ messages.value = [ // }, 2000); - -export default { - messages, - setMessages, - addMessage, - updateMessage -}; diff --git a/src/session.ts b/src/session.ts index df0c122..c1aec40 100644 --- a/src/session.ts +++ b/src/session.ts @@ -19,7 +19,7 @@ const isNewMessage = (object: any): object is Message => { }; const isAnnotation = (object: any): object is Annotation => { - return 'messages' in object; + return 'uid' in object; }; const deauthenticate = (): void => { diff --git a/src/types.ts b/src/types.ts index 7b6d964..a0cbb70 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,9 +6,16 @@ interface Message { uid: string; } -interface Annotation { +interface ContentData { content: string[]; +} + +interface ContextData { context: string; +} + +interface Annotation { + data: ContentData | ContextData; uid: string; } From a791f973dcc3ff4c511412c82b460919019be289 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Tue, 29 Jun 2021 11:30:35 -0500 Subject: [PATCH 4/6] working protocols --- src/account.ts | 12 +---- src/ipc/listeners.ts | 2 +- src/main.ts | 4 +- src/messages.ts | 83 +++++++++++++++++++++++------------ src/render/listeners.ts | 8 +++- src/render/shared/messages.ts | 53 ++++++++++------------ src/session.ts | 51 ++++++++++----------- src/types.ts | 16 +++---- 8 files changed, 117 insertions(+), 112 deletions(-) diff --git a/src/account.ts b/src/account.ts index ac53b23..965502c 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,10 +1,9 @@ import { postAuth, postLogin, postLogout } from "@/api/account"; import { endSession, launchSession } from "@/session"; -import { getToken, setToken, setProfile, getProfile, clearStore } from "./store"; +import { getToken, setToken, setProfile, clearStore } from "./store"; import { parseAuthRes } from "./auth"; import { ipcEmit } from "@/composables/useEmitter"; -import { messages } from "@/messages"; export const accountAuth = async (): Promise => { @@ -84,13 +83,4 @@ export const accountLogout = async (): Promise => { } -export const updateAppState = (): void => { - - const profile = getProfile(); - - ipcEmit("set-profile", profile); - - ipcEmit("init-messages", messages) - -} diff --git a/src/ipc/listeners.ts b/src/ipc/listeners.ts index cb17f65..17af103 100644 --- a/src/ipc/listeners.ts +++ b/src/ipc/listeners.ts @@ -2,7 +2,7 @@ import { IpcListener } from "@/composables/useIpcMain" import { sendMessage } from '@/session'; import { collect } from "@/audio"; -import { updateAppState } from "@/account"; +import { updateAppState } from "@/session"; import { onNavBar } from "@/window"; const CLIENT_MESSAGE_CHANNEL = "post-session-send" diff --git a/src/main.ts b/src/main.ts index a360835..6df9f6c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,8 +10,8 @@ */ import initIpcMain from "@/ipc/index"; -import { accountAuth, updateAppState } from "./account"; -import { launchSession } from "./session"; +import { accountAuth } from "./account"; +import { launchSession, updateAppState } from "./session"; import createWindow from "./window"; let authState: AuthState | null; diff --git a/src/messages.ts b/src/messages.ts index fa2ab22..9a72b38 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -1,40 +1,67 @@ import { ipcEmit } from "@/composables/useEmitter"; -export let messages: Message[] = []; +export default class Messages { -export const setMessages = (init: {messages: Message[]}) => { - console.log("setMessages", init); - messages = init.messages; - ipcEmit("init-messages", messages); -} + messages: Message[]; -export const newMessage = (message: Message) => { - console.log("newMessage", message); - messages.push(message); - ipcEmit("add-message", message); -} + constructor(messages: Message[]) { + console.log(messages); + this.messages = messages; + this.emit(); + } -export const annotateMessage = (annotation: Annotation) => { - console.log("annotateMessage", annotation); + emit() { + ipcEmit("init-messages", this.messages); + } - for (let i in messages) { + update(update: Update) { - if (messages[i].uid == annotation.uid) { + if (update.name === "add") { + this.messages.push(update.data as Message); + ipcEmit("add-message", update.data); + } + + else if (update.name === "annotate") { + this._annotate(update.data as Annotation); + ipcEmit("update-message", update.data); + } + + else { + this._delete(update.data as string); + ipcEmit("delete-message", update.data); + } + + } + + _annotate(annotation: Annotation) { + + for (let i in this.messages) { + + if (this.messages[i].uid == annotation.uid) { + + if (annotation.name == "content") { + this.messages[i].content = annotation.data as string[]; + } + + if (annotation.name == "context") { + this.messages[i].context = annotation.data as string; + } + + ipcEmit("update-message", annotation); - if (annotation.data.hasOwnProperty("content")) { - const data = annotation.data as ContentData; - messages[i].content = data.content; } - if (annotation.data.hasOwnProperty("context")) { - const data = annotation.data as ContextData; - messages[i].context = data.context; - } - - ipcEmit("update-message", annotation); - break; - } - } -} + } + + _delete(uid: string) { + for (var i = 0; i < this.messages.length; i++) { + if (this.messages[i].uid === uid) { + this.messages.splice(i, 1); + break; + } + } + } + +} \ No newline at end of file diff --git a/src/render/listeners.ts b/src/render/listeners.ts index 90b3cc4..e6ada7f 100644 --- a/src/render/listeners.ts +++ b/src/render/listeners.ts @@ -4,7 +4,7 @@ import { IpcRendererListener } from "./composables/useIpcRend" * Shared state imports * */ import { setProfile } from "./shared/profile"; -import { setMessages, addMessage, updateMessage } from "./shared/messages"; +import { setMessages, addMessage, updateMessage, deleteMessage } from "./shared/messages"; import { setConnectionStatus } from "./shared/connectionStatus"; const SET_PROFILE_CHANNEL = "set-profile"; @@ -12,6 +12,7 @@ const SET_PROFILE_CHANNEL = "set-profile"; const INIT_MESSAGES_CHANNEL = "init-messages"; const ADD_MESSAGE_CHANNEL = "add-message"; const UPDATE_MESSAGE_CHANNEL = "update-message"; +const DELETE_MESSAGE_CHANNEL = "delete-message"; const CONNECTION_STATUS_CHANNEL = "set-connection-status"; export const setProfileListener = new IpcRendererListener({ @@ -35,6 +36,11 @@ export const updateMessagesListener = new IpcRendererListener({ listenerCallback: updateMessage }); +export const deleteMessagesListener = new IpcRendererListener({ + channel: DELETE_MESSAGE_CHANNEL, + listenerCallback: deleteMessage +}); + export const connectionStatusListener = new IpcRendererListener({ channel: CONNECTION_STATUS_CHANNEL, listenerCallback: setConnectionStatus diff --git a/src/render/shared/messages.ts b/src/render/shared/messages.ts index 79b8fe7..b24dca3 100644 --- a/src/render/shared/messages.ts +++ b/src/render/shared/messages.ts @@ -5,55 +5,46 @@ import useScroll from "@/render/composables/useScroll"; export const messages: Ref> = ref([]); export const setMessages: IpcListenerCallback> = (payload) => { - console.log("setMessages", payload); messages.value = payload as Array; } export const addMessage: IpcListenerCallback = (payload) => { - console.log("addMessage", payload); messages.value.push(payload as Message); } export const updateMessage: IpcListenerCallback = (payload) => { - console.log("updateMessage", payload); const annotation = payload as Annotation; - /* find the target message */ - let targetMessage = messages.value.filter((m: Message) => { - return m.uid === annotation.uid; - })[0]; + for (let i in messages.value) { - if (targetMessage) { + if (messages.value[i].uid == annotation.uid) { + + if (annotation.name == "content") { + messages.value[i].content = annotation.data as string[]; + } + + if (annotation.name == "context") { + messages.value[i].context = annotation.data as string; + } - /* update the content (add a new bubble) */ - if (annotation.data.hasOwnProperty("content")) { - const data = annotation.data as ContentData; - targetMessage.content = data.content; } - /* and/or update the context */ - if (annotation.data.hasOwnProperty("context")) { - const data = annotation.data as ContextData; - targetMessage.context = data.context; - } - } } -// messages.value = [ -// { -// content: ["Welcome Andrew"], -// context: "Crimata", -// modifier: "ai", -// uid: "b5dd3d1b-cef0-4057-aa0f-c72e5c4cd67d" -// }, -// { -// content: ["show contacts"], -// context: "false", -// modifier: "client", -// uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" -// }] +export const deleteMessage: IpcListenerCallback = (payload) => { + const uid = payload as string; + + for (var i = 0; i < messages.value.length; i++) { + if (messages.value[i].uid === uid) { + messages.value.splice(i, 1); + break; + } + } + +} + // setTimeout(() => { diff --git a/src/session.ts b/src/session.ts index 885d940..6b40e43 100644 --- a/src/session.ts +++ b/src/session.ts @@ -3,52 +3,34 @@ // import useAudio from "@/audio"; -import { setMessages, newMessage, annotateMessage } from "./messages"; +import Messages from "./messages"; +import { getProfile } from "./store"; import useWebsockets from "./composables/useWebsockets"; import {config} from "@/config"; +import { ipcEmit } from "@/composables/useEmitter"; /* start and stop audio functionality */ // const { initAudio, closeAudio } = useAudio(); -const isInitMessage = (object: any): object is Message[] => { - return 'messages' in object; -}; +let messages: Messages; -const isNewMessage = (object: any): object is Message => { - return 'content' in object; -}; - -const isAnnotation = (object: any): object is Annotation => { - return 'uid' in object; -}; - -const deauthenticate = (): void => { - console.log('deauthenticating') -}; - -/** - * Controls for interfacing with the platform. - * Takes an onMessage callback which we define below. - */ const onMessageCallback = (payload: string) => { const message = JSON.parse(payload); if (message === "CLOSE_AUTH_FAIL") { - deauthenticate(); + console.log("deauthenticating"); } - else if (isInitMessage(message)) { - setMessages(message); + else if (message.header === "init") { + messages = new Messages(message.body); } - else if (isNewMessage(message)) { - newMessage(message); - } - - else if (isAnnotation(message)) { - annotateMessage(message); + else { + if (messages) { + messages.update(message.body); + } } } @@ -57,6 +39,17 @@ const connectionStatusCallback = (status: string) => { ipcEmit('set-connection-status', status); } + +export const updateAppState = (): void => { + const profile = getProfile(); + + ipcEmit("set-profile", profile); + + if (messages) + messages.emit(); + +} + const statusOptions = { openMessage: "Connected", pongMessage: "Nominal", diff --git a/src/types.ts b/src/types.ts index a0cbb70..bcadf73 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,9 @@ +interface Update { + name: string; + data: Message[] | Message | Annotation | string; +} + interface Message { modifier: string; content: string[]; @@ -6,16 +11,9 @@ interface Message { uid: string; } -interface ContentData { - content: string[]; -} - -interface ContextData { - context: string; -} - interface Annotation { - data: ContentData | ContextData; + name: string; + data: string | string[]; uid: string; } From b6b1f3e8948eb6a17160a0670fd5287a2db97ea0 Mon Sep 17 00:00:00 2001 From: Andrew Gundersen Date: Tue, 29 Jun 2021 16:21:18 -0500 Subject: [PATCH 5/6] working new protocols --- src/render/components/bubble.vue | 29 +--- src/render/components/context.vue | 88 ++++++++++++ src/render/components/controllers/helpers.ts | 5 +- src/render/components/inputItem.vue | 5 +- src/render/components/message.vue | 135 ++++++------------- src/render/components/messenger.vue | 2 +- src/render/composables/useScroll.ts | 26 ++-- src/render/shared/messages.ts | 15 ++- 8 files changed, 167 insertions(+), 138 deletions(-) create mode 100644 src/render/components/context.vue diff --git a/src/render/components/bubble.vue b/src/render/components/bubble.vue index 7084a75..fe71f94 100644 --- a/src/render/components/bubble.vue +++ b/src/render/components/bubble.vue @@ -6,22 +6,14 @@ + + \ No newline at end of file diff --git a/src/render/components/controllers/helpers.ts b/src/render/components/controllers/helpers.ts index f20a11a..017cfb3 100644 --- a/src/render/components/controllers/helpers.ts +++ b/src/render/components/controllers/helpers.ts @@ -1,6 +1,5 @@ import { ref, Ref } from "vue"; import anime from "animejs"; -import { v4 as uuidv4 } from 'uuid'; export function animateTextInput () { @@ -93,7 +92,7 @@ export function annotateAnim (uid: string, val: string, contextRef: Ref) { anime({ targets: `#${uid} span`, opacity: [1, 0], - duration: 500, + duration: 250, easing: 'easeOutExpo' }) @@ -105,7 +104,7 @@ export function annotateAnim (uid: string, val: string, contextRef: Ref) { anime({ targets: `#${uid} span`, opacity: [0, 1], - duration: 500, + duration: 250, easing: 'easeOutExpo' }) }) diff --git a/src/render/components/inputItem.vue b/src/render/components/inputItem.vue index edd844f..5deb739 100644 --- a/src/render/components/inputItem.vue +++ b/src/render/components/inputItem.vue @@ -32,7 +32,7 @@ import draggify from "@/render/composables/useDraggify"; import useTextInputController from "@/render/components/controllers/inputItem.control.text"; -import useAudioInputController from +// import useAudioInputController from "@/render/components/controllers/inputItem.control.audio"; export default defineComponent({ @@ -51,7 +51,8 @@ export default defineComponent({ // Controllers for text and audio. const { typing } = useTextInputController(elementX) - const { recording } = useAudioInputController(typing) + // const { recording } = useAudioInputController(typing) + const recording = false; return { elementX, diff --git a/src/render/components/message.vue b/src/render/components/message.vue index d27df6e..f7876f7 100644 --- a/src/render/components/message.vue +++ b/src/render/components/message.vue @@ -8,19 +8,21 @@ :child="calcChild(index, content.length)" /> - -
- {{ contextRef }} -
+ @@ -74,28 +70,4 @@ border-top-right-radius: 9px; } -// .notify { -// position: absolute; -// width: 12px; -// height: 12px; -// border-radius: 50%; -// background-color: #58D9FF; -// top: -5px; -// left: -5px; -// border: 2px solid #EBEBEB; -// transform: scale(0); - -// animation-name: notify-anim; -// animation-duration: 5s; -// } - -// @keyframes notify-anim { -// 0%, 90% { -// transform: scale(1); -// } -// 100% { -// transform: scale(0); -// } -// } - \ No newline at end of file diff --git a/src/render/shared/messages.ts b/src/render/shared/messages.ts index 71871a3..acf24e4 100644 --- a/src/render/shared/messages.ts +++ b/src/render/shared/messages.ts @@ -56,17 +56,9 @@ export const deleteMessage: IpcListenerCallback = (payload) => { } - -// setTimeout(() => { - -// console.log("updating message"); - -// updateMessage({ -// content: ["show contacts", "msg"], -// context: "show contacts", -// uid: "ee2819a3-1125-4881-9942-ca5b3d0ad502" -// }); - - - -// }, 2000); +export default { + messages, + setMessages, + addMessage, + updateMessage +};