From 97768e369580aee915700bcfbd5766d5523ece93 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Wed, 5 Apr 2023 17:28:58 +0200 Subject: [PATCH] add thread in api and front --- back/db/api.ts | 32 +++++++++---------- back/mails/saveMessage.ts | 2 ++ front/src/store/models/model.ts | 2 +- front/src/store/store.ts | 26 ++++++++++++--- front/src/views/room/Message.vue | 1 + front/src/views/sidebar/rooms/Room.vue | 5 +-- .../views/sidebar/rooms/threads/Thread.vue | 14 ++++++-- .../sidebar/rooms/threads/ThreadList.vue | 4 +-- 8 files changed, 58 insertions(+), 28 deletions(-) diff --git a/back/db/api.ts b/back/db/api.ts index b6a3812..31ea219 100644 --- a/back/db/api.ts +++ b/back/db/api.ts @@ -30,24 +30,24 @@ export async function getAccounts() { export async function getRooms(mailboxId) { const query = ` SELECT - app_room.room_id AS id, - app_room.room_name AS roomName, + room.room_id AS id, + room.room_name AS roomName, address.email AS user, - app_room.owner_id AS userId, - app_room.notSeen, - app_room.room_type AS roomType, - mailbox_message.mailbox_id AS mailboxId - FROM app_room - INNER JOIN message - INNER JOIN mailbox_message - INNER JOIN address + room.owner_id AS userId, + room.notSeen, + room.room_type AS roomType, + mailbox_message.mailbox_id AS mailboxId, + app_thread.parent_id + FROM app_room room + INNER JOIN message ON message.message_id = room.message_id + 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 - message.message_id = app_room.message_id AND - mailbox_message.mailbox_id = ? AND - mailbox_message.message_id = message.message_id AND - address.address_id = app_room.owner_id - ORDER BY app_room.lastUpdate DESC - `; + mailbox_message.mailbox_id = ? + ORDER BY room.lastUpdate DESC + `; const values = [mailboxId]; return await execQueryAsync(query, values); } diff --git a/back/mails/saveMessage.ts b/back/mails/saveMessage.ts index 6ed78ae..d309f0e 100644 --- a/back/mails/saveMessage.ts +++ b/back/mails/saveMessage.ts @@ -145,6 +145,8 @@ export default class RegisterMessageInApp { await this.incrementNotSeen(roomId); if (isThread) { 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); }); } diff --git a/front/src/store/models/model.ts b/front/src/store/models/model.ts index 9632f63..7bf2716 100644 --- a/front/src/store/models/model.ts +++ b/front/src/store/models/model.ts @@ -26,7 +26,7 @@ export interface Room { unseen: number; messages: Message[]; messageLoading: LoadingState; - threads: object[]; + threadIds: number[]; } export interface Account { diff --git a/front/src/store/store.ts b/front/src/store/store.ts index ad729d8..35fbf3b 100644 --- a/front/src/store/store.ts +++ b/front/src/store/store.ts @@ -11,7 +11,8 @@ interface RoomFromBack { mailboxId: number; user: string; userId: number; - // unseen: number; + unseen: number; + parent_id?: number; // todo thread } @@ -20,6 +21,8 @@ interface AccountFromBack { email: string; } +const buffer: RoomFromBack[] = []; + function createRoom(options: RoomFromBack): Room { return { id: options.id, @@ -31,7 +34,7 @@ function createRoom(options: RoomFromBack): Room { unseen: 0, messages: [], messageLoading: LoadingState.notLoaded, - threads: [], + threadIds: [], }; } @@ -48,7 +51,7 @@ export interface State { const store = createStore({ 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 }], addresses: [], activeAccount: 0, @@ -84,8 +87,21 @@ const store = createStore({ addRooms(state, payload) { // todo add if not exist payload.rooms.forEach((room: RoomFromBack) => { + if (room.roomType == RoomType.THREAD) { + buffer.push(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) { // todo add if not exist @@ -105,7 +121,9 @@ const store = createStore({ getters: { rooms: (state) => (): Room[] => { 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: (state) => diff --git a/front/src/views/room/Message.vue b/front/src/views/room/Message.vue index d3a0b41..9779ee9 100644 --- a/front/src/views/room/Message.vue +++ b/front/src/views/room/Message.vue @@ -105,6 +105,7 @@ iframe { overflow-y: auto; max-height: 300px; width: 100%; + padding: 2px 10px; max-width: 750px; /* template width being 600px to 640px up to 750px (experiment and test) */ background-color: rgb(234, 234, 234); } diff --git a/front/src/views/sidebar/rooms/Room.vue b/front/src/views/sidebar/rooms/Room.vue index 8c0b0c7..8d20094 100644 --- a/front/src/views/sidebar/rooms/Room.vue +++ b/front/src/views/sidebar/rooms/Room.vue @@ -14,9 +14,10 @@ const props = defineProps({ userId: Number, notSeen: Number, mailboxId: Number, - threads: [Object], + threadIds: [Number], }, }); +console.log(props.data.threadIds); const router = useRouter(); @@ -37,7 +38,7 @@ const router = useRouter(); > - + diff --git a/front/src/views/sidebar/rooms/threads/Thread.vue b/front/src/views/sidebar/rooms/threads/Thread.vue index bf0b8df..291bd83 100644 --- a/front/src/views/sidebar/rooms/threads/Thread.vue +++ b/front/src/views/sidebar/rooms/threads/Thread.vue @@ -1,15 +1,23 @@ diff --git a/front/src/views/sidebar/rooms/threads/ThreadList.vue b/front/src/views/sidebar/rooms/threads/ThreadList.vue index 9ac3bd6..e6c9bec 100644 --- a/front/src/views/sidebar/rooms/threads/ThreadList.vue +++ b/front/src/views/sidebar/rooms/threads/ThreadList.vue @@ -1,12 +1,12 @@