Browse Source

* Many fixes

master
vvandenb 2 years ago
parent
commit
5f5671a8a1
  1. 5
      back/volume/src/users/users.controller.ts
  2. 4
      front/volume/src/App.svelte
  3. 7
      front/volume/src/components/Channels.svelte
  4. 29
      front/volume/src/components/Chat.svelte
  5. 3
      front/volume/src/components/NavBar.svelte
  6. 8
      front/volume/src/components/Pong/Pong.svelte

5
back/volume/src/users/users.controller.ts

@ -55,6 +55,7 @@ export class UsersController {
if (user === null || target === null) { if (user === null || target === null) {
throw new BadRequestException('User not found') throw new BadRequestException('User not found')
} }
if (user.ftId === id) throw new BadRequestException('Cannot block yourself')
user.blocked.push(target) user.blocked.push(target)
console.log('user', JSON.stringify(user)) console.log('user', JSON.stringify(user))
console.log('user', JSON.stringify(target)) console.log('user', JSON.stringify(target))
@ -69,9 +70,11 @@ export class UsersController {
): Promise<void> { ): Promise<void> {
const user = await this.usersService.getFullUser(+profile.id) const user = await this.usersService.getFullUser(+profile.id)
if (user === null) throw new BadRequestException('User not found') if (user === null) throw new BadRequestException('User not found')
const lenBefore = user.blocked.length
user.blocked = user.blocked.filter((usr: User) => { user.blocked = user.blocked.filter((usr: User) => {
return usr.id !== id return usr.ftId !== id
}) })
if (lenBefore === user.blocked.length) throw new BadRequestException('User not found')
await this.usersService.save(user) await this.usersService.save(user)
} }

4
front/volume/src/App.svelte

@ -149,6 +149,7 @@
// GAME // GAME
let pong: Pong; let pong: Pong;
let gamePlaying: boolean = false; let gamePlaying: boolean = false;
let failedGameLogIn: boolean = false;
let resetGameConnection: () => void; let resetGameConnection: () => void;
</script> </script>
@ -175,6 +176,7 @@
{clickFriends} {clickFriends}
{clickChannels} {clickChannels}
{clickLeaderboard} {clickLeaderboard}
{failedGameLogIn}
/> />
{#if appState.includes(`${APPSTATE.CHANNELS}#`)} {#if appState.includes(`${APPSTATE.CHANNELS}#`)}
{#key appState} {#key appState}
@ -246,7 +248,7 @@
/> />
</div> </div>
{/if} {/if}
<Pong bind:gamePlaying={gamePlaying} bind:this={pong} {appState} {setAppState} bind:resetGameConnection={resetGameConnection} /> <Pong bind:gamePlaying={gamePlaying} bind:this={pong} bind:failedGameLogIn={failedGameLogIn} {appState} {setAppState} bind:resetGameConnection={resetGameConnection} />
{/if} {/if}
</Modal> </Modal>

7
front/volume/src/components/Channels.svelte

@ -229,15 +229,10 @@
on:click={() => removeChannel(channel.id)} on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button on:keydown={() => removeChannel(channel.id)}>🗑️</button
> >
<!-- Show invite if channel has password but is not DM --> {#if channel.isPrivate == true}
{#if channel.isPrivate == true && channel.password}
<button on:click={() => inviteChannel(channel.id)}>🤝</button> <button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if} {/if}
<!-- Show change password if channel is not DM -->
{#if !(channel.isPrivate == true && !channel.password)}
<button on:click={() => changePassword(channel.id)}>🔑</button> <button on:click={() => changePassword(channel.id)}>🔑</button>
{/if}
</div> </div>
</li> </li>
{/each} {/each}

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

@ -180,18 +180,14 @@
}); });
if (response.ok) { if (response.ok) {
const target = await response.json(); const target = await response.json();
response = await fetch(API_URL + "/users/" + target.ftId + "/block", { response = await fetch(API_URL + "/users/block/" + target.ftId, {
credentials: "include", credentials: "include",
method: "DELETE", method: "DELETE",
mode: "cors", mode: "cors"
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ id: target.ftId }),
}); });
} }
if (response.ok) await show_popup("User blocked", false); if (response.ok) await show_popup("User unblocked", false);
else await show_popup("Failed to block user", false); else await show_popup("Failed to unblock user", false);
}; };
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
@ -218,7 +214,7 @@
}); });
if (response.ok) { if (response.ok) {
socket.emit("kickUser", {chan: channel.id, from: $store.ftId, to: target.ftId}); socket.emit("kickUser", {chan: channel.id, from: $store.ftId, to: target.ftId});
} else await show_popup(`Ban of ${username}: ${response.text}`, false); } else await show_popup(`Ban of ${username}: ${await response.text()}`, false);
} }
}; };
@ -260,14 +256,14 @@
to: target.ftId, to: target.ftId,
}); });
} else { } else {
await show_popup("merde", false); await show_popup("Failed to kick: " + await response.text(), false);
} }
}; };
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
const muteUser = async (username: string) => { const muteUser = async (username: string) => {
const prompt = window.prompt("Enter mute duration in seconds"); await show_popup("Enter mute duration in seconds");
let response = await fetch(API_URL + "/users/" + username + "/byname", { let response = await fetch(API_URL + "/users/" + username + "/byname", {
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
@ -281,7 +277,7 @@
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ data: [target.ftId, +prompt] }), body: JSON.stringify({ data: [target.ftId, +$content] }),
}); });
} }
if (response.ok) await show_popup("User muted", false); if (response.ok) await show_popup("User muted", false);
@ -400,15 +396,9 @@
</button> </button>
</li> </li>
<li> <li>
{#if !blockedUsers.filter((user) => (user.username = selectedUser)).length}
<button on:click={() => blockUser(selectedUser)}> <button on:click={() => blockUser(selectedUser)}>
Block User Block User
</button> </button>
{:else}
<button on:click={() => unblockUser(selectedUser)}>
Unblock User
</button>
{/if}
</li> </li>
<li><button on:click={closeProfileMenu}> Close </button></li> <li><button on:click={closeProfileMenu}> Close </button></li>
</ul> </ul>
@ -446,6 +436,9 @@
<button on:click={() => removeAdminUser(member.username)}> <button on:click={() => removeAdminUser(member.username)}>
demote demote
</button> </button>
<button on:click={() => unblockUser(member.username)}>
unblock
</button>
</p> </p>
</li> </li>
{/each} {/each}

3
front/volume/src/components/NavBar.svelte

@ -19,6 +19,7 @@
export let clickFriends = () => {}; export let clickFriends = () => {};
export let clickChannels = () => {}; export let clickChannels = () => {};
export let clickLeaderboard = () => {}; export let clickLeaderboard = () => {};
export let failedGameLogIn: boolean;
let hide = true; let hide = true;
@ -27,7 +28,7 @@
} }
</script> </script>
<nav class="navigation-bar"> <nav class="navigation-bar" style={ failedGameLogIn ? "display: none" : '' } >
<ul> <ul>
<li> <li>
<img src="img/pong.png" alt="home-icon" /> <img src="img/pong.png" alt="home-icon" />

