message grouping

This commit is contained in:
Andrew Gundersen 2021-03-13 11:59:37 -06:00
commit feccda8ec9
6 changed files with 110 additions and 37 deletions

View file

@ -2,13 +2,13 @@ import { RenderMessage, ClientMessage } from "@/types/message/index";
import { v4 as uuidv4 } from 'uuid';
// Create a RenderMessage object directly from json string.
export function initRenderMessageFromString(message_str: string) {
export function initRenderMessageFromString(messageStr: string) {
// Parse the string.
const m = JSON.parse(message_str);
const m = JSON.parse(messageStr);
// Auto set uid and time.
let currentdate = new Date();
const currentdate = new Date();
const message: RenderMessage = {
content: m.content,
@ -16,7 +16,7 @@ export function initRenderMessageFromString(message_str: string) {
modifier: m.modifier,
time: currentdate.getTime(),
uid: uuidv4(),
isChild: false
isChild: "none"
}
return message
@ -26,7 +26,7 @@ export function initRenderMessageFromString(message_str: string) {
export function initRenderMessage(text: string, audio: string, context: string, modifier: string) {
// Auto set uid and time.
let currentdate = new Date();
const currentdate = new Date();
const message: RenderMessage = {
content: {
@ -37,7 +37,7 @@ export function initRenderMessage(text: string, audio: string, context: string,
modifier: modifier,
time: currentdate.getTime(),
uid: uuidv4(),
isChild: false
isChild: "none"
}
return message

View file

@ -16,14 +16,20 @@ if (messagesString) {
export default function useMessages() {
const addMessage = (m: RenderMessage) => messages.value.set(m.uid, m);
// Add new message and update previous message if nessesary.
const addMessage = (m: RenderMessage) => {
console.log(`Adding message: ${m.content.text}`)
messages.value.set(m.uid, m);
}
const updateMessage = (m: Annotation) => {
// update message if in the map.
if (messages.value.has(m.uid)) {
messages.value.get(m.uid).context = m.context;
messages.value.get(m.uid).content.text = m.text;
}
const updateMessage = (a: Annotation) => {
console.log("Updating message...")
const m = messages.value.get(a.uid)
m.context = a.context
m.text = a.text
return m
}
const saveMessages = () => {