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. 21
      front/volume/src/components/Channels.svelte
  4. 35
      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) {
throw new BadRequestException('User not found')
}
if (user.ftId === id) throw new BadRequestException('Cannot block yourself')
user.blocked.push(target)
console.log('user', JSON.stringify(user))
console.log('user', JSON.stringify(target))
@ -69,9 +70,11 @@ export class UsersController {
): Promise<void> {
const user = await this.usersService.getFullUser(+profile.id)
if (user === null) throw new BadRequestException('User not found')
const lenBefore = user.blocked.length
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)
}

4
front/volume/src/App.svelte

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

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

@ -224,20 +224,15 @@
<li>
<span>{channel.name} : {channel.id}</span>
<div style="display:block; margin-right:10%">
<button on:click={() => onSelectChannel(channel)}>🔌</button>
<button
on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button
>
<!-- Show invite if channel has password but is not DM -->
{#if channel.isPrivate == true && channel.password}
<button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if}
<!-- Show change password if channel is not DM -->
{#if !(channel.isPrivate == true && !channel.password)}
<button on:click={() => onSelectChannel(channel)}>🔌</button>
<button
on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button
>
{#if channel.isPrivate == true}
<button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if}
<button on:click={() => changePassword(channel.id)}>🔑</button>
{/if}
</div>
</li>
{/each}

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

@ -180,18 +180,14 @@
});
if (response.ok) {
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",
method: "DELETE",
mode: "cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ id: target.ftId }),
mode: "cors"
});
}
if (response.ok) await show_popup("User blocked", false);
else await show_popup("Failed to block user", false);
if (response.ok) await show_popup("User unblocked", false);
else await show_popup("Failed to unblock user", false);
};
//--------------------------------------------------------------------------------/
@ -218,7 +214,7 @@
});
if (response.ok) {
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,
});
} else {
await show_popup("merde", false);
await show_popup("Failed to kick: " + await response.text(), false);
}
};
//--------------------------------------------------------------------------------/
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", {
credentials: "include",
mode: "cors",
@ -281,7 +277,7 @@
headers: {
"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);
@ -400,15 +396,9 @@
</button>
</li>
<li>
{#if !blockedUsers.filter((user) => (user.username = selectedUser)).length}
<button on:click={() => blockUser(selectedUser)}>
Block User
</button>
{:else}
<button on:click={() => unblockUser(selectedUser)}>
Unblock User
</button>
{/if}
<button on:click={() => blockUser(selectedUser)}>
Block User
</button>
</li>
<li><button on:click={closeProfileMenu}> Close </button></li>
</ul>
@ -446,6 +436,9 @@
<button on:click={() => removeAdminUser(member.username)}>
demote
</button>
<button on:click={() => unblockUser(member.username)}>
unblock
</button>
</p>
</li>
{/each}

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

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

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

@ -24,7 +24,7 @@
export function resetGameConnection() {
connected = false;
loggedIn = false;
failedLogIn = false;
failedGameLogIn = false;
setupSocket(renderCanvas, canvas, context);
}
@ -38,7 +38,7 @@
export let gamePlaying: boolean;
let connected: boolean = false;
let loggedIn: boolean = false;
let failedLogIn: boolean = false;
export let failedGameLogIn: boolean = false;
let socket: Socket;
let elementsColor: string = "#FFFFFF";
let backgroundColor: string = "#000000";
@ -93,7 +93,7 @@
updateGameInfo();
}, 1000);
} else {
failedLogIn = true;
failedGameLogIn = true;
}
});
socket.on(GAME_EVENTS.CREATE_GAME, (succeeded: boolean) => {
@ -206,7 +206,7 @@
{/if}
{:else if !connected}
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
time? If yes, please close them and try again.
{:else if !loggedIn}

Loading…
Cancel
Save