From d39f752e2ef87b30c3867e26b8fca93bf00da54e Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 19 May 2024 02:25:11 -0500 Subject: [PATCH] Implement creating threads from messages --- src/components/Thread.vue | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/components/Thread.vue b/src/components/Thread.vue index b659d23..5736f1a 100644 --- a/src/components/Thread.vue +++ b/src/components/Thread.vue @@ -17,14 +17,14 @@
- {{ sourceObj.contacts[event.contact].name }} created a new thread called "{{ item.threads[event.thread].title }}" + {{ sourceObj.contacts[event.contact].name }} created a new thread called "{{ item.threads[event.thread].title }}"
-
+
- - - + + +
@@ -37,7 +37,9 @@ import { computed, onUnmounted, ref, watch } from 'vue'; import { items, sources } from '../state'; import Avatar from './Avatar.vue'; -import { RouterLink } from 'vue-router'; +import { RouterLink, useRouter } from 'vue-router'; + +const router = useRouter(); const props = defineProps<{ source: number; @@ -160,6 +162,27 @@ function deleteMessage(event: number) { threadItem.value.timeline.splice(event, 1); selectedMessageIndex.value = undefined; } + +function createThread(event: number) { + const messageEvent = threadItem.value.timeline[event]; + if (messageEvent.type !== "message") { + return; + } + + const threadId = Object.keys(item.value.threads).reduce((acc, curr) => Math.max(acc, parseInt(curr)), 0) + 1; + item.value.threads[threadId] = { + id: threadId, + timeline: [messageEvent], + title: messageEvent.message + }; + threadItem.value.timeline.push({ + contact: sourceObj.value.selfContact, + type: "create-thread", + time: Date.now(), + thread: threadId + }); + router.push(`/source/${props.source}/${props.sourceItem}/${threadId}`); +}