add block option

This commit is contained in:
2023-12-20 23:48:52 +01:00
parent 57ed6165ea
commit 4fd6616786
10 changed files with 154 additions and 44 deletions

View File

@ -54,13 +54,14 @@ class Channel {
return new_messages;
}
async sendMessageChannel(message) {
async sendMessageChannel(message, receivers_id) {
if (this.chatSocket == undefined)
return;
this.chatSocket.send(JSON.stringify({
'message':message
'message':message,
'receivers_id':receivers_id,
}));
}

View File

@ -35,10 +35,11 @@ class Client
return this.logged;
}
async _get(uri)
async _get(uri, data)
{
let response = await fetch(this._url + uri, {
method: "GET",
body: JSON.stringify(data),
});
return response;
}

View File

@ -12,8 +12,9 @@ class Profile
*/
this.client = client;
this.username = username;
this.avatar_url = avatar_url
this.user_id = user_id
this.avatar_url = avatar_url;
this.user_id = user_id;
this.isBlocked = false;
}
async init(user_id)
@ -24,7 +25,21 @@ class Profile
this.user_id = response_data.user_id;
this.username = response_data.username;
this.avatar_url = response_data.avatar_url;
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;
});
}
}
export {Profile}
export {Profile}

View File

@ -35,13 +35,30 @@ class Profiles
async block(user_id) {
// blocker & blocked
let response = await this.client._post("/api/block/",
[this.client.me.user_id, user_id],
);
let response = await this.client._post("/api/profiles/block", {
users_id:[this.client.me.user_id, user_id],
});
let data = await response.json();
console.log(response.status);
console.log(data);
return data;
}
async deblock(user_id) {
// blocker & blocked
let response = await this.client._delete("/api/profiles/block", {
users_id:[this.client.me.user_id, user_id],
});
let data = await response.json();
console.log(response.status);
console.log(data);
return data;
}
}
export {Profiles}