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>

View File

@@ -239,7 +239,7 @@ export async function remove_block_user(username: string): Promise<void>
await fetch_chat_request('unblock', FetchMethod.POST, {username: username} );
}
export async function list_block_user(username: string): Promise<string>
export async function list_block_user(username: string): Promise<string[]>
{
to_print("in list_block_user");

View File

@@ -6,8 +6,11 @@ const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`
export async function init_socket()
{
to_print("in init_socket");
console.log("here");
const response = await fetch(`${address}/api/v2/user`);
const response_data = await response.json();
to_print("-- response_data:", response_data);
set_user(response_data);
@@ -19,6 +22,7 @@ export async function init_socket()
username: response_data.username,
},
});
console.log("horo");
set_socket(socket);
socket_states(socket);