updates to local
This commit is contained in:
parent
71c281ec2b
commit
0cbc1a7910
6 changed files with 67 additions and 70 deletions
|
@ -102,24 +102,24 @@ class Channel {
|
||||||
return true;
|
return true;
|
||||||
}.bind(this), this.readbottom.bind(this));
|
}.bind(this), this.readbottom.bind(this));
|
||||||
}
|
}
|
||||||
constructor(JSON, owner) {
|
constructor(json, owner) {
|
||||||
if (JSON === -1) {
|
if (json === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.editing;
|
this.editing;
|
||||||
this.type = JSON.type;
|
this.type = json.type;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.name = JSON.name;
|
this.name = json.name;
|
||||||
this.snowflake = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(json.id, this);
|
||||||
this.parent_id = new SnowFlake(JSON.parent_id, undefined);
|
this.parent_id = new SnowFlake(json.parent_id, undefined);
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.guild_id = JSON.guild_id;
|
this.guild_id = json.guild_id;
|
||||||
this.messageids = new Map();
|
this.messageids = new Map();
|
||||||
this.permission_overwrites = new Map();
|
this.permission_overwrites = new Map();
|
||||||
this.permission_overwritesar = [];
|
this.permission_overwritesar = [];
|
||||||
for (const thing of JSON.permission_overwrites) {
|
for (const thing of json.permission_overwrites) {
|
||||||
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -127,11 +127,11 @@ class Channel {
|
||||||
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
||||||
this.permission_overwritesar.push([thing.id, this.permission_overwrites.get(thing.id)]);
|
this.permission_overwritesar.push([thing.id, this.permission_overwrites.get(thing.id)]);
|
||||||
}
|
}
|
||||||
this.topic = JSON.topic;
|
this.topic = json.topic;
|
||||||
this.nsfw = JSON.nsfw;
|
this.nsfw = json.nsfw;
|
||||||
this.position = JSON.position;
|
this.position = json.position;
|
||||||
this.lastreadmessageid = null;
|
this.lastreadmessageid = null;
|
||||||
this.lastmessageid = SnowFlake.getSnowFlakeFromID(JSON.last_message_id, Message);
|
this.lastmessageid = SnowFlake.getSnowFlakeFromID(json.last_message_id, Message);
|
||||||
this.setUpInfiniteScroller();
|
this.setUpInfiniteScroller();
|
||||||
}
|
}
|
||||||
isAdmin() {
|
isAdmin() {
|
||||||
|
@ -563,10 +563,10 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(json) {
|
||||||
const build = [];
|
const build = [];
|
||||||
for (const thing of this.children) {
|
for (const thing of this.children) {
|
||||||
if (thing.snowflake !== JSON.id) {
|
if (thing.snowflake !== json.id) {
|
||||||
build.push(thing);
|
build.push(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -644,16 +644,16 @@ class Channel {
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
updateChannel(JSON) {
|
updateChannel(json) {
|
||||||
this.type = JSON.type;
|
this.type = json.type;
|
||||||
this.name = JSON.name;
|
this.name = json.name;
|
||||||
this.parent_id = new SnowFlake(JSON.parent_id, undefined);
|
this.parent_id = new SnowFlake(json.parent_id, undefined);
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.guild_id = JSON.guild_id;
|
this.guild_id = json.guild_id;
|
||||||
this.messageids = new Map();
|
this.messageids = new Map();
|
||||||
this.permission_overwrites = new Map();
|
this.permission_overwrites = new Map();
|
||||||
for (const thing of JSON.permission_overwrites) {
|
for (const thing of json.permission_overwrites) {
|
||||||
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
if (thing.id === "1182819038095799904" || thing.id === "1182820803700625444") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -661,8 +661,8 @@ class Channel {
|
||||||
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
this.permission_overwrites.set(thing.id, new Permissions(thing.allow, thing.deny));
|
||||||
this.permission_overwritesar.push([thing.id, this.permission_overwrites.get(thing.id)]);
|
this.permission_overwritesar.push([thing.id, this.permission_overwrites.get(thing.id)]);
|
||||||
}
|
}
|
||||||
this.topic = JSON.topic;
|
this.topic = json.topic;
|
||||||
this.nsfw = JSON.nsfw;
|
this.nsfw = json.nsfw;
|
||||||
}
|
}
|
||||||
typingstart() {
|
typingstart() {
|
||||||
if (this.typing > new Date().getTime()) {
|
if (this.typing > new Date().getTime()) {
|
||||||
|
|
|
@ -4,10 +4,10 @@ import { Message } from "./message.js";
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
class Direct extends Guild {
|
class Direct extends Guild {
|
||||||
constructor(JSON, owner) {
|
constructor(json, owner) {
|
||||||
super(-1, owner, null);
|
super(-1, owner, null);
|
||||||
this.message_notifications = 0;
|
this.message_notifications = 0;
|
||||||
console.log(JSON);
|
console.log(json);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
if (!this.localuser) {
|
if (!this.localuser) {
|
||||||
console.error("Owner was not included, please fix");
|
console.error("Owner was not included, please fix");
|
||||||
|
@ -21,16 +21,16 @@ class Direct extends Guild {
|
||||||
this.roleids = new Map();
|
this.roleids = new Map();
|
||||||
this.prevchannel = undefined;
|
this.prevchannel = undefined;
|
||||||
this.properties.name = "Direct Messages";
|
this.properties.name = "Direct Messages";
|
||||||
for (const thing of JSON) {
|
for (const thing of json) {
|
||||||
const temp = new Group(thing, this);
|
const temp = new Group(thing, this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id] = temp;
|
this.channelids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
this.headchannels = this.channels;
|
this.headchannels = this.channels;
|
||||||
}
|
}
|
||||||
createChannelpac(JSON) {
|
createChannelpac(json) {
|
||||||
const thischannel = new Group(JSON, this);
|
const thischannel = new Group(json, this);
|
||||||
this.channelids[JSON.id] = thischannel;
|
this.channelids[json.id] = thischannel;
|
||||||
this.channels.push(thischannel);
|
this.channels.push(thischannel);
|
||||||
this.calculateReorder();
|
this.calculateReorder();
|
||||||
this.printServers();
|
this.printServers();
|
||||||
|
@ -61,26 +61,26 @@ class Direct extends Guild {
|
||||||
}
|
}
|
||||||
class Group extends Channel {
|
class Group extends Channel {
|
||||||
user;
|
user;
|
||||||
constructor(JSON, owner) {
|
constructor(json, owner) {
|
||||||
super(-1, owner);
|
super(-1, owner);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.guild.headers;
|
this.headers = this.guild.headers;
|
||||||
this.name = JSON.recipients[0]?.username;
|
this.name = json.recipients[0]?.username;
|
||||||
if (JSON.recipients[0]) {
|
if (json.recipients[0]) {
|
||||||
this.user = new User(JSON.recipients[0], this.localuser);
|
this.user = new User(json.recipients[0], this.localuser);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.user = this.localuser.user;
|
this.user = this.localuser.user;
|
||||||
}
|
}
|
||||||
this.name ??= this.localuser.user.username;
|
this.name ??= this.localuser.user.username;
|
||||||
this.snowflake = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(json.id, this);
|
||||||
this.parent_id = null;
|
this.parent_id = null;
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.guild_id = "@me";
|
this.guild_id = "@me";
|
||||||
this.messageids = new Map();
|
this.messageids = new Map();
|
||||||
this.permission_overwrites = new Map();
|
this.permission_overwrites = new Map();
|
||||||
this.lastmessageid = SnowFlake.getSnowFlakeFromID(JSON.last_message_id, Message);
|
this.lastmessageid = SnowFlake.getSnowFlakeFromID(json.last_message_id, Message);
|
||||||
this.lastmessageid ??= new SnowFlake("0", undefined);
|
this.lastmessageid ??= new SnowFlake("0", undefined);
|
||||||
this.mentions = 0;
|
this.mentions = 0;
|
||||||
this.setUpInfiniteScroller();
|
this.setUpInfiniteScroller();
|
||||||
|
|
|
@ -397,8 +397,8 @@ class Guild {
|
||||||
loadGuild() {
|
loadGuild() {
|
||||||
this.localuser.loadGuild(this.id);
|
this.localuser.loadGuild(this.id);
|
||||||
}
|
}
|
||||||
updateChannel(JSON) {
|
updateChannel(json) {
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.id, Channel).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(json.id, Channel).getObject().updateChannel(json);
|
||||||
this.headchannels = [];
|
this.headchannels = [];
|
||||||
for (const thing of this.channels) {
|
for (const thing of this.channels) {
|
||||||
thing.children = [];
|
thing.children = [];
|
||||||
|
@ -410,9 +410,9 @@ class Guild {
|
||||||
}
|
}
|
||||||
this.printServers();
|
this.printServers();
|
||||||
}
|
}
|
||||||
createChannelpac(JSON) {
|
createChannelpac(json) {
|
||||||
const thischannel = new Channel(JSON, this);
|
const thischannel = new Channel(json, this);
|
||||||
this.channelids[JSON.id] = thischannel;
|
this.channelids[json.id] = thischannel;
|
||||||
this.channels.push(thischannel);
|
this.channels.push(thischannel);
|
||||||
thischannel.resolveparent(this);
|
thischannel.resolveparent(this);
|
||||||
if (!thischannel.parent) {
|
if (!thischannel.parent) {
|
||||||
|
@ -461,9 +461,9 @@ class Guild {
|
||||||
]);
|
]);
|
||||||
channelselect.show();
|
channelselect.show();
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(json) {
|
||||||
const channel = this.channelids[JSON.id];
|
const channel = this.channelids[json.id];
|
||||||
delete this.channelids[JSON.id];
|
delete this.channelids[json.id];
|
||||||
this.channels.splice(this.channels.indexOf(channel), 1);
|
this.channels.splice(this.channels.indexOf(channel), 1);
|
||||||
const indexy = this.headchannels.indexOf(channel);
|
const indexy = this.headchannels.indexOf(channel);
|
||||||
if (indexy !== -1) {
|
if (indexy !== -1) {
|
||||||
|
@ -478,7 +478,7 @@ class Guild {
|
||||||
}else{
|
}else{
|
||||||
console.log("fail");
|
console.log("fail");
|
||||||
if(thing.parent){
|
if(thing.parent){
|
||||||
thing.parent.delChannel(JSON);
|
thing.parent.delChannel(json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { SnowFlake } from "./snowflake.js";
|
||||||
import { Message } from "./message.js";
|
import { Message } from "./message.js";
|
||||||
const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]);
|
const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]);
|
||||||
class Localuser {
|
class Localuser {
|
||||||
packets;
|
lastSequence = null;
|
||||||
token;
|
token;
|
||||||
userinfo;
|
userinfo;
|
||||||
serverurls;
|
serverurls;
|
||||||
|
@ -32,7 +32,6 @@ class Localuser {
|
||||||
connectionSucceed = 0;
|
connectionSucceed = 0;
|
||||||
errorBackoff = 0;
|
errorBackoff = 0;
|
||||||
constructor(userinfo) {
|
constructor(userinfo) {
|
||||||
this.packets = 1;
|
|
||||||
this.token = userinfo.token;
|
this.token = userinfo.token;
|
||||||
this.userinfo = userinfo;
|
this.userinfo = userinfo;
|
||||||
this.serverurls = this.userinfo.serverurls;
|
this.serverurls = this.userinfo.serverurls;
|
||||||
|
@ -132,6 +131,8 @@ class Localuser {
|
||||||
this.ws.addEventListener('message', (event) => {
|
this.ws.addEventListener('message', (event) => {
|
||||||
const temp = JSON.parse(event.data);
|
const temp = JSON.parse(event.data);
|
||||||
console.log(temp);
|
console.log(temp);
|
||||||
|
if (temp.s)
|
||||||
|
this.lastSequence = temp.s;
|
||||||
if (temp.op == 0) {
|
if (temp.op == 0) {
|
||||||
switch (temp.t) {
|
switch (temp.t) {
|
||||||
case "MESSAGE_CREATE":
|
case "MESSAGE_CREATE":
|
||||||
|
@ -203,12 +204,8 @@ class Localuser {
|
||||||
this.wsinterval = setInterval(_ => {
|
this.wsinterval = setInterval(_ => {
|
||||||
if (this.connectionSucceed === 0)
|
if (this.connectionSucceed === 0)
|
||||||
this.connectionSucceed = Date.now();
|
this.connectionSucceed = Date.now();
|
||||||
this.ws.send(JSON.stringify({ op: 1, d: this.packets }));
|
this.ws.send(JSON.stringify({ op: 1, d: this.lastSequence }));
|
||||||
}, temp.d.heartbeat_interval);
|
}, temp.d.heartbeat_interval);
|
||||||
this.packets = 1;
|
|
||||||
}
|
|
||||||
else if (temp.op != 11) {
|
|
||||||
this.packets++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.ws.addEventListener("close", event => {
|
this.ws.addEventListener("close", event => {
|
||||||
|
@ -249,24 +246,24 @@ class Localuser {
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
updateChannel(JSON) {
|
updateChannel(json) {
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(json.guild_id, Guild).getObject().updateChannel(json);
|
||||||
if (JSON.guild_id === this.lookingguild.id) {
|
if (json.guild_id === this.lookingguild.id) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(json.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createChannel(JSON) {
|
createChannel(json) {
|
||||||
JSON.guild_id ??= "@me";
|
json.guild_id ??= "@me";
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().createChannelpac(JSON);
|
SnowFlake.getSnowFlakeFromID(json.guild_id, Guild).getObject().createChannelpac(json);
|
||||||
if (JSON.guild_id === this.lookingguild.id) {
|
if (json.guild_id === this.lookingguild.id) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(json.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(json) {
|
||||||
JSON.guild_id ??= "@me";
|
json.guild_id ??= "@me";
|
||||||
this.guildids.get(JSON.guild_id).delChannel(JSON);
|
this.guildids.get(json.guild_id).delChannel(json);
|
||||||
if (JSON.guild_id === this.lookingguild.snowflake) {
|
if (json.guild_id === this.lookingguild.snowflake) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(json.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
|
|
|
@ -16,17 +16,17 @@ class Role {
|
||||||
get id() {
|
get id() {
|
||||||
return this.snowflake.id;
|
return this.snowflake.id;
|
||||||
}
|
}
|
||||||
constructor(JSON, owner) {
|
constructor(json, owner) {
|
||||||
this.headers = owner.headers;
|
this.headers = owner.headers;
|
||||||
this.info = owner.info;
|
this.info = owner.info;
|
||||||
for (const thing of Object.keys(JSON)) {
|
for (const thing of Object.keys(json)) {
|
||||||
if (thing === "id") {
|
if (thing === "id") {
|
||||||
this.snowflake = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(json.id, this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = JSON[thing];
|
this[thing] = json[thing];
|
||||||
}
|
}
|
||||||
this.permissions = new Permissions(JSON.permissions);
|
this.permissions = new Permissions(json.permissions);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
get guild() {
|
get guild() {
|
||||||
|
|
|
@ -757,7 +757,7 @@ textarea:focus-visible {
|
||||||
}
|
}
|
||||||
|
|
||||||
.servernamediv {
|
.servernamediv {
|
||||||
width: 99%;
|
width: 100%;
|
||||||
/* max-width: 100%; */
|
/* max-width: 100%; */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue