From 6e8b9a4d85ad46f9e8ddc8e6390396cd7c877e62 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Sun, 19 Mar 2023 19:42:37 +0100 Subject: [PATCH] some more fix --- back/volume/src/chat/chat.gateway.ts | 22 +++++++++++----------- front/volume/src/components/Chat.svelte | 10 ++++------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index a25f536..68fbe69 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -76,7 +76,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { user ); const conUser = new ConnectedUser(); - conUser.user = user.id; + conUser.user = user.ftId; conUser.channel = channel.id; conUser.socket = socket.id; const test = await this.connectedUserRepository.save(conUser); @@ -95,11 +95,11 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { if (connect == null) return; const channel = await this.chatService.getFullChannel(connect.channel); socket.disconnect(); - if (connect.user === channel.owner.id) { + if (connect.user === channel.owner.ftId) { this.server.in(channel.id.toString()).disconnectSockets(); await this.chatService.removeChannel(channel.id); } else { - channel.users = channel.users.filter((e) => e.id !== connect.user); + channel.users = channel.users.filter((e) => e.ftId !== connect.user); } await this.connectedUserRepository.delete({ socket: socket.id }); } @@ -107,7 +107,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { @SubscribeMessage("addMessage") async onAddMessage(socket: Socket, message: CreateMessageDto): Promise { const channel = await this.chatService.getChannel(message.ChannelId); - if (await this.chatService.isMuted(message.UserId, channel.id)) { + if (await this.chatService.isMuted(channel.id, message.UserId)) { throw new WsException("You are muted"); } const createdMessage: Message = await this.messageService.createMessage( @@ -119,24 +119,24 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { @SubscribeMessage("kickUser") async onKickUser(socket: Socket, kick: kickUserDto): Promise { const channel = await this.chatService.getFullChannel(kick.chan); - if (channel.owner.id === kick.to) { + if (channel.owner.ftId === kick.to) { throw new WsException("You cannot kick the owner of a channel"); } if ( - channel.owner.id !== kick.from && - channel.admins.findIndex((usr) => usr.id === kick.from) === -1 + channel.owner.ftId !== kick.from && + channel.admins.findIndex((usr) => usr.ftId === kick.from) === -1 ) { throw new WsException("You do not have the required privileges"); } const user = (await this.userService.findUser(kick.to)) as User; const connect = (await this.connectedUserRepository.findOneBy({ - user: user.id, + user: user.ftId, })) as ConnectedUser; + console.log(`kicking ${user.username} from ${channel.name}`); // await this.onLeaveChannel(socket) - await this.server.sockets.sockets - .get(connect.socket) - ?.leave(channel.id.toString()); this.server.sockets.sockets.get(connect.socket)?.emit("kicked"); + await this.server.sockets.sockets + .get(connect.socket)?.leave(channel.id.toString()); this.server.sockets.sockets.get(connect.socket)?.disconnect(); } } diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 2125708..7293ec6 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -5,8 +5,7 @@ import { show_popup, content } from "./Alert/content"; import { APPSTATE } from "../App.svelte"; import { formatChannelNames, type ChannelsType, type chatMessagesType } from "./Channels.svelte"; - import type User from "./Profile.svelte"; - + import type User from "./Profile.svelte";