diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index d5c19d0..268d968 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -49,15 +49,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { throw new WsException('You are banned from entering this channel') } const user = (await this.userService.findUser(connect.UserId)) as User - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - // We don't need to verify if the user is already in imo - // - // if ( - // channel.users.find((usr) => usr.id === user.id) == null && - // channel.password !== '' - // ) { - if ( - channel.password !== '' && + if ( channel.password !== '' && !(await bcrypt.compare(channel.password, connect.pwd)) ) { throw new WsException('Wrong password') @@ -88,6 +80,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { @SubscribeMessage('addMessage') async onAddMessage (socket: Socket, message: CreateMessageDto): Promise { + console.log(JSON.stringify(message)); const channel = await this.chatService.getChannel(message.ChannelId) if ( (await this.chatService.getMuteDuration(channel.id, message.UserId)) > 0 diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index 4cdf59f..e531156 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -180,7 +180,6 @@ export class ChatService { async getMuteDuration (id: number, userId: number): Promise { const channel = await this.ChannelRepository.findOne({ where: { id }, - relations: { muted: true } }) if (channel === null) { throw new NotFoundException(`Channel #${id} not found`) diff --git a/back/volume/src/chat/entity/connection.entity.ts b/back/volume/src/chat/entity/connection.entity.ts index b188175..e1a4487 100644 --- a/back/volume/src/chat/entity/connection.entity.ts +++ b/back/volume/src/chat/entity/connection.entity.ts @@ -1,4 +1,4 @@ -import { Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm' +import { Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm' import Channel from './channel.entity' import User from 'src/users/entity/user.entity' @@ -12,6 +12,6 @@ export default class ConnectedUser { @JoinColumn() channel: Channel - @PrimaryGeneratedColumn() + @PrimaryColumn() socket: string } diff --git a/back/volume/src/chat/message.service.ts b/back/volume/src/chat/message.service.ts index 6f08684..c35fe17 100644 --- a/back/volume/src/chat/message.service.ts +++ b/back/volume/src/chat/message.service.ts @@ -23,10 +23,7 @@ export class MessageService { msg.text = message.text msg.channel = await this.channelService.getChannel(message.ChannelId) msg.author = (await this.usersService.findUser(message.UserId)) as User - msg.channel.messages.push(msg) - return await this.MessageRepository.save( - this.MessageRepository.create(msg) - ) + return await this.MessageRepository.save(msg) } async findMessagesInChannelForUser ( @@ -34,6 +31,7 @@ export class MessageService { user: User ): Promise { return await this.MessageRepository.createQueryBuilder('message') + .innerJoin('message.channel', 'channel') .where('message.channel = :chan', { chan: channel }) .andWhere('message.author NOT IN (:...blocked)', { blocked: user.blocked diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index 8a3a286..b954424 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -35,13 +35,23 @@ import { join } from 'path' export class UsersController { constructor (private readonly usersService: UsersService) {} + @Get('blocked') + @UseGuards(AuthenticatedGuard) + async getBlockedUsers ( + @Profile42() profile: Profile + ): Promise { + const user = await this.usersService.getFullUser(profile.id) + if (user === null) throw new BadRequestException('User not found') + return user.blocked + } + @Get('block/:id') @UseGuards(AuthenticatedGuard) async blockUser ( @Profile42() profile: Profile, @Param('id') id: number ): Promise { - const user = await this.usersService.findUser(profile.id) + const user = await this.usersService.getFullUser(profile.id) const target = await this.usersService.findUser(id) if (user === null || target === null) { throw new BadRequestException('User not found') @@ -56,7 +66,7 @@ export class UsersController { @Profile42() profile: Profile, @Param('id') id: number ): Promise { - const user = await this.usersService.findUser(profile.id) + const user = await this.usersService.getFullUser(profile.id) if (user === null) throw new BadRequestException('User not found') user.blocked = user.blocked.filter((usr: User) => { return usr.id !== id diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index 39c91f3..9cc2144 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -58,6 +58,16 @@ export class UsersService { return user } + async getFullUser (ftId: number): Promise { + let user = await this.usersRepository.findOne({ + where: { ftId }, + relations: ['results', 'blocked', 'friends'] + }) + if (user === null) throw new BadRequestException('User not found.') + return user + } + + async findOnlineUsers (): Promise { const users = await this.usersRepository.find({ where: { status: 'online' } diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 8459182..ae35ed2 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -1,7 +1,7 @@