From 569c271c6c1ceb984ecdbfdfc7888e4a343a871b Mon Sep 17 00:00:00 2001 From: grimhilt Date: Mon, 3 Apr 2023 20:11:07 +0200 Subject: [PATCH] show description in room header --- back/db/api.ts | 3 +- front/src/components/Badge.vue | 52 ++++++++++++++++++-------- front/src/store/models/model.ts | 7 ++-- front/src/store/store.ts | 30 ++++++++++----- front/src/utils/string.ts | 2 + front/src/views/room/Header.vue | 46 +++++++++++++++++++---- front/src/views/room/RoomView.vue | 11 +++--- front/src/views/sidebar/Sidebar.vue | 12 +++--- front/src/views/sidebar/rooms/Room.vue | 3 +- front/tsconfig.json | 3 +- 10 files changed, 118 insertions(+), 51 deletions(-) diff --git a/back/db/api.ts b/back/db/api.ts index 0972ad3..4043d8b 100644 --- a/back/db/api.ts +++ b/back/db/api.ts @@ -35,6 +35,7 @@ export async function getRooms(mailboxId) { 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 @@ -91,7 +92,7 @@ export async function getMessages(roomId) { WHERE msg.room_id = ? GROUP BY msg.message_id - ORDER BY message.idate; + ORDER BY message.idate DESC; `; const values = [roomId]; return await execQueryAsync(query, values); diff --git a/front/src/components/Badge.vue b/front/src/components/Badge.vue index 0be364b..72bf93e 100644 --- a/front/src/components/Badge.vue +++ b/front/src/components/Badge.vue @@ -1,25 +1,45 @@ + + diff --git a/front/src/store/models/model.ts b/front/src/store/models/model.ts index ff3aa84..a4d9741 100644 --- a/front/src/store/models/model.ts +++ b/front/src/store/models/model.ts @@ -1,14 +1,13 @@ - export enum RoomType { ROOM = 0, CHANNEL = 1, GROUP = 2, DM = 3, THREAD = 4, -}; +} export interface Message { - + todo: true; } export interface Room { @@ -32,4 +31,4 @@ export interface Account { export interface Address { todo: boolean; -} \ No newline at end of file +} diff --git a/front/src/store/store.ts b/front/src/store/store.ts index e5e2e12..7be19e2 100644 --- a/front/src/store/store.ts +++ b/front/src/store/store.ts @@ -1,4 +1,5 @@ import API from "@/services/imapAPI"; +import { decodeEmojis } from "@/utils/string"; import { createStore, Store } from "vuex"; import { Room, Account, Address, RoomType, Message } from "./models/model"; @@ -19,9 +20,10 @@ interface AccountFromBack { } function createRoom(options: RoomFromBack): Room { + console.log(options.roomType); return { id: options.id, - roomName: options.roomName, + roomName: decodeEmojis(options.roomName), roomType: options.roomType, mailboxId: options.mailboxId, userId: options.userId, @@ -91,18 +93,26 @@ const store = createStore({ }, }, getters: { - rooms: (state) => () => { + rooms: (state) => (): Room[] => { if (state.activeAccount === 0) return state.rooms; return state.rooms.filter((room) => room.mailboxId == state.activeAccount); }, - messages: (state) => (roomId: number) => { - const room = state.rooms.find((room) => room.id == roomId); - if (!room) return []; - if (!room.messagesFetched) { - store.dispatch("fetchMessages", { roomId: room.id }); - } - return room.messages; - }, + room: + (state) => + (roomId: number): Room | undefined => { + const room = state.rooms.find((room) => room.id == roomId); + return room; + }, + messages: + (state) => + (roomId: number): Message[] => { + const room = state.rooms.find((room) => room.id == roomId); + if (!room) return []; + if (!room.messagesFetched) { + store.dispatch("fetchMessages", { roomId: room.id }); + } + return room.messages; + }, }, actions: { fetchAccounts: async (context) => { diff --git a/front/src/utils/string.ts b/front/src/utils/string.ts index ae78b00..1c1e40b 100644 --- a/front/src/utils/string.ts +++ b/front/src/utils/string.ts @@ -1,3 +1,5 @@ +// todo optimize + export function decodeEmojis(text: string): string { if (!text) return text; const regex = /\\u{([^}]+)}/g; diff --git a/front/src/views/room/Header.vue b/front/src/views/room/Header.vue index 49be798..e589507 100644 --- a/front/src/views/room/Header.vue +++ b/front/src/views/room/Header.vue @@ -1,22 +1,54 @@ - diff --git a/front/src/views/room/RoomView.vue b/front/src/views/room/RoomView.vue index b346aab..513192c 100644 --- a/front/src/views/room/RoomView.vue +++ b/front/src/views/room/RoomView.vue @@ -1,17 +1,17 @@