Browse Source

fix chat newmessages broadcast and some thigns not sure what

master
nicolas-arnaud 2 years ago
parent
commit
94766845fd
  1. 16
      back/volume/src/chat/chat.controller.ts
  2. 4
      back/volume/src/chat/chat.gateway.ts

16
back/volume/src/chat/chat.controller.ts

@ -232,6 +232,22 @@ export class ChatController {
})
}
@Get(':id/leave')
async leaveChannel (
@Profile42() profile: Profile,
@Param('id', ParseIntPipe) id: number
): Promise<void> {
if (await this.channelService.isOwner(id, +profile.id)) {
this.channelService.removeChannel(id) // -> verify that the deletion the break others users behaviors.
}
const channel = await this.channelService.getFullChannel(id)
channel.users = channel.users.filter((usr: User) => {
return usr.ftId !== profile.id
})
await this.channelService.save(channel)
}
@Post()
async createChannel (@Body() channel: CreateChannelDto): Promise<Channel> {
return await this.channelService.createChannel(channel)

4
back/volume/src/chat/chat.gateway.ts

@ -81,7 +81,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
}
@SubscribeMessage('addMessage')
async onAddMessage (socket: Socket, message: CreateMessageDto): Promise<void> {
async onAddMessage (message: CreateMessageDto): Promise<void> {
console.log(JSON.stringify(message))
const channel = await this.chatService.getChannel(message.ChannelId)
if (
@ -93,7 +93,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
message
)
console.log(createdMessage)
socket.in(channel.id.toString()).emit('newMessage', createdMessage)
this.server.to(channel.id.toString()).emit('newMessage', createdMessage)
}
@SubscribeMessage('kickUser')

Loading…
Cancel
Save