Make snooze page show snooze times etc.

This commit is contained in:
thepaperpilot 2024-05-09 19:21:34 -05:00
parent caecd859a1
commit 3795f35d7d
2 changed files with 23 additions and 5 deletions

View file

@ -20,7 +20,7 @@
<script setup lang="ts">
import { computed, onMounted, ref, toRef } from 'vue';
import { ThreadRef, items, sources } from '../state';
import { ItemThread, MessageEvent, ThreadRef, items, sources } from '../state';
import Modal from './Modal.vue';
import { initFlowbite } from 'flowbite';
@ -107,8 +107,19 @@ function snoozeUntil(date: Date) {
return;
}
const newItems = items.value.slice();
const item = newItems.find(item => item.source === selected.source && item.sourceItem === selected.sourceItem);
let item = newItems.find(item => item.source === selected.source && item.sourceItem === selected.sourceItem);
if (item == null) {
const timeline = sources.value[selected.source].items[selected.sourceItem].threads[selected.thread].timeline;
const lastMessage = timeline.findLast(msg => msg.type === 'message') as MessageEvent | undefined;
const threadUpdated = timeline[timeline.length - 1]?.time ?? 0;
const thread: ItemThread = {
count: 0,
preview: lastMessage?.message ?? "",
updatedAt: threadUpdated,
contact: lastMessage?.contact
};
item = { source: selected.source, sourceItem: selected.sourceItem, updatedAt: threadUpdated, threads: { [selected.thread]: thread } };
items.value.push(item);
return;
}
if (selected.thread === -1) {

View file

@ -25,7 +25,7 @@
<script setup lang="ts">
import { computed } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ItemThread, MessageEvent, sources } from '../../state';
import { ItemThread, MessageEvent, sources, items as stateItems } from '../../state';
import { deArray, setupSelectedThread } from '../../utils';
import Item from '../Item.vue';
import Modal from '../Modal.vue';
@ -45,12 +45,19 @@ const items = computed(() => Object.keys(source.value.items).map(item => {
const sourceItem = parseInt(item);
const sourceThreads = source.value.items[sourceItem].threads;
let updatedAt = 0;
const itemThreads = Object.keys(sourceThreads).reduce((acc, curr) => {
const thread = sourceThreads[parseInt(curr)];
const threadId = parseInt(curr);
const stateItem = stateItems.value.find(item => item.source === sourceId.value && item.sourceItem === sourceItem);
if (stateItem && threadId in stateItem.threads) {
acc[threadId] = stateItem.threads[threadId];
return acc;
}
const thread = sourceThreads[threadId];
const lastMessage = thread.timeline.findLast(msg => msg.type === 'message') as MessageEvent | undefined;
const threadUpdated = thread.timeline[thread.timeline.length - 1]?.time ?? 0;
updatedAt = Math.max(updatedAt, threadUpdated);
acc[parseInt(curr)] = {
acc[threadId] = {
count: 0,
preview: lastMessage?.message ?? "",
updatedAt: threadUpdated,