Start invitation; notification; add profile avatar in me
This commit is contained in:
@ -1,7 +1,16 @@
|
||||
import {create_popup} from "../../utils/noticeUtils.js";
|
||||
|
||||
class Notice {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.online_users = {};
|
||||
this.data = {};
|
||||
|
||||
// users online, invited by, asked friend by,
|
||||
let data_variable = ["online", "invited", "asked"];
|
||||
for (let i in data_variable) {
|
||||
this.data[data_variable[i]] = [];
|
||||
}
|
||||
|
||||
this.connect();
|
||||
|
||||
}
|
||||
@ -19,7 +28,6 @@ class Notice {
|
||||
this.receiveOnlineUser(data);
|
||||
}
|
||||
this.chatSocket.onopen = (event) => {
|
||||
this.online_users = {};
|
||||
this.getOnlineUser();
|
||||
}
|
||||
}
|
||||
@ -47,14 +55,22 @@ class Notice {
|
||||
async receiveInvite(data) {
|
||||
|
||||
if (data.content === "notice return") {
|
||||
if (data.status == 200)
|
||||
return
|
||||
// Notification pour dire que la notif a été bien envoyé
|
||||
if (data.status == 200) {
|
||||
for (let target in data.targets)
|
||||
this.data["invited"].push(target);
|
||||
return create_popup("Invitation send");
|
||||
}
|
||||
else if (data.status == 404)
|
||||
return
|
||||
// Pas connecté
|
||||
return create_popup("User not connected");
|
||||
else if (data.status == 409)
|
||||
return create_popup("Already invited");
|
||||
}
|
||||
else {
|
||||
let sender = await this.client.profiles.getProfile(data.author_id);
|
||||
|
||||
this.inviter.push(data.author_id);
|
||||
create_popup("Invitation received by " + sender.username);
|
||||
|
||||
// Géré la reception de l'invitation
|
||||
}
|
||||
}
|
||||
@ -75,7 +91,19 @@ class Notice {
|
||||
|
||||
async receiveOnlineUser(data) {
|
||||
if (data.content !== undefined) {
|
||||
this.online_users = data.content;
|
||||
|
||||
if (this.online_users.length > 0) {
|
||||
// get all disconnect user
|
||||
let disconnects = this.online_users.filter(id => !Object.keys(data.content).includes(id));
|
||||
|
||||
// delete invite
|
||||
this.data["invited"] = this.data["invited"].filter(id => !disconnects.includes(id));
|
||||
|
||||
//console.log(this.data["invited"]);
|
||||
}
|
||||
|
||||
this.data["online"] = Object.keys(data.content);
|
||||
|
||||
if (this.rewrite_usernames !== undefined)
|
||||
this.rewrite_usernames();
|
||||
}
|
||||
|
Reference in New Issue
Block a user