diff --git a/back/volume/src/chat/chat.controller.ts b/back/volume/src/chat/chat.controller.ts index 6437ace..2ffdc07 100644 --- a/back/volume/src/chat/chat.controller.ts +++ b/back/volume/src/chat/chat.controller.ts @@ -160,8 +160,8 @@ export class ChatController { if (await this.channelService.isBanned(channel.id, target.data[0])) { throw new BadRequestException('User is already banned from this channel') } - channel.banned.push([target.data[0], Date.now() + target.data[1] * 1000]) console.log(channel.banned) + channel.banned.push([target.data[0], Date.now() + target.data[1] * 1000]) await this.channelService.save(channel) } diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index 68fbe69..a82e9b6 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -46,8 +46,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { const connect = await this.connectedUserRepository.findOneBy({ socket: socket.id, }); - if (connect) + if (connect) { await this.connectedUserRepository.delete({ socket: socket.id }); + } socket.disconnect(); console.log("socket %s has disconnected", socket.id); } @@ -124,7 +125,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { } if ( channel.owner.ftId !== kick.from && - channel.admins.findIndex((usr) => usr.ftId === kick.from) === -1 + channel.admins.findIndex((usr) => +usr.ftId === kick.from) === -1 ) { throw new WsException("You do not have the required privileges"); } @@ -132,11 +133,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { const connect = (await this.connectedUserRepository.findOneBy({ user: user.ftId, })) as ConnectedUser; - console.log(`kicking ${user.username} from ${channel.name}`); - // await this.onLeaveChannel(socket) - 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(); + if (connect) { + console.log(`kicking ${user.username} from ${channel.name}`); + this.server.sockets.sockets.get(connect.socket)?.emit("kicked"); + } } } diff --git a/back/volume/src/chat/entity/connection.entity.ts b/back/volume/src/chat/entity/connection.entity.ts index de27caa..cc28f7d 100644 --- a/back/volume/src/chat/entity/connection.entity.ts +++ b/back/volume/src/chat/entity/connection.entity.ts @@ -1,8 +1,5 @@ import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm' -import Channel from './channel.entity' -import User from 'src/users/entity/user.entity' - @Entity() export default class ConnectedUser { @Column() diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 2970e74..56ad0dc 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -7,6 +7,8 @@ isPrivate: boolean; password: string; owner: User; + banned: Array; + muted: Array; } export interface chatMessagesType { id: number; diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 7293ec6..7bc0c4d 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -61,16 +61,23 @@ } socket.on("newMessage", (msg: chatMessagesType) => { console.log(msg); - messages = [...messages, msg]; + if (blockedUsers.findIndex((user) => msg.author.ftId === user.ftId) === -1) + messages = [...messages, msg]; }); socket.on("messages", (msgs: Array) => { messages = msgs; - getMembers(); + getMembers().then(() => { + console.log("You are joining channel: ", channel.name); + console.log(`Blocked users: ${blockedUsers.map((user) => user.username)}`); + console.log(`Chat members: ${chatMembers.map((user) => user.username)}`); + console.log(`Banned members: ${channel.banned.map((user) => user.username)}`); + console.log(`Muted users: ${channel.muted.map((user) => user.username)}`); + }); + usersInterval = setInterval(async () => { getMembers(); }, 1000); - console.log("You are joining channel: ", channel.name); }); socket.on("failedJoin", (error: string) => {