8
front/volume/src/components/Pong/Pong.svelte

@ -24,7 +24,7 @@
export function resetGameConnection() { export function resetGameConnection() {
connected = false; connected = false;
loggedIn = false; loggedIn = false;
failedLogIn = false; failedGameLogIn = false;
setupSocket(renderCanvas, canvas, context); setupSocket(renderCanvas, canvas, context);
} }
@ -38,7 +38,7 @@
export let gamePlaying: boolean; export let gamePlaying: boolean;
let connected: boolean = false; let connected: boolean = false;
let loggedIn: boolean = false; let loggedIn: boolean = false;
let failedLogIn: boolean = false; export let failedGameLogIn: boolean = false;
let socket: Socket; let socket: Socket;
let elementsColor: string = "#FFFFFF"; let elementsColor: string = "#FFFFFF";
let backgroundColor: string = "#000000"; let backgroundColor: string = "#000000";
@ -93,7 +93,7 @@
updateGameInfo(); updateGameInfo();
}, 1000); }, 1000);
} else { } else {
failedLogIn = true; failedGameLogIn = true;
} }
}); });
socket.on(GAME_EVENTS.CREATE_GAME, (succeeded: boolean) => { socket.on(GAME_EVENTS.CREATE_GAME, (succeeded: boolean) => {
@ -206,7 +206,7 @@
{/if} {/if}
{:else if !connected} {:else if !connected}
Connecting to game server... Connecting to game server...
{:else if failedLogIn} {:else if failedGameLogIn}
Failed to log in to game server. Do you have multiple pages open at the same Failed to log in to game server. Do you have multiple pages open at the same
time? If yes, please close them and try again. time? If yes, please close them and try again.
{:else if !loggedIn} {:else if !loggedIn}

Loading…
Cancel
Save