Browse Source

channel-message foreign key error fix that i probably broke

master
Pheuw1 2 years ago
parent
commit
f89e1a6509
  1. 18
      back/volume/src/chat/chat.gateway.ts
  2. 2
      back/volume/src/chat/chat.service.ts
  3. 2
      back/volume/src/chat/entity/message.entity.ts
  4. 1
      front/volume/src/components/Chat.svelte

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

@ -67,12 +67,12 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
channel, channel,
user user
) )
const conUser = { const conUser = new ConnectedUser()
user: user.id, conUser.user = user.id
channel: channel.id, conUser.channel = channel.id
socket: socket.id conUser.socket = socket.id
} const test = await this.connectedUserRepository.save(conUser)
this.connectedUserRepository.create(conUser) console.log(test)
this.server.to(socket.id).emit('messages', messages) this.server.to(socket.id).emit('messages', messages)
await socket.join(channel.id.toString()) await socket.join(channel.id.toString())
console.log(this.server.sockets.adapter.rooms.get(channel.id.toString())) console.log(this.server.sockets.adapter.rooms.get(channel.id.toString()))
@ -94,7 +94,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const connect = await this.connectedUserRepository.findOneBy({ const connect = await this.connectedUserRepository.findOneBy({
socket: socket.id socket: socket.id
}) })
console.log("connection removed", connect?.user) console.log('connection removed', connect?.user)
if (connect == null) return if (connect == null) return
const channel = await this.chatService.getFullChannel(connect.channel) const channel = await this.chatService.getFullChannel(connect.channel)
socket.disconnect() socket.disconnect()
@ -124,7 +124,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
@SubscribeMessage('kickUser') @SubscribeMessage('kickUser')
async onKickUser (socket: Socket, kick: kickUserDto): Promise<void> { async onKickUser (socket: Socket, kick: kickUserDto): Promise<void> {
const channel = await this.chatService.getFullChannel(kick.chan) const channel = await this.chatService.getFullChannel(kick.chan)
if (channel.owner.id === kick.to) { throw new WsException('You cannot kick the owner of a channel') } if (channel.owner.id === kick.to) {
throw new WsException('You cannot kick the owner of a channel')
}
if ( if (
channel.owner.id !== kick.from && channel.owner.id !== kick.from &&
channel.admins.findIndex((usr) => usr.id === kick.from) === -1 channel.admins.findIndex((usr) => usr.id === kick.from) === -1

2
back/volume/src/chat/chat.service.ts

@ -164,7 +164,7 @@ export class ChatService {
} }
async removeChannel(channelId: number): Promise<void> { async removeChannel(channelId: number): Promise<void> {
await this.ChannelRepository.delete(channelId) await this.ChannelRepository.remove(await this.getFullChannel(channelId))
} }
async isOwner (id: number, userId: number): Promise<boolean> { async isOwner (id: number, userId: number): Promise<boolean> {

2
back/volume/src/chat/entity/message.entity.ts

@ -22,7 +22,7 @@ export default class Message {
@JoinColumn() @JoinColumn()
author: User author: User
@ManyToOne(() => Channel, (channel) => channel.messages) @ManyToOne(() => Channel, (channel) => channel.messages, { onDelete: 'CASCADE' })
@JoinTable() @JoinTable()
channel: Channel channel: Channel

1
front/volume/src/components/Chat.svelte

@ -420,6 +420,7 @@
padding: 1rem; padding: 1rem;
max-width: 90%; max-width: 90%;
width: auto; width: auto;
margin: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }

Loading…
Cancel
Save