Browse Source

* DM FIx

master
vvandenb 2 years ago
committed by nicolas-arnaud
parent
commit
6cda3eaa32
  1. 8
      back/volume/src/chat/chat.controller.ts
  2. 6
      back/volume/src/chat/chat.service.ts
  3. 3
      back/volume/src/chat/entity/channel.entity.ts
  4. 7
      front/volume/src/components/Channels.svelte

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

@ -45,9 +45,7 @@ export class ChatController {
const dms = channels.filter((channel: Channel) => {
return (
(channel.name === `${user.ftId}&${other.ftId}` ||
channel.name === `${other.ftId}&${user.ftId}`) &&
(channel.password === undefined || channel.password === '') &&
channel.isPrivate
channel.name === `${other.ftId}&${user.ftId}`)
)
})
if (dms.length === 0) {
@ -67,9 +65,6 @@ export class ChatController {
if (user == null) {
throw new NotFoundException(`User #${target.id} not found`)
}
if (channel.isPrivate && channel.password === '') {
throw new BadRequestException('You cannot add more users to a DM')
}
if (!(await this.channelService.isUser(channel.id, +profile.id))) {
throw new BadRequestException(
'You are not allowed to invite users to this channel'
@ -213,6 +208,7 @@ export class ChatController {
throw new BadRequestException('You are not the owner of this channel')
}
let channel = (await this.channelService.getChannel(id)) as Channel
if (channel.isDM) throw new BadRequestException('You cannot set a password on a DM channel')
channel.password = await this.channelService.hash(data.password)
this.channelService.update(channel)
}

6
back/volume/src/chat/chat.service.ts

@ -42,9 +42,7 @@ export class ChatService {
const dmAlreadyExists = channels.find((channel: Channel) => {
return (
(channel.name === `${user.ftId}&${otherUser.ftId}` ||
channel.name === `${otherUser.ftId}&${user.ftId}`) &&
(channel.password === undefined || channel.password === '') &&
channel.isPrivate
channel.name === `${otherUser.ftId}&${user.ftId}`)
)
})
if (dmAlreadyExists !== undefined) {
@ -60,6 +58,7 @@ export class ChatService {
newChannel.name = channel.name
newChannel.isPrivate = channel.isPrivate
newChannel.password = await this.hash(channel.password)
newChannel.isDM = false
console.log("New channel: ", JSON.stringify(newChannel))
}
return await this.ChannelRepository.save(newChannel)
@ -73,6 +72,7 @@ export class ChatService {
newDM.users = [user, otherUser]
newDM.admins = []
newDM.name = `${user.ftId}&${otherUser.ftId}`
newDM.isDM = true
return newDM
}

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

@ -46,4 +46,7 @@ export default class Channel {
@Column('text', { array: true, default: [] })
muted: number[][]
@Column({ default: false })
isDM: boolean
}

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

@ -9,6 +9,7 @@
owner: User;
banned: Array<User>;
muted: Array<User>;
isDM: boolean;
}
export interface chatMessagesType {
id: number;
@ -229,10 +230,12 @@
on:click={() => removeChannel(channel.id)}
on:keydown={() => removeChannel(channel.id)}>🗑️</button
>
{#if channel.isPrivate == true}
{#if channel.isPrivate == true && !channel.isDM}
<button on:click={() => inviteChannel(channel.id)}>🤝</button>
{/if}
<button on:click={() => changePassword(channel.id)}>🔑</button>
{#if !channel.isDM}
<button on:click={() => changePassword(channel.id)}>🔑</button>
{/if}
</div>
</li>
{/each}

Loading…
Cancel
Save