get rid of the odd complexity of the snowflake class

This commit is contained in:
MathMan05 2024-09-03 10:34:40 -05:00
parent b72d7673f4
commit 03041cf9fd
13 changed files with 237 additions and 257 deletions

View file

@ -5,7 +5,7 @@ import { Contextmenu } from "./contextmenu.js";
import { Dialog } from "./dialog.js";
import { Permissions } from "./permissions.js";
import { Settings } from "./settings.js";
import { Role, RoleList } from "./role.js";
import { RoleList } from "./role.js";
import { InfiniteScroller } from "./infiniteScroller.js";
import { SnowFlake } from "./snowflake.js";
import { MarkDown } from "./markdown.js";
@ -151,7 +151,7 @@ class Channel {
}
sortPerms() {
this.permission_overwritesar.sort((a, b) => {
return this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
return this.guild.roles.findIndex(_ => _ === a[0]) - this.guild.roles.findIndex(_ => _ === b[0]);
});
}
setUpInfiniteScroller() {
@ -219,7 +219,7 @@ class Channel {
this.name = json.name;
this.snowflake = new SnowFlake(json.id, this);
if (json.parent_id) {
this.parent_id = SnowFlake.getSnowFlakeFromID(json.parent_id, Channel);
this.parent_id = json.parent_id;
}
this.parent = null;
this.children = [];
@ -234,7 +234,10 @@ class Channel {
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
const permission = this.permission_overwrites.get(thing.id);
if (permission) {
this.permission_overwritesar.push([SnowFlake.getSnowFlakeFromID(thing.id, Role), permission]);
const role = this.guild.roleids.get(thing.id);
if (role) {
this.permission_overwritesar.push([role, permission]);
}
}
}
this.topic = json.topic;
@ -313,7 +316,7 @@ class Channel {
});
}
resolveparent(guild) {
const parentid = this.parent_id?.id;
const parentid = this.parent_id;
if (!parentid)
return false;
this.parent = guild.channelids[parentid];
@ -335,7 +338,7 @@ class Channel {
if (thing.move_id && thing.move_id !== thing.parent_id) {
thing.parent_id = thing.move_id;
thisthing.parent_id = thing.parent?.id;
thing.move_id = null;
thing.move_id = undefined;
//console.log(this.guild.channelids[thisthing.parent_id.id]);
}
if (thisthing.position || thisthing.parent_id) {
@ -515,7 +518,7 @@ class Channel {
return;
event.preventDefault();
if (container) {
that.move_id = this.snowflake;
that.move_id = this.id;
if (that.parent) {
that.parent.children.splice(that.parent.children.indexOf(that), 1);
}
@ -782,12 +785,12 @@ class Channel {
for (const i in response) {
let messager;
let willbreak = false;
if (!SnowFlake.hasSnowFlakeFromID(response[i].id, Message)) {
messager = new Message(response[i], this);
if (this.messages.has(response[i].id)) {
messager = this.messages.get(response[i].id);
willbreak = true;
}
else {
messager = SnowFlake.getSnowFlakeFromID(response[i].id, Message).getObject();
willbreak = true;
messager = new Message(response[i], this);
}
this.idToPrev.set(messager.id, previd);
this.idToNext.set(previd, messager.id);
@ -942,11 +945,11 @@ class Channel {
const parent = this.guild.channelids[json.parent_id];
if (parent) {
this.parent = parent;
this.parent_id = parent.snowflake;
this.parent_id = parent.id;
}
else {
this.parent = null;
this.parent_id = null;
this.parent_id = undefined;
}
this.children = [];
this.guild_id = json.guild_id;
@ -959,7 +962,10 @@ class Channel {
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
const permisions = this.permission_overwrites.get(thing.id);
if (permisions) {
this.permission_overwritesar.push([SnowFlake.getSnowFlakeFromID(thing.id, Role), permisions]);
const role = this.guild.roleids.get(thing.id);
if (role) {
this.permission_overwritesar.push([role, permisions]);
}
}
}
this.topic = json.topic;
@ -1136,7 +1142,7 @@ class Channel {
});
const perm = new Permissions("0", "0");
this.permission_overwrites.set(role.id, perm);
this.permission_overwritesar.push([role.snowflake, perm]);
this.permission_overwritesar.push([role, perm]);
}
async updateRolePermissions(id, perms) {
const permission = this.permission_overwrites.get(id);