diff --git a/back/src/chat/chat.controller.ts b/back/src/chat/chat.controller.ts index d78272c..e6fcb13 100644 --- a/back/src/chat/chat.controller.ts +++ b/back/src/chat/chat.controller.ts @@ -18,7 +18,7 @@ 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 type Channel from './entity/channel.entity' +import Channel from './entity/channel.entity' import { Profile42 } from 'src/auth/42.decorator' import { Profile } from 'passport-42' import { IsNumberString, IsPositive } from 'class-validator' @@ -221,6 +221,18 @@ export class ChatController { this.channelService.update(channel) } + @Get(':id') + async getChannel (@Param('id', ParseIntPipe) id: number): Promise { + const chan = await this.channelService.getFullChannel(id) + if (chan == null) { + throw new NotFoundException(`Channel #${id} not found`) + } + chan.users.forEach((u) => (u.socketKey = '')) + chan.admins.forEach((u) => (u.socketKey = '')) + chan.owner.socketKey = '' + return chan + } + @Get() async getChannelsForUser (@Profile42() profile: Profile): Promise { const chan = await this.channelService.getChannelsForUser(+profile.id) diff --git a/front/src/App.svelte b/front/src/App.svelte index 3b3c454..3b43f79 100644 --- a/front/src/App.svelte +++ b/front/src/App.svelte @@ -44,7 +44,7 @@ function setAppState(newState: APPSTATE | string) { if (newState === appState) return; appState = newState; - history.pushState({ appState }, "", appState); + history.pushState({ appState: appState, prevState: window.location.pathname }, "", appState); } onMount(() => { @@ -130,7 +130,6 @@ on:keydown={() => setAppState(APPSTATE.CHANNELS)} > {/if} - {#if appState === APPSTATE.FRIENDS} + {#if appState == APPSTATE.FRIENDS}
- +
{/if} {#if appState === APPSTATE.HISTORY} @@ -180,10 +183,8 @@ {/if} {#if appState === APPSTATE.PROFILE_ID}
- setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)} - on:keydown={() => - setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)} + on:click={() => setAppState(history.state.prevState)} + on:keydown={() => setAppState(history.state.prevState)} > ; - muted: Array; + admins: Array; + banned: Array>; + muted: Array>; isDM: boolean; } export interface ChatMessageServer { diff --git a/front/src/components/Chat.svelte b/front/src/components/Chat.svelte index b48a1ce..9c94493 100644 --- a/front/src/components/Chat.svelte +++ b/front/src/components/Chat.svelte @@ -4,19 +4,20 @@ import { io, Socket } from "socket.io-client"; import { show_popup, content } from "./Alert/content"; import { APPSTATE } from "../App.svelte"; - import { formatChannelNames, type ChannelsType, type ChatMessage, type ChatMessageServer } from "./Channels.svelte"; import type User from "./Profile.svelte"; - import type { CreateChannelDto } from "./dtos/create-channel.dto"; + import type { ChannelsType, ChatMessage, ChatMessageServer } from "./Channels.svelte"; import type { IdDto, MuteDto } from "./dtos/updateUser.dto"; import type { ConnectionDto } from "./dtos/connection.dto"; import type { CreateMessageDto } from "./dtos/create-message.dto"; import type { kickUserDto } from "./dtos/kickUser.dto"; + import UsersMenu from "./UsersMenu.svelte"; +
@@ -450,8 +335,8 @@ {#if !message.hidden} openProfile(message.author.username)} - on:keydown={() => openProfile(message.author.username)} + on:click={() => openUserMenu(message.author.username)} + on:keydown={() => openUserMenu(message.author.username)} style="cursor: pointer;" > {message.author.username} @@ -460,40 +345,17 @@

{/each}
- {#if showProfileMenu} -
-
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • - -
  • -
  • -
-
- {/if} + {#if showUserMenu} + dispatch("view-profile", selectedUser)} + on:add-friend={() => dispatch("add-friend", selectedUser)} + on:invite-to-game={() => dispatch("invite-to-game", selectedUser)} + /> + {/if}
- - - + {#if channel.admins.some((usr) => usr.username == member.username)} + + {:else} + + {/if}

{/each} @@ -616,17 +475,6 @@ height: 16px; } - .profile-menu { - position: absolute; - background-color: #ffffff; - border: 1px solid #dedede; - border-radius: 5px; - padding: 1rem; - max-height: 70%; - overflow-y: auto; - z-index: 1; - } - ul { list-style: none; padding: 0; diff --git a/front/src/components/Friends.svelte b/front/src/components/Friends.svelte index 4ac781e..d8289e3 100644 --- a/front/src/components/Friends.svelte +++ b/front/src/components/Friends.svelte @@ -1,12 +1,19 @@
+ {#if showUserMenu} + dispatch("view-profile", selectedUser)} + on:add-friend={addFriend} + on:invite-to-game={() => dispatch("invite-to-game", selectedUser)} + /> + {/if} +
  • + openUserMenu($store.username)} + on:keydown={() => openUserMenu($store.username)} + style="cursor: pointer;" + >{$store.username} is {$store.status} +
  • {$store.username} friends:

    {#if friends.length > 0}
    {#each friends as friend}
  • - {friend.username} is {friend.status} + openUserMenu(friend.username)} + on:keydown={() => openUserMenu(friend.username)} + style="cursor: pointer;" + >{friend.username} is {friend.status}
  • {/each}
    @@ -83,7 +122,11 @@
    {#each invits as invit}
  • - {invit.username} invited you to be friend. + openUserMenu(invit.username)} + on:keydown={() => openUserMenu(invit.username)} + style="cursor: pointer;" + >{invit.username} invited you to be friend.
  • {/each}
    diff --git a/front/src/components/UsersMenu.svelte b/front/src/components/UsersMenu.svelte new file mode 100644 index 0000000..9aeddcc --- /dev/null +++ b/front/src/components/UsersMenu.svelte @@ -0,0 +1,174 @@ + + + + +
    +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    • +
    +
    +