|
@ -1,4 +1,4 @@ |
|
|
import { Injectable, NotFoundException } from '@nestjs/common' |
|
|
import { BadRequestException, Injectable } from '@nestjs/common' |
|
|
import { InjectRepository } from '@nestjs/typeorm' |
|
|
import { InjectRepository } from '@nestjs/typeorm' |
|
|
import { Repository } from 'typeorm' |
|
|
import { Repository } from 'typeorm' |
|
|
|
|
|
|
|
@ -20,7 +20,7 @@ export class ChatService { |
|
|
async createChannel (channel: CreateChannelDto): Promise<Channel> { |
|
|
async createChannel (channel: CreateChannelDto): Promise<Channel> { |
|
|
const user: User | null = await this.usersService.findUser(channel.owner) |
|
|
const user: User | null = await this.usersService.findUser(channel.owner) |
|
|
if (user == null) { |
|
|
if (user == null) { |
|
|
throw new NotFoundException(`User #${channel.owner} not found`) |
|
|
throw new BadRequestException(`User #${channel.owner} not found`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let newChannel: Channel |
|
|
let newChannel: Channel |
|
@ -29,10 +29,13 @@ export class ChatService { |
|
|
channel.otherDMedUsername |
|
|
channel.otherDMedUsername |
|
|
) |
|
|
) |
|
|
if (otherUser == null) { |
|
|
if (otherUser == null) { |
|
|
throw new NotFoundException( |
|
|
throw new BadRequestException( |
|
|
`User #${channel.otherDMedUsername} not found` |
|
|
`User #${channel.otherDMedUsername} not found` |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
if (otherUser.id === user.id) { |
|
|
|
|
|
throw new BadRequestException('Cannot DM yourself') |
|
|
|
|
|
} |
|
|
newChannel = this.createDM(user, otherUser) |
|
|
newChannel = this.createDM(user, otherUser) |
|
|
} else { |
|
|
} else { |
|
|
newChannel = new Channel() |
|
|
newChannel = new Channel() |
|
@ -50,13 +53,10 @@ export class ChatService { |
|
|
const newDM = new Channel() |
|
|
const newDM = new Channel() |
|
|
newDM.isPrivate = true |
|
|
newDM.isPrivate = true |
|
|
newDM.password = '' |
|
|
newDM.password = '' |
|
|
|
|
|
|
|
|
newDM.owner = user |
|
|
newDM.owner = user |
|
|
newDM.users = [user, otherUser] |
|
|
newDM.users = [user, otherUser] |
|
|
newDM.admins = [] |
|
|
newDM.admins = [] |
|
|
newDM.name = user.username + ' & ' + otherUser.username |
|
|
newDM.name = user.username + '&' + otherUser.username |
|
|
newDM.isPrivate = true |
|
|
|
|
|
newDM.password = '' |
|
|
|
|
|
return newDM |
|
|
return newDM |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ export class ChatService { |
|
|
id |
|
|
id |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
channel.password = password |
|
|
channel.password = password |
|
|
await this.ChannelRepository.save(channel) |
|
|
await this.ChannelRepository.save(channel) |
|
@ -110,7 +110,7 @@ export class ChatService { |
|
|
async getChannel (id: number): Promise<Channel> { |
|
|
async getChannel (id: number): Promise<Channel> { |
|
|
const channel = await this.ChannelRepository.findOneBy({ id }) |
|
|
const channel = await this.ChannelRepository.findOneBy({ id }) |
|
|
if (channel == null) { |
|
|
if (channel == null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel |
|
|
return channel |
|
|
} |
|
|
} |
|
@ -122,7 +122,7 @@ export class ChatService { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (channel == null) { |
|
|
if (channel == null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel |
|
|
return channel |
|
|
} |
|
|
} |
|
@ -145,7 +145,7 @@ export class ChatService { |
|
|
relations: { owner: true } |
|
|
relations: { owner: true } |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel.owner.ftId === userId |
|
|
return channel.owner.ftId === userId |
|
|
} |
|
|
} |
|
@ -156,7 +156,7 @@ export class ChatService { |
|
|
relations: { admins: true } |
|
|
relations: { admins: true } |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel.admins.findIndex((user) => user.ftId === userId) !== -1 |
|
|
return channel.admins.findIndex((user) => user.ftId === userId) !== -1 |
|
|
} |
|
|
} |
|
@ -167,7 +167,7 @@ export class ChatService { |
|
|
relations: { users: true } |
|
|
relations: { users: true } |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel.users.findIndex((user) => user.ftId === userId) !== -1 |
|
|
return channel.users.findIndex((user) => user.ftId === userId) !== -1 |
|
|
} |
|
|
} |
|
@ -178,7 +178,7 @@ export class ChatService { |
|
|
relations: { banned: true } |
|
|
relations: { banned: true } |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
return channel.banned.findIndex((user) => user.ftId === userId) !== -1 |
|
|
return channel.banned.findIndex((user) => user.ftId === userId) !== -1 |
|
|
} |
|
|
} |
|
@ -188,7 +188,7 @@ export class ChatService { |
|
|
where: { id } |
|
|
where: { id } |
|
|
}) |
|
|
}) |
|
|
if (channel === null) { |
|
|
if (channel === null) { |
|
|
throw new NotFoundException(`Channel #${id} not found`) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const mutation: number[] | undefined = channel.muted.find( |
|
|
const mutation: number[] | undefined = channel.muted.find( |
|
|