Browse Source

* Pong wall fix

* Fixed DMs
* MAny other fixes
master
Walid Bekkal 2 years ago
parent
commit
01587f06c8
  1. 5
      back/volume/src/auth/auth.controller.ts
  2. 2
      back/volume/src/auth/mails/confirm.hbs
  3. 23
      back/volume/src/chat/chat.controller.ts
  4. 2
      back/volume/src/chat/entity/channel.entity.ts
  5. 2
      back/volume/src/chat/entity/message.entity.ts
  6. 2
      back/volume/src/pong/game/constants.ts
  7. 23
      docker-compose.yml
  8. 35
      front/volume/src/App.svelte
  9. 14
      front/volume/src/components/Channels.svelte
  10. 2
      front/volume/src/components/Chat.svelte
  11. 2
      front/volume/src/components/Pong/constants.ts

5
back/volume/src/auth/auth.controller.ts

@ -6,7 +6,8 @@ import {
Res, Res,
Req, Req,
Post, Post,
Body Body,
BadRequestException
} from '@nestjs/common' } from '@nestjs/common'
import { Response, Request } from 'express' import { Response, Request } from 'express'
@ -54,7 +55,7 @@ export class AuthController {
async VerifyEmail (@Profile42() profile: Profile): Promise<void> { async VerifyEmail (@Profile42() profile: Profile): Promise<void> {
const ftId: number = profile.id const ftId: number = profile.id
const user = await this.usersService.findUser(ftId) const user = await this.usersService.findUser(ftId)
if (user == null) throw new Error('User not found') if (user == null) throw new BadRequestException('User not found')
await this.authService.sendConfirmationEmail(user) await this.authService.sendConfirmationEmail(user)
} }

2
back/volume/src/auth/mails/confirm.hbs

@ -8,7 +8,7 @@
<body> <body>
<h2>Hello {{username}}! </h2> <h2>Hello {{username}}! </h2>
<p> Once you clicked on the next verify button, you will have access to the app</p> <p> Once you clicked on the next verify button, you will have access to the app</p>
<form action="http://localhost:3001/log/verify" method="post"> <form action="http://c4r2p1:3001/log/verify" method="post">
<button type="submit" name="code" value={{code}}>Verify</button> <button type="submit" name="code" value={{code}}>Verify</button>
</form> </form>
</body> </body>

23
back/volume/src/chat/chat.controller.ts

@ -35,11 +35,11 @@ export class ChatController {
@Profile42() profile: Profile, @Profile42() profile: Profile,
@Param('otherName') otherName: string @Param('otherName') otherName: string
): Promise<Channel[]> { ): Promise<Channel[]> {
const user = await this.usersService.findUser(profile.fdId) const user = await this.usersService.findUser(+profile.id)
const other = await this.usersService.findUserByName(otherName) const other = await this.usersService.findUserByName(otherName)
const channels = await this.channelService.getChannelsForUser(+profile.id) const channels = await this.channelService.getChannelsForUser(+profile.id)
if (user === null) { if (user === null || other === null) {
throw new BadRequestException('User not found') throw new BadRequestException('User not found')
} }
const dms = channels.filter((channel: Channel) => { const dms = channels.filter((channel: Channel) => {
@ -50,10 +50,19 @@ export class ChatController {
(channel.password === undefined || channel.password === '') (channel.password === undefined || channel.password === '')
) )
}) })
dms.forEach((c) => { if (dms && dms.length === 0) {
c.users.forEach((u) => (u.socketKey = '')) throw new BadRequestException('No DMS found')
c.admins.forEach((u) => (u.socketKey = '')) }
c.owner.socketKey = '' dms.forEach((c) => {
if (c.users) {
c.users.forEach((u) => (u.socketKey = ''))
}
if (c.admins) {
c.admins.forEach((u) => (u.socketKey = ''))
}
if (c.owner) {
c.owner.socketKey = ''
}
}) })
return dms return dms
} }
@ -65,7 +74,7 @@ export class ChatController {
@Profile42() profile: Profile @Profile42() profile: Profile
): Promise<void> { ): Promise<void> {
const channel = await this.channelService.getFullChannel(id) const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(target.id) const user: User | null = await this.usersService.getFullUser(target.id)
if (user == null) { if (user == null) {
throw new NotFoundException(`User #${target.id} not found`) throw new NotFoundException(`User #${target.id} not found`)
} }

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

@ -40,7 +40,7 @@ export default class Channel {
@JoinTable() @JoinTable()
users: User[] users: User[]
@OneToMany(() => Message, (message: Message) => message.channel) @OneToMany(() => Message, (message: Message) => message.channel, {onDelete:'CASCADE'})
messages: Message[] messages: Message[]
@ManyToOne(() => User) @ManyToOne(() => User)

2
back/volume/src/chat/entity/message.entity.ts

@ -22,7 +22,7 @@ export default class Message {
@JoinColumn() @JoinColumn()
author: User author: User
@ManyToOne(() => Channel, (channel) => channel.messages, { cascade: true }) @ManyToOne(() => Channel, (channel) => channel.messages, {onDelete:'CASCADE'} )
@JoinTable() @JoinTable()
channel: Channel channel: Channel

2
back/volume/src/pong/game/constants.ts

@ -16,7 +16,7 @@ export const DEFAULT_MAP_SIZE = new Point(500, 400)
export const DEFAULT_PADDLE_SIZE = new Point(30, 50) export const DEFAULT_PADDLE_SIZE = new Point(30, 50)
export const DEFAULT_BALL_SIZE = new Point(10, 10) export const DEFAULT_BALL_SIZE = new Point(10, 10)
export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2) export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2)
export const DEFAULT_MAX_BALL_SPEED = new Point(30, 20) export const DEFAULT_MAX_BALL_SPEED = new Point(20, 20)
export const DEFAULT_BALL_SPEED_INCREMENT = new Point(0.05, 0) export const DEFAULT_BALL_SPEED_INCREMENT = new Point(0.05, 0)
export const DEFAULT_WIN_SCORE = 5 export const DEFAULT_WIN_SCORE = 5
export const GAME_TICKS = 30 export const GAME_TICKS = 30

23
docker-compose.yml

@ -1,4 +1,4 @@
version: '3.8' version: "3.8"
networks: networks:
transcendence: transcendence:
@ -31,26 +31,7 @@ services:
image: postgres image: postgres
ports: [5432:5432] ports: [5432:5432]
volumes: volumes:
- ./postgres:/var/lib/postgresql/data - ./postgres:/var/lib/postgresql/data
networks: [transcendence] networks: [transcendence]
restart: always restart: always
env_file: .env env_file: .env
pgadmin:
links:
- postgres:postgres
container_name: pgadmin
image: dpage/pgadmin4
ports:
- "8081:80"
volumes:
- /data/pgadmin:/root/.pgadmin
environment:
PGADMIN_DEFAULT_EMAIL: 'usr@usr.com'
PGADMIN_DEFAULT_PASSWORD: 'pw'
GUNICORN_ACCESS_LOGFILE: '/dev/null'
PGADMIN_CONFIG_UPGRADE_CHECK_ENABLED: 'False'
depends_on:
- postgres
networks: [transcendence]
logging:
driver: none

35
front/volume/src/App.svelte

@ -93,25 +93,27 @@
setAppState(APPSTATE.PROFILE_ID); setAppState(APPSTATE.PROFILE_ID);
} }
async function getDMs(username: string): Promise<Response> { async function getDMs(username: string): Promise<Response | null> {
const response = await fetch(API_URL + "/channels/dms/" + username, { const res = await fetch(API_URL + "/channels/dms/" + username, {
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
}); })
return response; if (res.ok)
return res;
else
return null;
} }
let chan: Channels; let chan: Channels;
async function openDirectChat(event: CustomEvent<string>) { async function openDirectChat(event: CustomEvent<string>) {
const DMUsername = "test"; const DMUsername = event.detail;
// const DMUsername = event.detail;
let DMChannel: Array<ChannelsType> = []; let DMChannel: Array<ChannelsType> = [];
const res = await getDMs($store.username) const res = await getDMs(DMUsername)
if (res.ok) { if (res && res.ok) {
DMChannel = await res.json(); DMChannel = await res.json();
if (DMChannel.length != 0) { if (DMChannel.length != 0)
chan.selectChat(DMChannel[0].id); chan.selectChat(DMChannel[0].id);
} else { } else {
console.log("Creating DMChannel: " + $store.username + "&" + DMUsername) console.log("Creating DMChannel: " + $store.username + "&" + DMUsername)
fetch(API_URL + "/channels", { fetch(API_URL + "/channels", {
credentials: "include", credentials: "include",
@ -129,8 +131,8 @@
otherDMedUsername: DMUsername otherDMedUsername: DMUsername
}), }),
}).then(async () => { }).then(async () => {
const response = await getDMs($store.username) const response = await getDMs(DMUsername)
if (response.ok) { if (response && response.ok) {
DMChannel = await response.json(); DMChannel = await response.json();
if (DMChannel.length != 0) { if (DMChannel.length != 0) {
chan.selectChat(DMChannel[0].id); chan.selectChat(DMChannel[0].id);
@ -141,13 +143,10 @@
alert("Error creating DM"); alert("Error creating DM");
} }
}).catch((error) => { }).catch((error) => {
alert(error.message); alert("Error creating DM");
}) })
} }
} else {
alert("Error creating DM");
} }
}
async function clickHistory() { async function clickHistory() {
setAppState(APPSTATE.HISTORY); setAppState(APPSTATE.HISTORY);

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

@ -54,7 +54,7 @@
</script> </script>
<script lang="ts"> <script lang="ts">
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------//
let channelMode = ""; let channelMode = "";
const channelOptions = ["public", "private", "protected"]; const channelOptions = ["public", "private", "protected"];
@ -99,9 +99,13 @@
}; };
const createChannel = async () => { const createChannel = async () => {
let name; let name: string;
let password = ""; let password = "";
name = prompt("Enter a name for the new channel:"); name = prompt("Enter a name for the new channel:");
if (name.includes("#")) {
alert("Channel name cannot contain #");
return;
}
if (name) { if (name) {
if (channelMode === 'protected') if (channelMode === 'protected')
password = prompt("Enter a password for the new channel:"); password = prompt("Enter a password for the new channel:");
@ -163,7 +167,7 @@
}), }),
}); });
if (response2.ok) { if (response2.ok) {
channels.push(await response2.json()); alert("User invited");
} else { } else {
alert("Error inviting user"); alert("Error inviting user");
} }
@ -203,7 +207,7 @@
<div class="channels" on:click|stopPropagation on:keydown|stopPropagation> <div class="channels" on:click|stopPropagation on:keydown|stopPropagation>
<div> <div>
{#if channels.length > 0} {#if channels.length > 0}
<h2>Channels</h2> <h2>Channels <button style="margin-right :auto;" on:click={() => getChannels()}>🔄</button> </h2>
{#each channels.slice(0, 10) as channel} {#each channels.slice(0, 10) as channel}
<li> <li>
<span>{channel.name}</span> <span>{channel.name}</span>
@ -213,7 +217,7 @@
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 == false} {#if channel.isPrivate == true}
<button on:click={() => inviteChannel(channel.id)}>🤝</button> <button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if} {/if}
<button on:click={() => changePassword(channel.id)}>🔑</button> <button on:click={() => changePassword(channel.id)}>🔑</button>

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

@ -24,7 +24,7 @@
getMembers(); getMembers();
usersInterval = setInterval(async () => { usersInterval = setInterval(async () => {
getMembers(); getMembers();
}, 3000); }, 1000);
}); });
socket.on("messages", (msgs: Array<chatMessagesType>) => { socket.on("messages", (msgs: Array<chatMessagesType>) => {

2
front/volume/src/components/Pong/constants.ts

@ -16,7 +16,7 @@ export const DEFAULT_MAP_SIZE = new Point(500, 400);
export const DEFAULT_PADDLE_SIZE = new Point(30, 50); export const DEFAULT_PADDLE_SIZE = new Point(30, 50);
export const DEFAULT_BALL_SIZE = new Point(10, 10); export const DEFAULT_BALL_SIZE = new Point(10, 10);
export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2); export const DEFAULT_BALL_INITIAL_SPEED = new Point(10, 2);
export const DEFAULT_MAX_BALL_SPEED = new Point(30, 20); export const DEFAULT_MAX_BALL_SPEED = new Point(20, 20);
export const DEFAULT_BALL_SPEED_INCREMENT = new Point(0.05, 0); export const DEFAULT_BALL_SPEED_INCREMENT = new Point(0.05, 0);
export const DEFAULT_WIN_SCORE = 5; export const DEFAULT_WIN_SCORE = 5;
export const GAME_TICKS = 30; export const GAME_TICKS = 30;

Loading…
Cancel
Save