Pheuw1 2 years ago
parent
commit
fd2b066b9f
  1. 5
      back/volume/src/chat/entity/channel.entity.ts
  2. 2
      front/volume/src/App.svelte
  3. 11
      front/volume/src/components/Channels.svelte
  4. 3
      front/volume/src/components/Chat.svelte

5
back/volume/src/chat/entity/channel.entity.ts

@ -13,6 +13,11 @@ import User from 'src/users/entity/user.entity'
import Message from './message.entity' import Message from './message.entity'
import * as bcrypt from 'bcrypt' import * as bcrypt from 'bcrypt'
export interface Ban {
user: User
duration: number
}
@Entity() @Entity()
export default class Channel { export default class Channel {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()

2
front/volume/src/App.svelte

@ -167,7 +167,7 @@
let selectedChannel: ChannelsType; let selectedChannel: ChannelsType;
const handleSelectChannel = (channel: ChannelsType) => { const handleSelectChannel = (channel: ChannelsType) => {
selectedChannel = channel; selectedChannel = channel;
setAppState(APPSTATE.CHANNELS + "#" + channel.id); setAppState(APPSTATE.CHANNELS + "#" + channel.name);
}; };
// GAME // GAME

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

@ -56,7 +56,7 @@
<script lang="ts"> <script lang="ts">
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
let channelMode = ""; let channelMode = "";
const channelOptions = ["public", "private"]; const channelOptions = ["public", "private", "protected"];
const joinChannel = async (id: number) => { const joinChannel = async (id: number) => {
socket.emit("joinChannel", { socket.emit("joinChannel", {
@ -100,10 +100,11 @@
const createChannel = async () => { const createChannel = async () => {
let name; let name;
let password = "";
name = prompt("Enter a name for the new channel:"); name = prompt("Enter a name for the new channel:");
if (name) { if (name) {
let password = ""; if (channelMode === 'protected')
password = prompt("Enter a password for the new channel:"); password = prompt("Enter a password for the new channel:");
name = "🚪 " + name; name = "🚪 " + name;
const response = await fetch(API_URL + "/channels", { const response = await fetch(API_URL + "/channels", {
credentials: "include", credentials: "include",
@ -212,12 +213,10 @@
on:click={() => removeChannel(channel.id)} on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button on:keydown={() => removeChannel(channel.id)}>🗑️</button
> >
{#if channel.isPrivate == true} {#if channel.isPrivate == false}
<button on:click={() => inviteChannel(channel.id)}>🤝</button> <button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if} {/if}
{#if channel.password !== ''}
<button on:click={() => changePassword(channel.id)}>🔑</button> <button on:click={() => changePassword(channel.id)}>🔑</button>
{/if}
</div> </div>
</li> </li>

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

@ -154,6 +154,7 @@
}); });
if (response.ok) { if (response.ok) {
const target = await response.json(); const target = await response.json();
const duration = prompt("Enter a time for which the user will be banned from this channel")
response = await fetch(API_URL + "/channels/" + channel.id + "/ban", { response = await fetch(API_URL + "/channels/" + channel.id + "/ban", {
credentials: "include", credentials: "include",
method: "POST", method: "POST",
@ -163,7 +164,7 @@
}, },
body: JSON.stringify({ id: target.ftId }), body: JSON.stringify({ id: target.ftId }),
}); });
socket.emit("kickUser", channel.id, $store.ftId, target.ftId); socket.emit("kickUser", channel.id, $store.ftId, target.ftId, duration);
} }
if (response.ok) { if (response.ok) {
alert("User banned"); alert("User banned");

Loading…
Cancel
Save