snowflake and cleaning up classes

This commit is contained in:
MathMan05 2024-07-23 23:01:45 -05:00
parent 14d1c69c7d
commit 7eb3ff6cab
21 changed files with 584 additions and 361 deletions

View file

@ -4,6 +4,7 @@ import { Role } from "./role.js";
import { Fullscreen } from "./fullscreen.js";
import { Member } from "./member.js";
import { Settings, RoleList } from "./settings.js";
import { SnowFlake } from "./snowflake.js";
class Guild {
owner;
headers;
@ -67,30 +68,30 @@ class Guild {
s1.options.push(new RoleList(permlist, this, this.updateRolePermissions.bind(this)));
settings.show();
}
constructor(JSON, owner, member) {
if (JSON === -1) {
constructor(json, owner, member) {
if (json === -1) {
return;
}
this.owner = owner;
this.headers = this.owner.headers;
this.channels = [];
this.channelids = {};
this.id = JSON.id;
this.properties = JSON.properties;
this.id = new SnowFlake(json.id, this);
this.properties = json.properties;
this.roles = [];
this.roleids = {};
this.roleids = new Map();
this.prevchannel = undefined;
this.message_notifications = 0;
for (const roley of JSON.roles) {
for (const roley of json.roles) {
const roleh = new Role(roley, this);
this.roles.push(roleh);
this.roleids[roleh.id] = roleh;
this.roleids.set(roleh.id, roleh);
}
Member.resolve(member, this).then(_ => this.member = _);
for (const thing of JSON.channels) {
for (const thing of json.channels) {
const temp = new Channel(thing, this);
this.channels.push(temp);
this.channelids[temp.id] = temp;
this.channelids[temp.id.id] = temp;
}
this.headchannels = [];
for (const thing of this.channels) {
@ -118,7 +119,7 @@ class Guild {
headers: this.headers,
body: JSON.stringify({
"guilds": {
[this.id]: {
[this.id.id]: {
"message_notifications": noti
}
}
@ -237,7 +238,7 @@ class Guild {
const noti = document.createElement("div");
noti.classList.add("unread");
divy.append(noti);
this.localuser.guildhtml[this.id] = divy;
this.localuser.guildhtml[this.id.id] = divy;
if (this.properties.icon != null) {
const img = document.createElement("img");
img.classList.add("pfp", "servericon");
@ -366,16 +367,10 @@ class Guild {
body: JSON.stringify(build)
});
}
getRole(ID) {
if (!this.roleids[ID]) {
console.error(`role id ${ID} does not exist`, this.roleids);
}
return this.roleids[ID];
}
hasRole(r) {
console.log("this should run");
if ((typeof r) !== (typeof "")) {
r = r.id;
if (r instanceof Role) {
r = r.id.id;
}
return this.member.hasRole(r);
}
@ -397,10 +392,10 @@ class Guild {
}
}
loadGuild() {
this.localuser.loadGuild(this.id);
this.localuser.loadGuild(this.id.id);
}
updateChannel(JSON) {
this.channelids[JSON.id].updateChannel(JSON);
SnowFlake.getSnowFlakeFromID(JSON.id, Channel).getObject().updateChannel(JSON);
this.headchannels = [];
for (const thing of this.channels) {
thing.children = [];
@ -507,7 +502,7 @@ class Guild {
});
const json = await fetched.json();
const role = new Role(json, this);
this.roleids[role.id] = role;
this.roleids[role.id.id] = role;
this.roles.push(role);
return role;
}