profiles(block): get profiles of blocked users

This commit is contained in:
AdrienLSH
2024-04-07 17:43:30 +02:00
parent 8912e39fa4
commit 80e7335c8d
4 changed files with 40 additions and 47 deletions

View File

@ -10,6 +10,22 @@ class MyProfile extends Profile
constructor (client)
{
super(client, "../me");
/**
* @type {[Profile]}
*/
this.blockedUsers = [];
}
async init() {
await super.init();
await this.getBlockedUsers();
}
async getBlockedUsers() {
const response = await this.client._get('/api/profiles/block');
const data = await response.json();
data.forEach(profileData => this.blockedUsers.push(new Profile(this.client, profileData.username, profileData.user_id, profileData.avatar)));
}
/**

View File

@ -57,9 +57,6 @@ export class Profile extends AExchangeable
this.username = response_data.username;
this.avatar = response_data.avatar;
await this.getBlock();
await this.getFriend();
}
/**
@ -79,42 +76,6 @@ export class Profile extends AExchangeable
return games;
}
async getBlock() {
let block_response = await this.client._get("/api/profiles/block");
if (block_response.status != 200)
return;
let block_data = await block_response.json();
let block_list = JSON.parse(block_data.blockeds);
let client_id = block_data.user_id;
block_list.forEach(block => {
let blocker = block.fields.blocker;
let blocked = block.fields.blocked;
if (blocker == client_id && blocked == this.id)
return (this.isBlocked = true);
});
}
async getFriend() {
let friend_response = await this.client._get("/api/profiles/friend");
this.isFriend = false;
if (friend_response.status != 200)
return this.isFriend;
let friend_data = await friend_response.json();
let friends_list = friend_data.friends;
let client_id = friend_data.user_id;
friends_list.forEach(friend => {
if (friend == this.id) {
this.isFriend = true;
return this.isFriend;
}
});
return this.isFriend;
}
/**
* @param {[String]} additionalFieldList
*/
@ -122,4 +83,4 @@ export class Profile extends AExchangeable
{
super.export([...["username", "avatar", "id"], ...additionalFieldList])
}
}
}