Browse Source

removed connectedc User

master
nicolas-arnaud 2 years ago
parent
commit
4db1db4070
  1. 13
      back/volume/src/chat/chat.gateway.ts
  2. 3
      back/volume/src/chat/chat.module.ts
  3. 4
      back/volume/src/chat/chat.service.ts
  4. 17
      back/volume/src/chat/entity/connection.entity.ts
  5. 19
      docker-compose.yml
  6. 2
      front/volume/src/components/Channels.svelte

13
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<ConnectedUser>
) {}
async handleConnection (socket: Socket): Promise<void> {}
@ -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<void> {
const id = socket.id as any
await this.connectedUserRepository.delete({ socket: id })
}
@SubscribeMessage('addMessage')

3
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],

4
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> {
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`)
}

17
back/volume/src/chat/entity/connection.entity.ts

@ -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
}

19
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

2
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;

Loading…
Cancel
Save