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

47 lines
974 B
JavaScript
Raw Permalink 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) {
2023-12-18 15:26:18 -05:00
let null_id = false;
users_id.forEach(user_id => {
if (user_id == null)
2023-12-18 15:26:18 -05:00
null_id = true;
});
2023-12-18 15:26:18 -05:00
if (null_id)
return console.log(users_id, "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}