etienne apprend à coder pitié
This commit is contained in:
@ -1,9 +1,15 @@
|
||||
import { Account } from "./Account.js";
|
||||
import { MatchMaking } from "./Matchmaking.js";
|
||||
import { Profiles } from "./Profiles.js";
|
||||
import { Channels } from './chat/Channels.js';
|
||||
import { MyProfile } from "./MyProfile.js";
|
||||
<<<<<<< Updated upstream
|
||||
import { Channel } from "./chat/Channel.js";
|
||||
||||||| Stash base
|
||||
import { Tourmanents } from "./tournament/Tournaments.js";
|
||||
import { Channel } from "./chat/Channel.js";
|
||||
=======
|
||||
import { Tourmanents } from "./tournament/Tournaments.js";
|
||||
>>>>>>> Stashed changes
|
||||
import Notice from "./Notice.js";
|
||||
import LanguageManager from './LanguageManager.js';
|
||||
|
||||
@ -50,16 +56,6 @@ class Client
|
||||
*/
|
||||
this._logged = undefined;
|
||||
|
||||
/**
|
||||
* @type {Channels}
|
||||
*/
|
||||
this.channels = new Channels(this);
|
||||
|
||||
/**
|
||||
* @type {Channel}
|
||||
*/
|
||||
this.channel = undefined;
|
||||
|
||||
/**
|
||||
* @type {Notice}
|
||||
*/
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {Message} from "./Message.js";
|
||||
|
||||
class Channel {
|
||||
constructor(client, channel_id, members_id, messages, reload) {
|
||||
constructor(client, channel, members, messages, reload) {
|
||||
this.client = client;
|
||||
this.channel_id = channel_id;
|
||||
this.members_id = members_id;
|
||||
this.channel = channel;
|
||||
this.members = members;
|
||||
this.messages = [];
|
||||
if (messages != undefined)
|
||||
this.updateMessages(messages);
|
||||
@ -13,16 +13,18 @@ class Channel {
|
||||
}
|
||||
|
||||
// reload = function to use when we receive a message
|
||||
async connect(reload) {
|
||||
let url = `${window.location.protocol[4] === 's' ? 'wss' : 'ws'}://${window.location.host}/ws/chat/${this.channel_id}`;
|
||||
connect(reload) {
|
||||
const url = location.origin.replace('http', 'ws') +
|
||||
'/ws/chat/' +
|
||||
this.channel;
|
||||
|
||||
this.chatSocket = new WebSocket(url);
|
||||
this.chatSocket.onmessage = (event) =>{
|
||||
let data = JSON.parse(event.data);
|
||||
|
||||
this.messages.push(new Message(
|
||||
this.channel_id,
|
||||
data.author_id,
|
||||
this.channel,
|
||||
data.author,
|
||||
data.content,
|
||||
data.time,
|
||||
));
|
||||
@ -31,28 +33,22 @@ class Channel {
|
||||
};
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
disconnect() {
|
||||
this.chatSocket.close();
|
||||
}
|
||||
|
||||
updateMessages(messages)
|
||||
{
|
||||
messages = JSON.parse(messages);
|
||||
let new_messages = [];
|
||||
this.messages = [];
|
||||
|
||||
messages.forEach((message) => {
|
||||
message = message.fields;
|
||||
new_messages.push(new Message(
|
||||
message.channel_id,
|
||||
message.author_id,
|
||||
this.messages.push(new Message(
|
||||
message.channel,
|
||||
message.author,
|
||||
message.content,
|
||||
message.time,
|
||||
));
|
||||
});
|
||||
|
||||
//console.log(new_messages);
|
||||
this.messages = new_messages;
|
||||
return new_messages;
|
||||
}
|
||||
|
||||
async sendMessageChannel(message, receivers_id) {
|
||||
@ -65,19 +61,6 @@ class Channel {
|
||||
'receivers_id':receivers_id,
|
||||
}));
|
||||
}
|
||||
|
||||
async deleteChannel() {
|
||||
let response = await this.client._delete("/api/chat/" + this.channel_id, {
|
||||
});
|
||||
|
||||
let data = await response.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
async sendInvite() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export {Channel};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {Channel} from "./Channel.js";
|
||||
|
||||
class Channels {
|
||||
export default class Channels {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.channel = undefined;
|
||||
@ -8,32 +8,16 @@ class Channels {
|
||||
|
||||
async createChannel(members_id, reload) {
|
||||
|
||||
let response = await this.client._post("/api/chat/", {
|
||||
const response = await this.client._post("/api/chat/", {
|
||||
members_id:members_id
|
||||
});
|
||||
|
||||
if (response.status >= 300)
|
||||
return undefined;
|
||||
|
||||
let data = await response.json();
|
||||
const data = await response.json();
|
||||
console.log(data)
|
||||
|
||||
let messages;
|
||||
if (response.status == 200)
|
||||
messages = data.messages;
|
||||
|
||||
this.channel = new Channel(this.client, data.channel_id, members_id, messages, reload);
|
||||
return this.channel;
|
||||
this.channel = new Channel(this.client, data.id, members_id, data.messages, reload);
|
||||
}
|
||||
|
||||
async deleteChannel(members_id) {
|
||||
let response = await this.client._delete("/api/chat/", {
|
||||
members_id:members_id
|
||||
});
|
||||
|
||||
let data = await response.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export {Channels};
|
||||
|
@ -1,7 +1,7 @@
|
||||
class Message {
|
||||
constructor(channel_id, author_id, content, time) {
|
||||
this.channel_id = channel_id;
|
||||
this.author_id = author_id;
|
||||
constructor(channel, author, content, time) {
|
||||
this.channel = channel;
|
||||
this.author = author;
|
||||
this.content = content;
|
||||
this.time = time;
|
||||
}
|
||||
|
Reference in New Issue
Block a user