merge
This commit is contained in:
@ -2,6 +2,7 @@ import {Client} from './Client.js';
|
||||
import {createNotification} from '../utils/noticeUtils.js'
|
||||
import { lastView } from '../index.js';
|
||||
import ProfilePageView from '../views/ProfilePageView.js';
|
||||
import Search from '../views/Search.js';
|
||||
|
||||
export default class Notice {
|
||||
|
||||
@ -22,7 +23,7 @@ export default class Notice {
|
||||
this._socket.onclose = _ => this._socket = undefined;
|
||||
this._socket.onmessage = message => {
|
||||
const data = JSON.parse(message.data);
|
||||
console.log(data)
|
||||
//console.log(data)
|
||||
|
||||
if (data.type === 'friend_request') {
|
||||
this.friend_request(data.author);
|
||||
@ -52,6 +53,9 @@ export default class Notice {
|
||||
lastView.profile.online = status;
|
||||
lastView.loadFriendshipStatus();
|
||||
}
|
||||
else if (lastView instanceof Search) {
|
||||
lastView.display_specific_user(user.id);
|
||||
}
|
||||
}
|
||||
|
||||
online(user) {
|
||||
|
@ -18,8 +18,6 @@ export default class extends AbstractView {
|
||||
|
||||
const games = await this.profile.getGameHistory();
|
||||
|
||||
console.log(games)
|
||||
|
||||
await this.fillHistory(games);
|
||||
await this.fillStatistics(games);
|
||||
|
||||
@ -80,10 +78,10 @@ export default class extends AbstractView {
|
||||
*/
|
||||
async fillStatistics(games)
|
||||
{
|
||||
const winrateDiv = document.getElementById("winrate");
|
||||
let winrateDiv = document.getElementById("winrate");
|
||||
|
||||
const win = 0;
|
||||
const lose = 0;
|
||||
let win = 0;
|
||||
let lose = 0;
|
||||
|
||||
games.forEach(game => {
|
||||
if (game.finished === false)
|
||||
@ -100,7 +98,7 @@ export default class extends AbstractView {
|
||||
|
||||
async fillHistory(games)
|
||||
{
|
||||
const game_list = document.getElementById("game-list");
|
||||
let game_list = document.getElementById("game-list");
|
||||
|
||||
games.forEach(game => {
|
||||
|
||||
|
@ -9,30 +9,30 @@ export default class extends AbstractView {
|
||||
|
||||
async postInit() {
|
||||
|
||||
let logged = await client.isAuthenticated();
|
||||
let profiles = await client.profiles.all();
|
||||
this.logged = await client.isAuthenticated();
|
||||
this.profiles = await client.profiles.all();
|
||||
|
||||
let search = document.getElementById("input_user");
|
||||
if (search != undefined)
|
||||
search.oninput = () => this.display_users(logged, profiles);
|
||||
search.oninput = () => this.display_users();
|
||||
|
||||
let chat_input = document.getElementById("input_chat");
|
||||
|
||||
this.last_add_chat = undefined;
|
||||
|
||||
this.display_users(logged, profiles);
|
||||
this.display_chat(logged, profiles);
|
||||
this.display_users();
|
||||
this.display_chat();
|
||||
|
||||
}
|
||||
|
||||
async display_users(logged, profiles) {
|
||||
async display_users() {
|
||||
|
||||
let search = document.getElementById("input_user").value.toLowerCase();
|
||||
|
||||
let list_users = document.getElementById('list_users');
|
||||
list_users.innerHTML = "";
|
||||
|
||||
profiles.filter(user => user.username.toLowerCase().startsWith(search) == true).forEach(async (user) => {
|
||||
this.profiles.filter(user => user.username.toLowerCase().startsWith(search) == true).forEach(async (user) => {
|
||||
|
||||
if (user.id == null) {
|
||||
console.log("list User one with id null;");
|
||||
@ -46,14 +46,14 @@ export default class extends AbstractView {
|
||||
username.setAttribute('data-link', '');
|
||||
username.id = `username${user.id}`;
|
||||
username.href = `/profiles/${user.username}`;
|
||||
if (logged && user.id == client.me.id)
|
||||
if (this.logged && user.id == client.me.id)
|
||||
username.style.color = "green";
|
||||
else {
|
||||
let profile = await client.profiles.getProfileId(user.id);
|
||||
let online = profile.online;
|
||||
if (online == undefined)
|
||||
username.style.color = "gray";
|
||||
if (online == true)
|
||||
else if (online == true)
|
||||
username.style.color = "green";
|
||||
else
|
||||
username.style.color = "red";
|
||||
@ -65,7 +65,7 @@ export default class extends AbstractView {
|
||||
new_user.appendChild(document.createTextNode(" "));
|
||||
|
||||
// button chat
|
||||
if (logged && client.me.id != user.id) {
|
||||
if (this.logged && client.me.id != user.id) {
|
||||
let add_chat = document.createElement("a");
|
||||
add_chat.id = "add_chat_off";
|
||||
add_chat.onclick = async () => {
|
||||
@ -86,7 +86,7 @@ export default class extends AbstractView {
|
||||
await client.channels.channel.disconnect();
|
||||
}
|
||||
client.channels.channel = await client.channels.createChannel([client.me.id , user.id], () => this.reload_display_messages());
|
||||
this.display_chat(logged, profiles);
|
||||
this.display_chat();
|
||||
if (this.last_add_chat != undefined)
|
||||
this.last_add_chat.id = "add_chat_off";
|
||||
this.last_add_chat = add_chat;
|
||||
@ -113,7 +113,27 @@ export default class extends AbstractView {
|
||||
|
||||
}
|
||||
|
||||
async display_chat(logged, profiles)
|
||||
async display_specific_user(id) {
|
||||
|
||||
let user = document.getElementById("username" + id);
|
||||
if (user == undefined)
|
||||
return ;
|
||||
|
||||
if (this.logged && id == client.me.id)
|
||||
user.style.color = "green";
|
||||
else {
|
||||
let profile = await client.profiles.getProfileId(id);
|
||||
let online = profile.online;
|
||||
if (online == undefined)
|
||||
user.style.color = "gray";
|
||||
else if (online == true)
|
||||
user.style.color = "green";
|
||||
else
|
||||
user.style.color = "red";
|
||||
}
|
||||
}
|
||||
|
||||
async display_chat()
|
||||
{
|
||||
let reloads = ["members", "messages"];
|
||||
reloads.forEach(reload => {
|
||||
@ -121,7 +141,7 @@ export default class extends AbstractView {
|
||||
document.getElementById(reload).remove();
|
||||
});
|
||||
|
||||
if (client.channels.channel === undefined || logged === false)
|
||||
if (client.channels.channel === undefined || this.logged === false)
|
||||
return ;
|
||||
|
||||
let chats = document.getElementById("chats");
|
||||
@ -133,7 +153,7 @@ export default class extends AbstractView {
|
||||
}
|
||||
|
||||
// nom des membres du channel
|
||||
let members = await this.display_members(chat, profiles);
|
||||
let members = await this.display_members(chat);
|
||||
|
||||
// L'affiche des messages
|
||||
let messages = await this.display_messages(chat);
|
||||
@ -157,7 +177,7 @@ export default class extends AbstractView {
|
||||
let receivers_id = [];
|
||||
members_id.forEach((member_id) => {
|
||||
if (member_id != client.me.id)
|
||||
receivers_id.push(profiles.filter(user => user.id == member_id)[0].id);
|
||||
receivers_id.push(this.profiles.filter(user => user.id == member_id)[0].id);
|
||||
});
|
||||
await client.channels.channel.sendMessageChannel(chat_text, receivers_id);
|
||||
// Reset
|
||||
@ -215,7 +235,7 @@ export default class extends AbstractView {
|
||||
messages.scrollTop = messages.scrollHeight;
|
||||
}
|
||||
|
||||
async display_members(chat, profiles) {
|
||||
async display_members(chat) {
|
||||
|
||||
let members_id = client.channels.channel.members_id;
|
||||
|
||||
@ -226,7 +246,7 @@ export default class extends AbstractView {
|
||||
if (member_id != client.me.id) {
|
||||
if (usernames.length > 0)
|
||||
usernames += ", ";
|
||||
usernames += (profiles.filter(user => user.id == member_id)[0].username);
|
||||
usernames += (this.profiles.filter(user => user.id == member_id)[0].username);
|
||||
}
|
||||
});
|
||||
members.textContent = usernames;
|
||||
@ -251,11 +271,6 @@ export default class extends AbstractView {
|
||||
let no = document.getElementById("no") || document.createElement("button");
|
||||
|
||||
let invitedBy;
|
||||
for (let x in others) {
|
||||
if (client.notice.data.invited.includes(others[x])) {
|
||||
invitedBy = others[x];
|
||||
}
|
||||
}
|
||||
|
||||
if (invitedBy == undefined) {
|
||||
|
||||
|
Reference in New Issue
Block a user