From 956bc35158f76fd71847d34b195df5e5f1c5ffd0 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Fri, 14 Apr 2023 23:04:09 +0200 Subject: [PATCH] fix duplication of threads on account change --- back/db/api-db.ts | 2 +- front/src/store/store.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/back/db/api-db.ts b/back/db/api-db.ts index 8ac88b6..bc87f96 100644 --- a/back/db/api-db.ts +++ b/back/db/api-db.ts @@ -27,7 +27,7 @@ export async function getAccounts() { return await execQueryAsync(query, values); } -export async function getRooms(mailboxId) { +export async function getRooms(mailboxId: number) { const query = ` SELECT room.room_id AS id, diff --git a/front/src/store/store.ts b/front/src/store/store.ts index d07823f..3b79a43 100644 --- a/front/src/store/store.ts +++ b/front/src/store/store.ts @@ -21,8 +21,6 @@ interface AccountFromBack { email: string; } -const buffer: RoomFromBack[] = []; - function createRoom(options: RoomFromBack): Room { return { id: options.id, @@ -117,6 +115,7 @@ const store = createStore({ }, addRooms(state, payload) { // todo add if not exist + const buffer: RoomFromBack[] = []; payload.rooms.forEach((room: RoomFromBack) => { if (room.roomType == RoomType.THREAD) { buffer.push(room); @@ -174,7 +173,7 @@ const store = createStore({ }, getters: { rooms: (state) => (): Room[] => { - if (state.activeAccount === 0) return state.rooms; + if (state.activeAccount === 0) return state.rooms.filter((room) => room.roomType != RoomType.THREAD); return state.rooms.filter( (room) => room.mailboxId == state.activeAccount && room.roomType != RoomType.THREAD, );