diff --git a/front/src/store/models/model.ts b/front/src/store/models/model.ts index 8903d80..9741482 100644 --- a/front/src/store/models/model.ts +++ b/front/src/store/models/model.ts @@ -33,6 +33,7 @@ export interface Room { members: Address[]; notSeen: number; threadIds: number[]; + parent_id?: number; } export interface Account { diff --git a/front/src/store/store.ts b/front/src/store/store.ts index 032b105..eb79e9c 100644 --- a/front/src/store/store.ts +++ b/front/src/store/store.ts @@ -32,6 +32,7 @@ function createRoom(options: RoomFromBack): Room { user: options.user, notSeen: options.notSeen, threadIds: [], + parent_id: options.parent_id, }; } @@ -133,9 +134,19 @@ const store = createStore({ }); }, removeRoom(state, payload) { + console.log(payload); const roomMessageIndex = state.roomMessages.findIndex((roomM) => roomM.roomId === payload.roomId); state.roomMessages.splice(roomMessageIndex, 1); const roomIndex = state.rooms.findIndex((room) => room.id === payload.roomId); + const roomToDelete = state.rooms[roomIndex]; + // todo debug parent_id to root_id + // remove thread + if (roomToDelete.roomType === RoomType.THREAD && roomToDelete.parent_id) { + const parentRoom = roomOnId(state, roomToDelete.parent_id); + if (parentRoom) { + parentRoom.threadIds = parentRoom?.threadIds.filter((id) => id !== roomToDelete.id); + } + } state.rooms.splice(roomIndex, 1); // state.activeRoom = state.rooms[0].id; // router.push(`/${state.activeRoom}`);