lint and merge

This commit is contained in:
MathMan05 2024-09-19 12:49:50 -05:00
parent 49f2234e81
commit e12b99c38b
34 changed files with 10323 additions and 10330 deletions

View file

@ -1,78 +1,78 @@
import { Guild } from "./guild.js";
import { Channel } from "./channel.js";
import { Message } from "./message.js";
import { Localuser } from "./localuser.js";
import { User } from "./user.js";
import {
channeljson,
dirrectjson,
memberjson,
messagejson,
} from "./jsontypes.js";
import { Permissions } from "./permissions.js";
import { SnowFlake } from "./snowflake.js";
import { Contextmenu } from "./contextmenu.js";
import{ Guild }from"./guild.js";
import{ Channel }from"./channel.js";
import{ Message }from"./message.js";
import{ Localuser }from"./localuser.js";
import{ User }from"./user.js";
import{
channeljson,
dirrectjson,
memberjson,
messagejson,
}from"./jsontypes.js";
import{ Permissions }from"./permissions.js";
import{ SnowFlake }from"./snowflake.js";
import{ Contextmenu }from"./contextmenu.js";
class Direct extends Guild {
declare channelids: { [key: string]: Group };
getUnixTime(): number {
throw new Error("Do not call this for Direct, it does not make sense");
}
constructor(json: dirrectjson[], owner: Localuser) {
super(-1, owner, null);
this.message_notifications = 0;
this.owner = owner;
if (!this.localuser) {
console.error("Owner was not included, please fix");
}
this.headers = this.localuser.headers;
this.channels = [];
this.channelids = {};
// @ts-ignore
this.properties = {};
this.roles = [];
this.roleids = new Map();
this.prevchannel = undefined;
this.properties.name = "Direct Messages";
for (const thing of json) {
const temp = new Group(thing, this);
this.channels.push(temp);
this.channelids[temp.id] = temp;
}
this.headchannels = this.channels;
}
createChannelpac(json: any) {
const thischannel = new Group(json, this);
this.channelids[thischannel.id] = thischannel;
this.channels.push(thischannel);
this.sortchannels();
this.printServers();
return thischannel;
}
delChannel(json: channeljson) {
const channel = this.channelids[json.id];
super.delChannel(json);
if (channel) {
channel.del();
}
}
giveMember(_member: memberjson) {
console.error("not a real guild, can't give member object");
}
getRole(/* ID: string */) {
return null;
}
hasRole(/* r: string */) {
return false;
}
isAdmin() {
return false;
}
unreaddms() {
for (const thing of this.channels) {
(thing as Group).unreads();
}
}
class Direct extends Guild{
declare channelids: { [key: string]: Group };
getUnixTime(): number{
throw new Error("Do not call this for Direct, it does not make sense");
}
constructor(json: dirrectjson[], owner: Localuser){
super(-1, owner, null);
this.message_notifications = 0;
this.owner = owner;
if(!this.localuser){
console.error("Owner was not included, please fix");
}
this.headers = this.localuser.headers;
this.channels = [];
this.channelids = {};
// @ts-ignore
this.properties = {};
this.roles = [];
this.roleids = new Map();
this.prevchannel = undefined;
this.properties.name = "Direct Messages";
for(const thing of json){
const temp = new Group(thing, this);
this.channels.push(temp);
this.channelids[temp.id] = temp;
}
this.headchannels = this.channels;
}
createChannelpac(json: any){
const thischannel = new Group(json, this);
this.channelids[thischannel.id] = thischannel;
this.channels.push(thischannel);
this.sortchannels();
this.printServers();
return thischannel;
}
delChannel(json: channeljson){
const channel = this.channelids[json.id];
super.delChannel(json);
if(channel){
channel.del();
}
}
giveMember(_member: memberjson){
console.error("not a real guild, can't give member object");
}
getRole(/* ID: string */){
return null;
}
hasRole(/* r: string */){
return false;
}
isAdmin(){
return false;
}
unreaddms(){
for(const thing of this.channels){
(thing as Group).unreads();
}
}
}
const dmPermissions = new Permissions("0");
@ -99,37 +99,37 @@ dmPermissions.setPermission("STREAM", 1);
dmPermissions.setPermission("USE_VAD", 1);
// @ts-ignore
class Group extends Channel {
user: User;
static contextmenu = new Contextmenu<Group, undefined>("channel menu");
static setupcontextmenu() {
this.contextmenu.addbutton("Copy DM id", function (this: Group) {
navigator.clipboard.writeText(this.id);
});
class Group extends Channel{
user: User;
static contextmenu = new Contextmenu<Group, undefined>("channel menu");
static setupcontextmenu(){
this.contextmenu.addbutton("Copy DM id", function(this: Group){
navigator.clipboard.writeText(this.id);
});
this.contextmenu.addbutton("Mark as read", function (this: Group) {
this.readbottom();
});
this.contextmenu.addbutton("Mark as read", function(this: Group){
this.readbottom();
});
this.contextmenu.addbutton("Close DM", function (this: Group) {
this.deleteChannel();
});
this.contextmenu.addbutton("Close DM", function(this: Group){
this.deleteChannel();
});
this.contextmenu.addbutton("Copy user ID", function () {
navigator.clipboard.writeText(this.user.id);
});
this.contextmenu.addbutton("Copy user ID", function(){
navigator.clipboard.writeText(this.user.id);
});
}
constructor(json: dirrectjson, owner: Direct) {
super(-1, owner, json.id);
this.owner = owner;
this.headers = this.guild.headers;
this.name = json.recipients[0]?.username;
if (json.recipients[0]) {
this.user = new User(json.recipients[0], this.localuser);
} else {
this.user = this.localuser.user;
}
this.name ??= this.localuser.user.username;
constructor(json: dirrectjson, owner: Direct){
super(-1, owner, json.id);
this.owner = owner;
this.headers = this.guild.headers;
this.name = json.recipients[0]?.username;
if(json.recipients[0]){
this.user = new User(json.recipients[0], this.localuser);
}else{
this.user = this.localuser.user;
}
this.name ??= this.localuser.user.username;
this.parent_id!;
this.parent!;
this.children = [];
@ -140,139 +140,139 @@ static contextmenu = new Contextmenu<Group, undefined>("channel menu");
this.setUpInfiniteScroller();
this.updatePosition();
}
updatePosition() {
if (this.lastmessageid) {
this.position = SnowFlake.stringToUnixTime(this.lastmessageid);
} else {
this.position = 0;
updatePosition(){
if(this.lastmessageid){
this.position = SnowFlake.stringToUnixTime(this.lastmessageid);
}else{
this.position = 0;
}
this.position = -Math.max(this.position, this.getUnixTime());
}
this.position = -Math.max(this.position, this.getUnixTime());
}
createguildHTML() {
const div = document.createElement("div");
Group.contextmenu.bindContextmenu(div, this, undefined);
this.html = new WeakRef(div);
div.classList.add("channeleffects");
const myhtml = document.createElement("span");
myhtml.textContent = this.name;
div.appendChild(this.user.buildpfp());
div.appendChild(myhtml);
(div as any)["myinfo"] = this;
div.onclick = (_) => {
this.getHTML();
};
createguildHTML(){
const div = document.createElement("div");
Group.contextmenu.bindContextmenu(div, this);
this.html = new WeakRef(div);
div.classList.add("channeleffects");
const myhtml = document.createElement("span");
myhtml.textContent = this.name;
div.appendChild(this.user.buildpfp());
div.appendChild(myhtml);
(div as any).myinfo = this;
div.onclick = _=>{
this.getHTML();
};
return div;
return div;
}
async getHTML() {
const id = ++Channel.genid;
if (this.localuser.channelfocus) {
this.localuser.channelfocus.infinite.delete();
}
if (this.guild !== this.localuser.lookingguild) {
this.guild.loadGuild();
}
this.guild.prevchannel = this;
this.localuser.channelfocus = this;
const prom = this.infinite.delete();
history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.id);
this.localuser.pageTitle("@" + this.name);
(document.getElementById("channelTopic") as HTMLElement).setAttribute(
"hidden",
""
);
async getHTML(){
const id = ++Channel.genid;
if(this.localuser.channelfocus){
this.localuser.channelfocus.infinite.delete();
}
if(this.guild !== this.localuser.lookingguild){
this.guild.loadGuild();
}
this.guild.prevchannel = this;
this.localuser.channelfocus = this;
const prom = this.infinite.delete();
history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.id);
this.localuser.pageTitle("@" + this.name);
(document.getElementById("channelTopic") as HTMLElement).setAttribute(
"hidden",
""
);
const loading = document.getElementById("loadingdiv") as HTMLDivElement;
Channel.regenLoadingMessages();
loading.classList.add("loading");
this.rendertyping();
await this.putmessages();
await prom;
if (id !== Channel.genid) {
return;
}
this.buildmessages();
(document.getElementById("typebox") as HTMLDivElement).contentEditable =
const loading = document.getElementById("loadingdiv") as HTMLDivElement;
Channel.regenLoadingMessages();
loading.classList.add("loading");
this.rendertyping();
await this.putmessages();
await prom;
if(id !== Channel.genid){
return;
}
this.buildmessages();
(document.getElementById("typebox") as HTMLDivElement).contentEditable =
"" + true;
}
messageCreate(messagep: { d: messagejson }) {
const messagez = new Message(messagep.d, this);
if (this.lastmessageid) {
this.idToNext.set(this.lastmessageid, messagez.id);
this.idToPrev.set(messagez.id, this.lastmessageid);
}
this.lastmessageid = messagez.id;
if (messagez.author === this.localuser.user) {
this.lastreadmessageid = messagez.id;
if (this.myhtml) {
this.myhtml.classList.remove("cunread");
}
} else {
if (this.myhtml) {
this.myhtml.classList.add("cunread");
}
}
this.unreads();
this.updatePosition();
this.infinite.addedBottom();
this.guild.sortchannels();
if (this.myhtml) {
const parrent = this.myhtml.parentElement as HTMLElement;
parrent.prepend(this.myhtml);
}
if (this === this.localuser.channelfocus) {
if (!this.infinitefocus) {
this.tryfocusinfinate();
}
this.infinite.addedBottom();
}
this.unreads();
if (messagez.author === this.localuser.user) {
return;
}
if (
this.localuser.lookingguild?.prevchannel === this &&
messageCreate(messagep: { d: messagejson }){
const messagez = new Message(messagep.d, this);
if(this.lastmessageid){
this.idToNext.set(this.lastmessageid, messagez.id);
this.idToPrev.set(messagez.id, this.lastmessageid);
}
this.lastmessageid = messagez.id;
if(messagez.author === this.localuser.user){
this.lastreadmessageid = messagez.id;
if(this.myhtml){
this.myhtml.classList.remove("cunread");
}
}else{
if(this.myhtml){
this.myhtml.classList.add("cunread");
}
}
this.unreads();
this.updatePosition();
this.infinite.addedBottom();
this.guild.sortchannels();
if(this.myhtml){
const parrent = this.myhtml.parentElement as HTMLElement;
parrent.prepend(this.myhtml);
}
if(this === this.localuser.channelfocus){
if(!this.infinitefocus){
this.tryfocusinfinate();
}
this.infinite.addedBottom();
}
this.unreads();
if(messagez.author === this.localuser.user){
return;
}
if(
this.localuser.lookingguild?.prevchannel === this &&
document.hasFocus()
) {
return;
}
if (this.notification === "all") {
this.notify(messagez);
} else if (
this.notification === "mentions" &&
){
return;
}
if(this.notification === "all"){
this.notify(messagez);
}else if(
this.notification === "mentions" &&
messagez.mentionsuser(this.localuser.user)
) {
this.notify(messagez);
){
this.notify(messagez);
}
}
notititle(message: Message){
return message.author.username;
}
notititle(message: Message) {
return message.author.username;
}
readbottom() {
super.readbottom();
this.unreads();
readbottom(){
super.readbottom();
this.unreads();
}
all: WeakRef<HTMLElement> = new WeakRef(document.createElement("div"));
noti: WeakRef<HTMLElement> = new WeakRef(document.createElement("div"));
del() {
const all = this.all.deref();
if (all) {
noti: WeakRef<HTMLElement> = new WeakRef(document.createElement("div"));
del(){
const all = this.all.deref();
if(all){
all.remove();
}
if (this.myhtml) {
}
if(this.myhtml){
this.myhtml.remove();
}
}
unreads() {
const sentdms = document.getElementById("sentdms") as HTMLDivElement; //Need to change sometime
const current = this.all.deref();
if (this.hasunreads) {
}
}
unreads(){
const sentdms = document.getElementById("sentdms") as HTMLDivElement; //Need to change sometime
const current = this.all.deref();
if(this.hasunreads){
{
const noti = this.noti.deref();
if (noti) {
noti.textContent = this.mentions + "";
return;
}
const noti = this.noti.deref();
if(noti){
noti.textContent = this.mentions + "";
return;
}
}
const div = document.createElement("div");
div.classList.add("servernoti");
@ -286,21 +286,21 @@ static contextmenu = new Contextmenu<Group, undefined>("channel menu");
buildpfp.classList.add("mentioned");
div.append(buildpfp);
sentdms.append(div);
div.onclick = (_) => {
this.guild.loadGuild();
this.getHTML();
div.onclick = _=>{
this.guild.loadGuild();
this.getHTML();
};
} else if (current) {
}else if(current){
current.remove();
} else {
}
}
isAdmin(): boolean {
return false;
}
hasPermission(name: string): boolean {
return dmPermissions.hasPermission(name);
}
}
export { Direct, Group };
Group.setupcontextmenu();
}else{
}
}
isAdmin(): boolean{
return false;
}
hasPermission(name: string): boolean{
return dmPermissions.hasPermission(name);
}
}
export{ Direct, Group };
Group.setupcontextmenu();