From 6cda3eaa32609223eba64c4fbef1ab398a911d9c Mon Sep 17 00:00:00 2001 From: vvandenb Date: Mon, 20 Mar 2023 13:16:18 +0100 Subject: [PATCH] * DM FIx --- back/volume/src/chat/chat.controller.ts | 8 ++------ back/volume/src/chat/chat.service.ts | 6 +++--- back/volume/src/chat/entity/channel.entity.ts | 3 +++ front/volume/src/components/Channels.svelte | 7 +++++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/back/volume/src/chat/chat.controller.ts b/back/volume/src/chat/chat.controller.ts index 2dff850..3c7b536 100644 --- a/back/volume/src/chat/chat.controller.ts +++ b/back/volume/src/chat/chat.controller.ts @@ -45,9 +45,7 @@ export class ChatController { const dms = channels.filter((channel: Channel) => { return ( (channel.name === `${user.ftId}&${other.ftId}` || - channel.name === `${other.ftId}&${user.ftId}`) && - (channel.password === undefined || channel.password === '') && - channel.isPrivate + channel.name === `${other.ftId}&${user.ftId}`) ) }) if (dms.length === 0) { @@ -67,9 +65,6 @@ export class ChatController { if (user == null) { throw new NotFoundException(`User #${target.id} not found`) } - if (channel.isPrivate && channel.password === '') { - throw new BadRequestException('You cannot add more users to a DM') - } if (!(await this.channelService.isUser(channel.id, +profile.id))) { throw new BadRequestException( 'You are not allowed to invite users to this channel' @@ -213,6 +208,7 @@ export class ChatController { throw new BadRequestException('You are not the owner of this channel') } let channel = (await this.channelService.getChannel(id)) as Channel + if (channel.isDM) throw new BadRequestException('You cannot set a password on a DM channel') channel.password = await this.channelService.hash(data.password) this.channelService.update(channel) } diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index b794cb5..4709c0b 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -42,9 +42,7 @@ export class ChatService { const dmAlreadyExists = channels.find((channel: Channel) => { return ( (channel.name === `${user.ftId}&${otherUser.ftId}` || - channel.name === `${otherUser.ftId}&${user.ftId}`) && - (channel.password === undefined || channel.password === '') && - channel.isPrivate + channel.name === `${otherUser.ftId}&${user.ftId}`) ) }) if (dmAlreadyExists !== undefined) { @@ -60,6 +58,7 @@ export class ChatService { newChannel.name = channel.name newChannel.isPrivate = channel.isPrivate newChannel.password = await this.hash(channel.password) + newChannel.isDM = false console.log("New channel: ", JSON.stringify(newChannel)) } return await this.ChannelRepository.save(newChannel) @@ -73,6 +72,7 @@ export class ChatService { newDM.users = [user, otherUser] newDM.admins = [] newDM.name = `${user.ftId}&${otherUser.ftId}` + newDM.isDM = true return newDM } diff --git a/back/volume/src/chat/entity/channel.entity.ts b/back/volume/src/chat/entity/channel.entity.ts index 72eb420..8d4f2f1 100644 --- a/back/volume/src/chat/entity/channel.entity.ts +++ b/back/volume/src/chat/entity/channel.entity.ts @@ -46,4 +46,7 @@ export default class Channel { @Column('text', { array: true, default: [] }) muted: number[][] + + @Column({ default: false }) + isDM: boolean } diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index cc2ea40..a1b721f 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -9,6 +9,7 @@ owner: User; banned: Array; muted: Array; + isDM: boolean; } export interface chatMessagesType { id: number; @@ -229,10 +230,12 @@ on:click={() => removeChannel(channel.id)} on:keydown={() => removeChannel(channel.id)}>🗑️ - {#if channel.isPrivate == true} + {#if channel.isPrivate == true && !channel.isDM} {/if} - + {#if !channel.isDM} + + {/if} {/each}