ft_transcendence/frontend/static/js/api/profile.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-12-16 12:00:38 -05:00
import { Client } from "./client.js";
2023-12-06 09:19:41 -05:00
class Profile
{
2023-12-16 12:00:38 -05:00
/**
* @param {Client} client
*/
2023-12-08 11:36:41 -05:00
constructor (client, username = undefined, avatar_url = undefined, user_id = undefined)
2023-12-06 09:19:41 -05:00
{
2023-12-16 12:00:38 -05:00
/**
* @type {Client} client
*/
2023-12-06 09:19:41 -05:00
this.client = client;
2023-12-08 11:36:41 -05:00
this.username = username;
2023-12-20 17:48:52 -05:00
this.avatar_url = avatar_url;
this.user_id = user_id;
this.isBlocked = false;
2023-12-06 09:19:41 -05:00
}
2023-12-12 03:53:28 -05:00
async init(user_id)
2023-12-06 09:19:41 -05:00
{
2023-12-12 03:53:28 -05:00
let response = await this.client._get(`/api/profiles/${user_id}`);
2023-12-06 09:19:41 -05:00
let response_data = await response.json();
2023-12-18 15:41:00 -05:00
this.user_id = response_data.user_id;
2023-12-06 09:19:41 -05:00
this.username = response_data.username;
this.avatar_url = response_data.avatar_url;
2023-12-20 17:48:52 -05:00
let block_response = await this.client._get("/api/profiles/block");
if (block_response.status == 404)
return
let block_data = await block_response.json();
let block_list = JSON.parse(block_data);
block_list.forEach(block => {
let blocker = block.fields.blocker;
let blocked = block.fields.blocked;
if (blocker == this.client.me.user_id && blocked == user_id)
return this.isBlocked = true;
});
2023-12-06 09:19:41 -05:00
}
}
2023-12-20 17:48:52 -05:00
export {Profile}