will not show direct rooms if blocked
This commit is contained in:
@@ -52,8 +52,22 @@ export class ChatController {
|
|||||||
|
|
||||||
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
||||||
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
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);
|
let new_room = this.format_room(room);
|
||||||
if (room.protection)
|
if (room.protection)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
socket.username = socket.handshake.query.username.toString();
|
socket.username = socket.handshake.query.username.toString();
|
||||||
this.sockets.set(socket.username, socket);
|
this.sockets.set(socket.username, socket);
|
||||||
|
|
||||||
printCaller("socket.username:", socket.username);
|
printCaller("--- socket.username:", socket.username);
|
||||||
|
|
||||||
let not_emit: string = `${socket.username}_not_emit`;
|
let not_emit: string = `${socket.username}_not_emit`;
|
||||||
socket.join(not_emit);
|
socket.join(not_emit);
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export async function remove_block_user(username: string): Promise<void>
|
|||||||
await fetch_chat_request('unblock', FetchMethod.POST, {username: username} );
|
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");
|
to_print("in list_block_user");
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`
|
|||||||
|
|
||||||
export async function init_socket()
|
export async function init_socket()
|
||||||
{
|
{
|
||||||
|
to_print("in init_socket");
|
||||||
|
console.log("here");
|
||||||
const response = await fetch(`${address}/api/v2/user`);
|
const response = await fetch(`${address}/api/v2/user`);
|
||||||
const response_data = await response.json();
|
const response_data = await response.json();
|
||||||
|
to_print("-- response_data:", response_data);
|
||||||
|
|
||||||
set_user(response_data);
|
set_user(response_data);
|
||||||
|
|
||||||
@@ -19,6 +22,7 @@ export async function init_socket()
|
|||||||
username: response_data.username,
|
username: response_data.username,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log("horo");
|
||||||
set_socket(socket);
|
set_socket(socket);
|
||||||
|
|
||||||
socket_states(socket);
|
socket_states(socket);
|
||||||
|
|||||||
Reference in New Issue
Block a user