will not show direct rooms if blocked

This commit is contained in:
simplonco
2023-01-16 16:08:56 +01:00
parent 61864af0a3
commit 3cd9a0b52e
5 changed files with 33 additions and 16 deletions

View File

@@ -52,8 +52,22 @@ export class ChatController {
let fields = ["name", "type", "users", "protection", "allowed_users"];
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
const blocked = await this.chatService.getListBlockUser(req.user.username);
const ret_rooms = rooms.map(room =>
let filtered_rooms = rooms.filter(room =>
{
if (room.type === 'direct')
{
let roomname = room.users[0];
if (roomname === req.user.username)
roomname = room.users[1];
if (blocked.includes(roomname))
return false;
}
return true;
});
const ret_rooms = filtered_rooms.map(room =>
{
let new_room = this.format_room(room);
if (room.protection)

View File

@@ -28,7 +28,7 @@ implements OnGatewayConnection, OnGatewayDisconnect
socket.username = socket.handshake.query.username.toString();
this.sockets.set(socket.username, socket);
printCaller("socket.username:", socket.username);
printCaller("--- socket.username:", socket.username);
let not_emit: string = `${socket.username}_not_emit`;
socket.join(not_emit);

View File

@@ -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>