will not show users in rooms if blocked
This commit is contained in:
@@ -92,8 +92,19 @@ export class ChatController {
|
||||
printCaller("- in ");
|
||||
|
||||
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 });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@@ -306,26 +306,22 @@ export class ChatService {
|
||||
|
||||
async findOneRelationshipByUsername(friendUsername : string, username : string)
|
||||
{
|
||||
printCaller("-- in ");
|
||||
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||
.where
|
||||
(
|
||||
new Brackets((qb) =>
|
||||
{
|
||||
qb.where
|
||||
(
|
||||
new Brackets((subAQb) =>
|
||||
{
|
||||
.where (
|
||||
new Brackets((qb) => {
|
||||
qb.where (
|
||||
new Brackets((subAQb) => {
|
||||
subAQb.where('sender.username = :username', {username : username})
|
||||
.andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername})
|
||||
})
|
||||
)
|
||||
.orWhere
|
||||
(
|
||||
new Brackets((subBQb) =>
|
||||
{
|
||||
.orWhere (
|
||||
new Brackets((subBQb) => {
|
||||
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
|
||||
.andWhere('receiver.username = :username2', {username2 : username})
|
||||
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||
@@ -333,11 +329,14 @@ export class ChatService {
|
||||
)
|
||||
}),
|
||||
)
|
||||
.getOne()
|
||||
.getOne();
|
||||
|
||||
console.log("friendship:", friendship);
|
||||
if (!friendship)
|
||||
return null;
|
||||
return new SendableFriendship(friendship);
|
||||
|
||||
printCaller("-- out ");
|
||||
}
|
||||
|
||||
async addBlockUser(username: string, to_block_username: string): Promise<void>
|
||||
|
||||
Reference in New Issue
Block a user