diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index b81298a..3c7821d 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -16,7 +16,6 @@ import { MessageService } from './message.service' import { CreateMessageDto } from './dto/create-message.dto' import { InjectRepository } from '@nestjs/typeorm' import { Repository } from 'typeorm' -import ConnectedUser from './entity/connection.entity' import { ConnectionDto } from './dto/connection.dto' @WebSocketGateway({ @@ -30,8 +29,6 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { private readonly userService: UsersService, private readonly messageService: MessageService, private readonly chatService: ChatService, - @InjectRepository(ConnectedUser) - private readonly connectedUserRepository: Repository ) {} async handleConnection (socket: Socket): Promise {} @@ -67,24 +64,20 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { } } else await this.chatService.addUserToChannel(channel, user) console.log('5') - const conUser = { - user, - channel, - socket: socket.id - } - this.connectedUserRepository.create(conUser) + console.log('8') const messages = await this.messageService.findMessagesInChannelForUser( channel, user ) + console.log('9') this.server.to(socket.id).emit('messages', messages) + console.log('10') await socket.join(channel.id.toString()) } @SubscribeMessage('leaveChannel') async onLeaveChannel (socket: Socket): Promise { const id = socket.id as any - await this.connectedUserRepository.delete({ socket: id }) } @SubscribeMessage('addMessage') diff --git a/back/volume/src/chat/chat.module.ts b/back/volume/src/chat/chat.module.ts index 8909b26..08ad1d1 100644 --- a/back/volume/src/chat/chat.module.ts +++ b/back/volume/src/chat/chat.module.ts @@ -10,13 +10,12 @@ import { MessageService } from './message.service' import Channel from './entity/channel.entity' import Message from './entity/message.entity' -import ConnectedUser from './entity/connection.entity' @Module({ imports: [ UsersModule, AuthModule, - TypeOrmModule.forFeature([Channel, Message, ConnectedUser]) + TypeOrmModule.forFeature([Channel, Message]) ], controllers: [ChatController], providers: [ChatService, ChatGateway, MessageService], diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index 69ea0df..3d52573 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -76,6 +76,7 @@ export class ChatService { rooms = [ ...(await this.ChannelRepository.createQueryBuilder('room') .where('room.isPrivate = false') + .orderBy('room.id', 'DESC') .getMany()) ] @@ -102,7 +103,7 @@ export class ChatService { } async addUserToChannel (channel: Channel, user: User): Promise { - channel.owner = user + channel.users.push(user) return await this.ChannelRepository.save(channel) } @@ -119,6 +120,7 @@ export class ChatService { where: { id }, relations: ['users', 'admins', 'banned', 'owner'] }) + 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 deleted file mode 100644 index e1a4487..0000000 --- a/back/volume/src/chat/entity/connection.entity.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Entity, JoinColumn, OneToOne, PrimaryColumn } from 'typeorm' - -import Channel from './channel.entity' -import User from 'src/users/entity/user.entity' - -@Entity() -export default class ConnectedUser { - @OneToOne(() => User) - user: User - - @OneToOne(() => Channel) - @JoinColumn() - channel: Channel - - @PrimaryColumn() - socket: string -} diff --git a/docker-compose.yml b/docker-compose.yml index d36268d..d6b48eb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,3 +35,22 @@ services: networks: [transcendence] restart: always env_file: .env + pgadmin: + links: + - postgres:postgres + container_name: pgadmin + image: dpage/pgadmin4 + ports: + - "8081:80" + volumes: + - /data/pgadmin:/root/.pgadmin + environment: + PGADMIN_DEFAULT_EMAIL: 'usr@usr.com' + PGADMIN_DEFAULT_PASSWORD: 'pw' + GUNICORN_ACCESS_LOGFILE: '/dev/null' + PGADMIN_CONFIG_UPGRADE_CHECK_ENABLED: 'False' + depends_on: + - postgres + networks: [transcendence] + logging: + driver: none diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 43acb67..7a89ad9 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -43,11 +43,11 @@ const channel = channels.find((c) => c.id === id); if (channel) { joinChannel(id); + console.log("joined a channel") onSelectChannel(channel); } }; - //--------------------------------------------------------------------------------/ const createChannel = async () => { let name, friend;