ft_transcendence/frontend/static/js/api/chat/channels.js

44 lines
907 B
JavaScript
Raw Normal View History

2023-12-15 14:32:43 -05:00
import {Channel} from "./channel.js"
import {Message} from "./message.js"
2023-12-12 04:04:46 -05:00
class Channels {
constructor(client) {
this.client = client;
}
2023-12-15 14:32:43 -05:00
async createChannel(users_id, reload) {
users_id.forEach(user_id => {
if (user_id == null)
return console.log("createChannel error, null id;");
});
2023-12-12 04:04:46 -05:00
let response = await this.client._post("/api/chat/", {
users_id:users_id
});
let data = await response.json();
2023-12-15 14:32:43 -05:00
let exit_code = await response.status;
if (exit_code >= 300)
return undefined;
let messages = undefined;
if (exit_code == 200)
messages = data.messages;
return new Channel(this.client, data.channel_id, users_id, messages, reload);
}
async deleteChannel(users_id) {
let response = await this.client._delete("/api/chat/", {
users_id:users_id
});
let data = await response.json();
console.log(response.status)
2023-12-12 04:04:46 -05:00
return data;
}
2023-12-15 14:32:43 -05:00
2023-12-12 04:04:46 -05:00
}
export {Channels}