Browse Source

front

master
Pheuw1 2 years ago
parent
commit
0ca8b2eab8
  1. 5
      back/volume/src/chat/chat.gateway.ts
  2. 4
      front/volume/src/components/Channels.svelte
  3. 9
      front/volume/src/components/Chat.svelte

5
back/volume/src/chat/chat.gateway.ts

@ -38,6 +38,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async handleDisconnect (socket: Socket): Promise<void> { async handleDisconnect (socket: Socket): Promise<void> {
await this.onLeaveChannel(socket) await this.onLeaveChannel(socket)
socket.disconnect()
} }
@SubscribeMessage('joinChannel') @SubscribeMessage('joinChannel')
@ -84,7 +85,6 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
async onLeaveChannel (socket: Socket): Promise<void> { async onLeaveChannel (socket: Socket): Promise<void> {
const id = socket.id as any const id = socket.id as any
await this.connectedUserRepository.delete({ socket: id }) await this.connectedUserRepository.delete({ socket: id })
socket.disconnect()
} }
@SubscribeMessage('addMessage') @SubscribeMessage('addMessage')
@ -99,7 +99,8 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const createdMessage: Message = await this.messageService.createMessage( const createdMessage: Message = await this.messageService.createMessage(
message message
) )
socket.in(channel.toString()).emit('newMessage', createdMessage) console.log(createdMessage)
socket.in(channel.id.toString()).emit('newMessage', createdMessage)
} }
@SubscribeMessage('kickUser') @SubscribeMessage('kickUser')

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

@ -187,9 +187,11 @@
on:keydown={() => removeChannel(_channels.id)}>🗑️</button on:keydown={() => removeChannel(_channels.id)}>🗑️</button
> >
<button on:click={() => inviteChannel(_channels.id)}>🤝</button> <button on:click={() => inviteChannel(_channels.id)}>🤝</button>
{#if _channels.isPrivate}
<button on:click={() => changePassword(_channels.id)} <button on:click={() => changePassword(_channels.id)}
>Edit Password</button >Edit Password</button
> >
{/if}
</div> </div>
</li>{/each} </li>{/each}
{:else} {:else}
@ -227,7 +229,7 @@
} }
.channels { .channels {
background-color: #5f5e5e; background-color: #343a40;
border: 1px solid #dedede; border: 1px solid #dedede;
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;

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

@ -29,14 +29,15 @@
}); });
socket.on("newMessage", (msg: chatMessagesType) => { socket.on("newMessage", (msg: chatMessagesType) => {
console.log(msg)
chatMessages = [...chatMessages, msg]; chatMessages = [...chatMessages, msg];
}); });
onDestroy(() => { onDestroy(() => {
io.emit("LeaveChanel", async (response) => { socket.emit("LeaveChanel", async (response) => {
console.log(response.status); console.log(response.status);
}); });
io.disconnect(); socket.disconnect();
}); });
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
@ -378,9 +379,9 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.chat { .chat {
background-color: #5f5e5e; background-color: #343a40;
border: 1px solid #dedede; border: 1px solid #dedede;
border-radius: 5px; border-radius: 5px;
padding: 1rem; padding: 1rem;

Loading…
Cancel
Save