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
);
const conUser = new ConnectedUser();
conUser.user = user.id;
conUser.user = user.ftId;
conUser.channel = channel.id;
conUser.socket = socket.id;
const test = await this.connectedUserRepository.save(conUser);
@ -95,11 +95,11 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
if (connect == null) return;
const channel = await this.chatService.getFullChannel(connect.channel);
socket.disconnect();
if (connect.user === channel.owner.id) {
if (connect.user === channel.owner.ftId) {
this.server.in(channel.id.toString()).disconnectSockets();
await this.chatService.removeChannel(channel.id);
} 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 });
}
@ -107,7 +107,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
@SubscribeMessage("addMessage")
async onAddMessage(socket: Socket, message: CreateMessageDto): Promise<void> {
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");
}
const createdMessage: Message = await this.messageService.createMessage(
@ -119,24 +119,24 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
@SubscribeMessage("kickUser")
async onKickUser(socket: Socket, kick: kickUserDto): Promise<void> {
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");
}
if (
channel.owner.id !== kick.from &&
channel.admins.findIndex((usr) => usr.id === kick.from) === -1
channel.owner.ftId !== kick.from &&
channel.admins.findIndex((usr) => usr.ftId === kick.from) === -1
) {
throw new WsException("You do not have the required privileges");
}
const user = (await this.userService.findUser(kick.to)) as User;
const connect = (await this.connectedUserRepository.findOneBy({
user: user.id,
user: user.ftId,
})) as ConnectedUser;
console.log(`kicking ${user.username} from ${channel.name}`);
// 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");
await this.server.sockets.sockets
.get(connect.socket)?.leave(channel.id.toString());
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 { APPSTATE } from "../App.svelte";
import { formatChannelNames, type ChannelsType, type chatMessagesType } from "./Channels.svelte";
import type User from "./Profile.svelte";
</script>
import type User from "./Profile.svelte"; </script>
<script lang="ts">
export let channel: ChannelsType;
@ -79,9 +78,9 @@
setAppState(APPSTATE.CHANNELS);
});
socket.on("kicked", (msg: string) => {
show_popup(`You have been kicked from channel: ${msg}`, false);
setAppState(APPSTATE.CHANNELS);
socket.on("kicked", () => {
show_popup(`You have been kicked from channel`, false);
setAppState(APPSTATE.HOME);
})
console.log("Try to join channel: ", $store.ftId, channel.id, $content);
@ -257,7 +256,6 @@
from: $store.ftId,
to: target.ftId,
});
dispatch("return-home");
} else {
await show_popup("merde", false);
}

Loading…
Cancel
Save