48 lines
999 B
JavaScript
48 lines
999 B
JavaScript
import {Channel} from "./channel.js"
|
|
import {Message} from "./message.js"
|
|
|
|
class Channels {
|
|
constructor(client) {
|
|
this.client = client;
|
|
}
|
|
|
|
async createChannel(members_id, reload) {
|
|
|
|
let null_id = false;
|
|
members_id.forEach(member_id => {
|
|
if (member_id == null)
|
|
null_id = true;
|
|
});
|
|
if (null_id)
|
|
return console.log(members_id, "createChannel error, null id;");
|
|
|
|
let response = await this.client._post("/api/chat/", {
|
|
members_id:members_id
|
|
});
|
|
|
|
let data = await response.json();
|
|
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, members_id, messages, reload);
|
|
}
|
|
|
|
async deleteChannel(members_id) {
|
|
let response = await this.client._delete("/api/chat/", {
|
|
members_id:members_id
|
|
});
|
|
|
|
let data = await response.json();
|
|
console.log(response.status)
|
|
return data;
|
|
}
|
|
|
|
}
|
|
|
|
export {Channels}
|