will not show users in rooms if blocked

This commit is contained in:
simplonco
2023-01-16 16:46:04 +01:00
parent e52690d890
commit 8b508063e8
2 changed files with 24 additions and 14 deletions

View File

@@ -92,8 +92,19 @@ export class ChatController {
printCaller("- in "); printCaller("- in ");
const rooms: roomDto[] = await this.chatService.getAllOtherRoomsAndUsers(req.user.username) const rooms: roomDto[] = await this.chatService.getAllOtherRoomsAndUsers(req.user.username)
const blocked = await this.chatService.getListBlockUser(req.user.username);
const ret_rooms = rooms.map(room => this.format_room(room)); let filtered_rooms = rooms.filter(room =>
{
if (room.type === 'user')
{
if (blocked.includes(room.name))
return false;
}
return true;
});
const ret_rooms = filtered_rooms.map(room => this.format_room(room));
res.status(HttpStatus.OK).json({ rooms: ret_rooms }); res.status(HttpStatus.OK).json({ rooms: ret_rooms });
printCaller("- out "); printCaller("- out ");
} }

View File

@@ -306,26 +306,22 @@ export class ChatService {
async findOneRelationshipByUsername(friendUsername : string, username : string) async findOneRelationshipByUsername(friendUsername : string, username : string)
{ {
printCaller("-- in ");
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
.leftJoinAndSelect('friendship.receiver', 'receiver') .leftJoinAndSelect('friendship.receiver', 'receiver')
.where .where (
( new Brackets((qb) => {
new Brackets((qb) => qb.where (
{ new Brackets((subAQb) => {
qb.where
(
new Brackets((subAQb) =>
{
subAQb.where('sender.username = :username', {username : username}) subAQb.where('sender.username = :username', {username : username})
.andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername}) .andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername})
}) })
) )
.orWhere .orWhere (
( new Brackets((subBQb) => {
new Brackets((subBQb) =>
{
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername}) subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
.andWhere('receiver.username = :username2', {username2 : username}) .andWhere('receiver.username = :username2', {username2 : username})
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED}) .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
@@ -333,11 +329,14 @@ export class ChatService {
) )
}), }),
) )
.getOne() .getOne();
console.log("friendship:", friendship);
if (!friendship) if (!friendship)
return null; return null;
return new SendableFriendship(friendship); return new SendableFriendship(friendship);
printCaller("-- out ");
} }
async addBlockUser(username: string, to_block_username: string): Promise<void> async addBlockUser(username: string, to_block_username: string): Promise<void>