diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index 26300cc..08d511f 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -43,28 +43,6 @@ export class UsersController { return await this.usersService.findOnlineUsers() } - @Get(':id') - async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise { - return await this.usersService.findUser(ftId) - } - - @Get() - @UseGuards(AuthenticatedGuard) - async getUser (@FtUser() profile: Profile): Promise { - return await this.usersService.findUser(profile.id) - } - - @Post() - @UseGuards(AuthenticatedGuard) - async create (@Body() payload: UserDto, @FtUser() profile: Profile) { - const user = await this.usersService.findUser(profile.id) - if (user) { - return await this.usersService.update(user.id, payload) - } else { - return await this.usersService.create(payload) - } - } - @Get('friends') @UseGuards(AuthenticatedGuard) async getFriends (@FtUser() profile: Profile) { @@ -77,15 +55,6 @@ export class UsersController { return await this.usersService.getInvits(profile.id) } - @Post('invit/:id') - @UseGuards(AuthenticatedGuard) - async invitUser ( - @FtUser() profile: Profile, - @Param('id', ParseIntPipe) id: number - ) { - return await this.usersService.invit(profile.id, id) - } - @Post('avatar') @UseGuards(AuthenticatedGuard) @UseInterceptors( @@ -114,7 +83,24 @@ export class UsersController { return await this.usersService.addAvatar(profile.id, file.filename) } - @Get(':id/avatar') + @Get('avatar') + @UseGuards(AuthenticatedGuard) + async getAvatar ( + @FtUser() profile: Profile, + @Res({ passthrough: true }) response: Response + ){ + const user = await this.usersService.findUser(profile.id) + if (!user) return + const filename = user.avatar + const stream = createReadStream(join(process.cwd(), 'avatars/' + filename)) + response.set({ + 'Content-Diposition': `inline; filename="${filename}"`, + 'Content-Type': 'image/jpg' + }) + return new StreamableFile(stream) + } + + @Get('avatar/:id') async getAvatarById ( @Param('id', ParseIntPipe) ftId: number, @Res({ passthrough: true }) response: Response @@ -130,11 +116,25 @@ export class UsersController { return new StreamableFile(stream) } - @Get('avatar') - async getAvatar ( - @FtUser() profile: Profile, - @Res({ passthrough: true }) response: Response - ) { - return await this.getAvatarById(profile.id, response); + @Get(':id') + async getUserById (@Param('id', ParseIntPipe) ftId: number): Promise { + return await this.usersService.findUser(ftId) + } + + @Get() + @UseGuards(AuthenticatedGuard) + async getUser (@FtUser() profile: Profile): Promise { + return await this.usersService.findUser(profile.id) + } + + @Post() + @UseGuards(AuthenticatedGuard) + async create (@Body() payload: UserDto, @FtUser() profile: Profile) { + const user = await this.usersService.findUser(profile.id) + if (user) { + return await this.usersService.update(user.id, payload) + } else { + return await this.usersService.create(payload) + } } } diff --git a/front/volume/src/components/Chat2.svelte b/front/volume/src/components/Chat2.svelte index 974d97b..4ebf96a 100644 --- a/front/volume/src/components/Chat2.svelte +++ b/front/volume/src/components/Chat2.svelte @@ -15,8 +15,12 @@ name: "You", text: newText, }; - chatMessages = [...chatMessages.slice(-7 + 1), newMessage]; + chatMessages = [...chatMessages.slice(-5 + 1), newMessage]; newText = ""; + const messagesDiv = document.querySelector(".messages"); + if (messagesDiv) { + messagesDiv.scrollTop = messagesDiv.scrollHeight; + } } // TODO: save to database }; @@ -24,18 +28,25 @@ export let chatMessages: Array = []; let newText = ""; - // const openProfile = (id: number) => (event: Event) => { - // const message = chatMessages.find((m) => m.id === id); - // if (message) { - // const { name } = message; - // const options = ["View profile", "Send private message", "Block user"]; - // const option = prompt(`Select an option for ${name}: ${options.join(", ")}`); - // if (option === "View profile") { - // } else if (option === "Send private message") { - // } else if (option === "Block user") { - // } - // } - // }; + const openProfile = (id: number) => (event: Event) => { + const message = chatMessages.find((m) => m.id === id); + if (message) { + const optionsModal = document.createElement("div"); + optionsModal.classList.add("options-modal"); + optionsModal.innerHTML = ` +

${message.name}

+
    +
  • View profile
  • +
  • View posts
  • +
  • View comments
  • +
+ `; + document.querySelector('.overlay')?.appendChild(optionsModal); + optionsModal.addEventListener("click", () => { + document.body.removeChild(optionsModal); + }); + } + };
@@ -43,7 +54,7 @@
{#each chatMessages as message}

- + {message.name} : {message.text}

@@ -79,4 +90,20 @@ padding: 1rem; width: 300px; } + + .messages { + height: 200px; + overflow-y: scroll; + } + + .options-modal { + position: absolute; + top: 0; + left: 0; + background-color: white; + padding: 1rem; + border: 1px solid #ccc; + border-radius: 5px; + z-index: 9999; + } diff --git a/front/volume/src/components/Profile.svelte b/front/volume/src/components/Profile.svelte index 3e015de..1702e84 100644 --- a/front/volume/src/components/Profile.svelte +++ b/front/volume/src/components/Profile.svelte @@ -1,4 +1,5 @@