Browse Source

* Various fixes

master
vvandenb 2 years ago
parent
commit
f7d3c2e45c
  1. 7
      back/src/chat/chat.controller.ts
  2. 6
      back/src/chat/chat.gateway.ts
  3. 9
      back/src/chat/dto/updateUser.dto.ts
  4. 1
      front/src/components/Alert/Alert.svelte
  5. 2
      front/src/components/Channels.svelte
  6. 11
      front/src/components/Chat.svelte
  7. 17
      front/src/components/Friends.svelte
  8. 2
      front/src/components/Pong/Pong.svelte
  9. 13
      front/src/components/Profile.svelte

7
back/src/chat/chat.controller.ts

@ -18,10 +18,9 @@ import { CreateChannelDto } from './dto/create-channel.dto'
import { IdDto, PasswordDto, MuteDto } from './dto/updateUser.dto'
import type User from 'src/users/entity/user.entity'
import Channel from './entity/channel.entity'
import type Channel from './entity/channel.entity'
import { Profile42 } from 'src/auth/42.decorator'
import { Profile } from 'passport-42'
import { IsNumberString, IsPositive } from 'class-validator'
@Controller('channels')
@UseGuards(AuthenticatedGuard)
@ -145,7 +144,7 @@ export class ChatController {
const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(+target.data[0])
if (isNaN(+target.data[1])) {
throw new BadRequestException(`Invalid duration ${+target.data[1]}`)
throw new BadRequestException('Invalid duration')
}
if (user == null) {
throw new NotFoundException(`User #${+target.data[0]} not found`)
@ -174,7 +173,7 @@ export class ChatController {
const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(+mute.data[0])
if (isNaN(+mute.data[1])) {
throw new BadRequestException(`Invalid duration ${+mute.data[1]}`)
throw new BadRequestException('Invalid duration')
}
if (user == null) {
throw new NotFoundException(`User #${+mute.data[0]} not found`)

6
back/src/chat/chat.gateway.ts

@ -98,7 +98,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
if (connect == null) return false;
const channel = await this.chatService.getFullChannel(connect.channel);
if (connect.user === channel.owner.ftId) {
this.server.in(channel.id.toString()).emit('kicked');
this.server.in(channel.id.toString()).emit('deleted');
await this.chatService.removeChannel(channel.id);
} else {
channel.users = channel.users.filter((usr: User) => usr.ftId !== connect.user);
@ -114,8 +114,8 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
let channel: Channel | null = null
channel = await this.chatService.getChannel(message.ChannelId).catch(() => { return null })
if (channel == null) {
this.server.to(socket.id).emit('kicked')
throw new WsException('Channel has been removed by owner');
this.server.to(socket.id).emit('deleted')
throw new WsException('Channel has been deleted');
}
if (await this.chatService.isMuted(channel.id, message.UserId)) {
throw new WsException('You are muted');

9
back/src/chat/dto/updateUser.dto.ts

@ -1,4 +1,5 @@
import { IsEmail, IsNumber, IsString } from 'class-validator'
import { Type } from 'class-transformer'
import { IsArray, IsEmail, IsNumber, IsPositive, IsString } from 'class-validator'
export class IdDto {
@IsNumber()
@ -11,7 +12,11 @@ export class PasswordDto {
}
export class MuteDto {
data: number[]
@Type(() => Number)
@IsArray()
@IsNumber({}, { each: true })
@IsPositive({ each: true })
data: number[]
}
export class EmailDto {

1
front/src/components/Alert/Alert.svelte

@ -1,6 +1,5 @@
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { get } from "svelte/store";
import { content, popup } from "./content";
export let message: string;

2
front/src/components/Channels.svelte

@ -242,8 +242,8 @@
<div class="overlay">
<div class="channels" on:click|stopPropagation on:keydown|stopPropagation>
<div>
<h2 >Channels <button class="refresh" on:click={() => getChannels()}>🔄</button> </h2>
{#if channels.length > 0}
<h2 >Channels <button class="refresh" on:click={() => getChannels()}>🔄</button> </h2>
{#each channels as channel}
<li>
<span>{channel.name} : {channel.id}</span>

11
front/src/components/Chat.svelte

@ -108,6 +108,11 @@
setAppState(APPSTATE.HOME);
})
socket.on("deleted", () => {
show_popup(`Channel has been deleted`, false);
setAppState(APPSTATE.HOME);
})
console.log("Try to join channel: ", $store.ftId, channel.id);
});
@ -170,6 +175,7 @@
);
const duration = $content;
if (duration === "") return
if (isNaN(Number(duration)) || Number(duration) < 0) return await show_popup("Invalid duration", false);
const body: MuteDto = {
data: [target.ftId, duration]
}
@ -191,7 +197,7 @@
};
socket.emit("kickUser", data);
} else {
const error = await response.json();
const error = await response.json();
await show_popup(error.message, false)
}
}
@ -224,6 +230,7 @@
await show_popup("Enter mute duration in seconds");
const muteDuration = $content;
if (muteDuration === "") return;
if (isNaN(Number(muteDuration)) || Number(muteDuration) < 0) return await show_popup("Invalid duration", false);
let response = await fetch(API_URL + "/users/" + username + "/byname", {
credentials: "include",
mode: "cors",
@ -371,8 +378,8 @@
<button on:click={() => banUser(member.username)}> ban </button>
<button on:click={() => kickUser(member.username)}> kick </button>
<button on:click={() => muteUser(member.username)}> mute </button>
<button on:click={() => removeAdminUser(member.username)}> demote </button>
<button on:click={() => adminUser(member.username)}> promote </button>
<button on:click={() => removeAdminUser(member.username)}> demote </button>
</p>
</li>
{/each}

17
front/src/components/Friends.svelte

@ -36,7 +36,6 @@
let friends: Friend[] = [];
let invits: Friend[] = [];
let friendsInterval: ReturnType<typeof setInterval>;
let blockedUsers: Array<Friend> = [];
onMount(() => {
getFriends();
@ -68,27 +67,11 @@
let showUserMenu = false;
let selectedUser: string | null = null;
function openUserMenu(username: string) {
showUserMenu = true;
selectedUser = username;
}
function closeUserMenu() {
showUserMenu = false;
selectedUser = "";
}
</script>
<div class="overlay">
<div class="friends" on:click|stopPropagation on:keydown|stopPropagation>
<div>
<li>
<span class="message-name"
on:click={() => dispatch("view-profile", $store.username)}
on:keydown={() => dispatch("view-profile", $store.username)}
style="cursor: pointer;"
>{$store.username} is {$store.status}</span>
</li>
<h2>{$store.username} friends:</h2>
{#if friends.length > 0}
<div class="friends-list">

2
front/src/components/Pong/Pong.svelte

@ -101,7 +101,7 @@
gamePlaying = true;
} else {
gamePlaying = false;
popup.set(bind(Alert, { message: "Failed to invite user. Is he currently connected to the game?", form: false }))
show_popup("Failed to invite user. Is he currently connected to the game?", false)
}
});
socket.on(GAME_EVENTS.MATCHMAKING, (data: MatchmakingDto) => {

13
front/src/components/Profile.svelte

@ -100,7 +100,7 @@
async function handleSubmit() {
if (gamePlaying) {
popup.set(bind(Alert, { message: "Cannot change username while playing.", form: false }))
await show_popup("Cannot change username while playing.", false)
return;
}
@ -125,11 +125,11 @@
if (response.ok) {
$store.username = username;
$store.email = email;
popup.set(bind(Alert, { message: "Succefully changed informations.", form: false }))
await show_popup("Succefully changed informations.", false)
resetGameConnection();
} else {
const error = await response.json();
popup.set(bind(Alert, { message: error.message, form: false}))
await show_popup(error.message, false)
}
}
@ -143,17 +143,14 @@
credentials: "include",
});
if (response.ok) {
popup.set(bind(Alert, {
message: "Succefully " + (user.twoFA ? "enabled" : "disabled") + " 2FA",
form : false
}))
await show_popup("Succefully " + (user.twoFA ? "enabled" : "disabled") + " 2FA", false)
}
}
</script>
<div class="overlay">
<div class="profile" on:click|stopPropagation on:keydown|stopPropagation>
<h3>===| <mark>{username}'s Profile</mark> |===</h3>
<h3>===| <mark>{username}</mark> |===</h3>
<div class="profile-header">
{#if !edit}
<img src={`${API_URL}/users/${user.ftId}/avatar`} alt="avatar" class="profile-img" />

Loading…
Cancel
Save