add thread in api and front

This commit is contained in:
grimhilt 2023-04-05 17:28:58 +02:00
parent 51003b494b
commit 97768e3695
8 changed files with 58 additions and 28 deletions

View File

@ -30,24 +30,24 @@ export async function getAccounts() {
export async function getRooms(mailboxId) { export async function getRooms(mailboxId) {
const query = ` const query = `
SELECT SELECT
app_room.room_id AS id, room.room_id AS id,
app_room.room_name AS roomName, room.room_name AS roomName,
address.email AS user, address.email AS user,
app_room.owner_id AS userId, room.owner_id AS userId,
app_room.notSeen, room.notSeen,
app_room.room_type AS roomType, room.room_type AS roomType,
mailbox_message.mailbox_id AS mailboxId mailbox_message.mailbox_id AS mailboxId,
FROM app_room app_thread.parent_id
INNER JOIN message FROM app_room room
INNER JOIN mailbox_message INNER JOIN message ON message.message_id = room.message_id
INNER JOIN address INNER JOIN mailbox_message ON mailbox_message.message_id = message.message_id
INNER JOIN address ON address.address_id = room.owner_id
LEFT JOIN app_thread ON room.room_id = app_thread.room_id
WHERE WHERE
message.message_id = app_room.message_id AND mailbox_message.mailbox_id = ?
mailbox_message.mailbox_id = ? AND ORDER BY room.lastUpdate DESC
mailbox_message.message_id = message.message_id AND `;
address.address_id = app_room.owner_id
ORDER BY app_room.lastUpdate DESC
`;
const values = [mailboxId]; const values = [mailboxId];
return await execQueryAsync(query, values); return await execQueryAsync(query, values);
} }

View File

@ -145,6 +145,8 @@ export default class RegisterMessageInApp {
await this.incrementNotSeen(roomId); await this.incrementNotSeen(roomId);
if (isThread) { if (isThread) {
await getThreadInfoOnId(roomId).then(async (res) => { await getThreadInfoOnId(roomId).then(async (res) => {
let root_id = res[0].root_id;
if (root_id == undefined) root_id = res[0].room_id;
await this.incrementNotSeen(res[0].root_id); await this.incrementNotSeen(res[0].root_id);
}); });
} }

View File

@ -26,7 +26,7 @@ export interface Room {
unseen: number; unseen: number;
messages: Message[]; messages: Message[];
messageLoading: LoadingState; messageLoading: LoadingState;
threads: object[]; threadIds: number[];
} }
export interface Account { export interface Account {

View File

@ -11,7 +11,8 @@ interface RoomFromBack {
mailboxId: number; mailboxId: number;
user: string; user: string;
userId: number; userId: number;
// unseen: number; unseen: number;
parent_id?: number;
// todo thread // todo thread
} }
@ -20,6 +21,8 @@ interface AccountFromBack {
email: string; email: string;
} }
const buffer: RoomFromBack[] = [];
function createRoom(options: RoomFromBack): Room { function createRoom(options: RoomFromBack): Room {
return { return {
id: options.id, id: options.id,
@ -31,7 +34,7 @@ function createRoom(options: RoomFromBack): Room {
unseen: 0, unseen: 0,
messages: [], messages: [],
messageLoading: LoadingState.notLoaded, messageLoading: LoadingState.notLoaded,
threads: [], threadIds: [],
}; };
} }
@ -48,7 +51,7 @@ export interface State {
const store = createStore<State>({ const store = createStore<State>({
state: { state: {
rooms: [createRoom({ id: 12, userId: 1, user: "user", roomName: "room name", mailboxId: 2, roomType: 1 })], rooms: [], //createRoom({ id: 12, userId: 1, user: "user", roomName: "room name", mailboxId: 2, roomType: 1 })
accounts: [{ id: 0, email: "All", fetched: false }], accounts: [{ id: 0, email: "All", fetched: false }],
addresses: [], addresses: [],
activeAccount: 0, activeAccount: 0,
@ -84,8 +87,21 @@ const store = createStore<State>({
addRooms(state, payload) { addRooms(state, payload) {
// todo add if not exist // todo add if not exist
payload.rooms.forEach((room: RoomFromBack) => { payload.rooms.forEach((room: RoomFromBack) => {
if (room.roomType == RoomType.THREAD) {
buffer.push(room);
}
state.rooms.push(createRoom(room)); state.rooms.push(createRoom(room));
}); });
buffer.forEach((thread) => {
const parentRoom = state.rooms.find((room) => room.id == thread.parent_id); // todo debug parent_id to root_id
if (parentRoom) {
parentRoom.threadIds.push(thread.id);
console.log(parentRoom);
} else {
console.log("yep...");
}
});
}, },
addMessages(state, payload) { addMessages(state, payload) {
// todo add if not exist // todo add if not exist
@ -105,7 +121,9 @@ const store = createStore<State>({
getters: { getters: {
rooms: (state) => (): Room[] => { rooms: (state) => (): Room[] => {
if (state.activeAccount === 0) return state.rooms; if (state.activeAccount === 0) return state.rooms;
return state.rooms.filter((room) => room.mailboxId == state.activeAccount); return state.rooms.filter(
(room) => room.mailboxId == state.activeAccount && room.roomType != RoomType.THREAD,
);
}, },
room: room:
(state) => (state) =>

View File

@ -105,6 +105,7 @@ iframe {
overflow-y: auto; overflow-y: auto;
max-height: 300px; max-height: 300px;
width: 100%; width: 100%;
padding: 2px 10px;
max-width: 750px; /* template width being 600px to 640px up to 750px (experiment and test) */ max-width: 750px; /* template width being 600px to 640px up to 750px (experiment and test) */
background-color: rgb(234, 234, 234); background-color: rgb(234, 234, 234);
} }

View File

@ -14,9 +14,10 @@ const props = defineProps({
userId: Number, userId: Number,
notSeen: Number, notSeen: Number,
mailboxId: Number, mailboxId: Number,
threads: [Object], threadIds: [Number],
}, },
}); });
console.log(props.data.threadIds);
const router = useRouter(); const router = useRouter();
</script> </script>
@ -37,7 +38,7 @@ const router = useRouter();
><template v-slot:body>{{ props.data.unseen }}</template> ><template v-slot:body>{{ props.data.unseen }}</template>
</Badge> </Badge>
</div> </div>
<ThreadList :threads="props.data.threads" /> <ThreadList :threadIds="props.data.threadIds" />
</div> </div>
</template> </template>

View File

@ -1,15 +1,23 @@
<script setup> <script setup>
import store from "@/store/store";
import { defineProps } from "vue"; import { defineProps } from "vue";
import { useRouter } from "vue-router";
const props = defineProps({ const props = defineProps({
thread: Object, threadId: Number,
}); });
const room = store.getters.room(props.threadId);
console.log(props.thread); console.log(props.thread);
const router = useRouter();
</script> </script>
<template> <template>
<div class="room"> <div
{{ props.thread.roomName }} @click="router.push(`/${props.threadId}`)"
v-bind:class="store.state.activeRoom == props.data.id ? 'selected' : ''"
class="room"
>
{{ room.roomName }}
</div> </div>
</template> </template>

View File

@ -1,12 +1,12 @@
<script setup> <script setup>
import Thread from "./Thread.vue"; import Thread from "./Thread.vue";
import { defineProps } from "vue"; import { defineProps } from "vue";
const props = defineProps({ threads: [Object] }); const props = defineProps({ threadIds: [Number] });
</script> </script>
<template> <template>
<div> <div>
<Thread v-for="(thread, index) in props.threads" :key="index" :thread="thread" /> <Thread v-for="(threadId, index) in props.threadIds" :key="index" :threadId="threadId" />
</div> </div>
</template> </template>