Browse Source

some more fix

master
nicolas-arnaud 2 years ago
parent
commit
6e8b9a4d85
  1. 22
      back/volume/src/chat/chat.gateway.ts
  2. 10
      front/volume/src/components/Chat.svelte

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

@ -76,7 +76,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
user user
); );
const conUser = new ConnectedUser(); const conUser = new ConnectedUser();
conUser.user = user.id; conUser.user = user.ftId;
conUser.channel = channel.id; conUser.channel = channel.id;
conUser.socket = socket.id; conUser.socket = socket.id;
const test = await this.connectedUserRepository.save(conUser); const test = await this.connectedUserRepository.save(conUser);
@ -95,11 +95,11 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
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();
if (connect.user === channel.owner.id) { if (connect.user === channel.owner.ftId) {
this.server.in(channel.id.toString()).disconnectSockets(); this.server.in(channel.id.toString()).disconnectSockets();
await this.chatService.removeChannel(channel.id); await this.chatService.removeChannel(channel.id);
} else { } else {
channel.users = channel.users.filter((e) => e.id !== connect.user); channel.users = channel.users.filter((e) => e.ftId !== connect.user);
} }
await this.connectedUserRepository.delete({ socket: socket.id }); await this.connectedUserRepository.delete({ socket: socket.id });
} }
@ -107,7 +107,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
@SubscribeMessage("addMessage") @SubscribeMessage("addMessage")
async onAddMessage(socket: Socket, message: CreateMessageDto): Promise<void> { async onAddMessage(socket: Socket, message: CreateMessageDto): Promise<void> {
const channel = await this.chatService.getChannel(message.ChannelId); const channel = await this.chatService.getChannel(message.ChannelId);
if (await this.chatService.isMuted(message.UserId, channel.id)) { if (await this.chatService.isMuted(channel.id, message.UserId)) {
throw new WsException("You are muted"); throw new WsException("You are muted");
} }
const createdMessage: Message = await this.messageService.createMessage( const createdMessage: Message = await this.messageService.createMessage(
@ -119,24 +119,24 @@ 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) { if (channel.owner.ftId === kick.to) {
throw new WsException("You cannot kick the owner of a channel"); throw new WsException("You cannot kick the owner of a channel");
} }
if ( if (
channel.owner.id !== kick.from && channel.owner.ftId !== kick.from &&
channel.admins.findIndex((usr) => usr.id === kick.from) === -1 channel.admins.findIndex((usr) => usr.ftId === kick.from) === -1
) { ) {
throw new WsException("You do not have the required privileges"); throw new WsException("You do not have the required privileges");
} }
const user = (await this.userService.findUser(kick.to)) as User; const user = (await this.userService.findUser(kick.to)) as User;
const connect = (await this.connectedUserRepository.findOneBy({ const connect = (await this.connectedUserRepository.findOneBy({
user: user.id, user: user.ftId,
})) as ConnectedUser; })) as ConnectedUser;
console.log(`kicking ${user.username} from ${channel.name}`);
// await this.onLeaveChannel(socket) // await this.onLeaveChannel(socket)
await this.server.sockets.sockets
.get(connect.socket)
?.leave(channel.id.toString());
this.server.sockets.sockets.get(connect.socket)?.emit("kicked"); this.server.sockets.sockets.get(connect.socket)?.emit("kicked");
await this.server.sockets.sockets
.get(connect.socket)?.leave(channel.id.toString());
this.server.sockets.sockets.get(connect.socket)?.disconnect(); this.server.sockets.sockets.get(connect.socket)?.disconnect();
} }
} }

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

@ -5,8 +5,7 @@
import { show_popup, content } from "./Alert/content"; import { show_popup, content } from "./Alert/content";
import { APPSTATE } from "../App.svelte"; import { APPSTATE } from "../App.svelte";
import { formatChannelNames, type ChannelsType, type chatMessagesType } from "./Channels.svelte"; import { formatChannelNames, type ChannelsType, type chatMessagesType } from "./Channels.svelte";
import type User from "./Profile.svelte"; import type User from "./Profile.svelte"; </script>
</script>
<script lang="ts"> <script lang="ts">
export let channel: ChannelsType; export let channel: ChannelsType;
@ -79,9 +78,9 @@
setAppState(APPSTATE.CHANNELS); setAppState(APPSTATE.CHANNELS);
}); });
socket.on("kicked", (msg: string) => { socket.on("kicked", () => {
show_popup(`You have been kicked from channel: ${msg}`, false); show_popup(`You have been kicked from channel`, false);
setAppState(APPSTATE.CHANNELS); setAppState(APPSTATE.HOME);
}) })
console.log("Try to join channel: ", $store.ftId, channel.id, $content); console.log("Try to join channel: ", $store.ftId, channel.id, $content);
@ -257,7 +256,6 @@
from: $store.ftId, from: $store.ftId,
to: target.ftId, to: target.ftId,
}); });
dispatch("return-home");
} else { } else {
await show_popup("merde", false); await show_popup("merde", false);
} }

Loading…
Cancel
Save