cleaning stuff up

This commit is contained in:
MathMan05 committed 2026-06-26 22:15:50 -05:00
1 parent 54147a82a3
commit 42ba22b622
9 files changed
+204 -233

No files matched your search

+21 -21
View File
@@ -1141,7 +1141,7 @@ class Channel extends SnowFlake {
}
owner_id?: string;
threadVis() {
return (this.member && !this.threadData?.archived) || this.localuser.channelfocus === this;
return (this.member && !this.threadData?.archived) || this.localuser.focusChannel === this;
}
async moveForDrag(x: number) {
const mainarea = document.getElementById("mainarea");
@@ -1509,7 +1509,7 @@ class Channel extends SnowFlake {
loading.classList.remove("loading");
}
if (this.localuser.channelfocus !== this) {
if (this.localuser.focusChannel !== this) {
await this.getHTML(true);
}
@@ -1968,7 +1968,7 @@ class Channel extends SnowFlake {
typebox.markdown.boxEnabled = false;
const func = () => {
const node = window.getSelection()?.focusNode;
if (this.localuser.channelfocus === this) {
if (this.localuser.focusChannel === this) {
const out = command.collect(typebox, this, node || undefined);
if (!out) {
typebox.markdown.boxEnabled = true;
@@ -2608,8 +2608,8 @@ class Channel extends SnowFlake {
if (this.owner instanceof Direct) {
this.owner.freindDiv?.classList.remove("viewChannel");
}
if (this.localuser.channelfocus) {
this.localuser.channelfocus.collectBox();
if (this.localuser.focusChannel) {
this.localuser.focusChannel.collectBox();
}
const typebox = document.getElementById("typebox") as CustomHTMLDivElement;
typebox.markdown.boxEnabled = !this.curCommand;
@@ -2684,34 +2684,34 @@ class Channel extends SnowFlake {
channelTopic.setAttribute("hidden", "");
channelTopic.onclick = () => {};
}
if (this.guild !== this.localuser.lookingguild) {
if (this.guild !== this.localuser.focusGuild) {
this.guild.loadGuild();
}
if (this.localuser.channelfocus && this.localuser.channelfocus.myhtml) {
this.localuser.channelfocus.myhtml.classList.remove("viewChannel");
if (this.localuser.focusChannel && this.localuser.focusChannel.myhtml) {
this.localuser.focusChannel.myhtml.classList.remove("viewChannel");
}
if (this.myhtml) {
this.myhtml.classList.add("viewChannel");
}
const id = ++Channel.genid;
if (this.localuser.channelfocus && this.localuser.channelfocus !== this) {
this.localuser.channelfocus.infinite.delete();
if (this.localuser.focusChannel && this.localuser.focusChannel !== this) {
this.localuser.focusChannel.infinite.delete();
if (this.localuser.channelfocus.isThread() && !this.localuser.channelfocus.member) {
const prev = this.localuser.channelfocus;
this.localuser.channelfocus = this;
if (this.localuser.focusChannel.isThread() && !this.localuser.focusChannel.member) {
const prev = this.localuser.focusChannel;
this.localuser.focusChannel = this;
prev.parent?.createguildHTML();
}
} else if (this.localuser.channelfocus === this && !aroundMessage && !this.isForum()) {
} else if (this.localuser.focusChannel === this && !aroundMessage && !this.isForum()) {
if (this.lastmessageid)
this.infinite.focus(aroundMessage || this.lastmessageid, !!aroundMessage, true);
return;
}
this.guild.prevchannel = this;
this.guild.perminfo.prevchannel = this.id;
this.localuser.channelfocus = this;
this.localuser.focusChannel = this;
if (this.isThread() && !this.member) {
this.parent?.createguildHTML();
@@ -2835,7 +2835,7 @@ class Channel extends SnowFlake {
}
}
build = I18n.typing(i + "", build);
if (this.localuser.channelfocus === this) {
if (this.localuser.focusChannel === this) {
if (showing) {
typingtext.classList.remove("hidden");
const typingtext2 = document.getElementById("typingtext") as HTMLDivElement;
@@ -3147,7 +3147,7 @@ class Channel extends SnowFlake {
} else if (removetitle) {
removetitle.remove();
}
if (this.localuser.channelfocus !== this) {
if (this.localuser.focusChannel !== this) {
return;
}
const elements = Array.from(messages.getElementsByClassName("scroller"));
@@ -3422,7 +3422,7 @@ class Channel extends SnowFlake {
dont.style.marginLeft = "4px";
buttons.append(retryB, dont);
if (this === this.localuser.channelfocus) {
if (this === this.localuser.focusChannel) {
if (!this.infinitefocus) {
await this.tryfocusinfinate();
}
@@ -3874,7 +3874,7 @@ class Channel extends SnowFlake {
this.unreads();
this.guild.unreads();
if (this === this.localuser.channelfocus) {
if (this === this.localuser.focusChannel) {
if (!this.infinitefocus) {
await this.tryfocusinfinate();
}
@@ -3887,7 +3887,7 @@ class Channel extends SnowFlake {
this.mentions = 0;
this.unreads();
this.guild.unreads();
if (this == this.localuser.channelfocus) {
if (this == this.localuser.focusChannel) {
setTimeout(() => this.goToBottom());
}
}
@@ -3896,7 +3896,7 @@ class Channel extends SnowFlake {
if (messagez.author === this.localuser.user) {
return;
}
if (this.localuser.lookingguild?.prevchannel === this && document.hasFocus()) {
if (this.localuser.focusGuild?.prevchannel === this && document.hasFocus()) {
return;
}
+3 -3
View File
@@ -149,7 +149,7 @@ class Direct extends Guild {
messages.append(container);
const checkVoid = () => {
if (this.localuser.channelfocus !== undefined || this.localuser.lookingguild !== this) {
if (this.localuser.focusChannel !== undefined || this.localuser.focusGuild !== this) {
this.localuser.relationshipsUpdate = () => {};
}
};
@@ -518,13 +518,13 @@ class Group extends Channel {
addRec(user: User) {
this.users.push(user);
this.users = [...new Set(this.users)];
if (this.localuser.channelfocus === this) {
if (this.localuser.focusChannel === this) {
this.localuser.memberListQue();
}
}
removeRec(user: User) {
this.users = this.users.filter((u) => u !== user);
if (this.localuser.channelfocus === this) {
if (this.localuser.focusChannel === this) {
this.localuser.memberListQue();
}
}
+6 -6
View File
@@ -50,8 +50,8 @@ export class Discovery {
if (this.owner instanceof Direct) {
this.owner.freindDiv?.classList.remove("viewChannel");
}
if (this.localuser.channelfocus) {
this.localuser.channelfocus.collectBox();
if (this.localuser.focusChannel) {
this.localuser.focusChannel.collectBox();
}
history.pushState(["@me", "discover"], "", "/channels/@me/discover");
this.localuser.pageTitle(I18n.discovery());
@@ -60,12 +60,12 @@ export class Discovery {
channelTopic.removeAttribute("hidden");
channelTopic.textContent = "";
channelTopic.onclick = () => {};
if (this.localuser.lookingguild) {
this.localuser.lookingguild.html.classList.remove("serveropen");
if (this.localuser.focusGuild) {
this.localuser.focusGuild.html.classList.remove("serveropen");
}
this.localuser.lookingguild = undefined;
this.localuser.channelfocus = undefined;
this.localuser.focusGuild = undefined;
this.localuser.focusChannel = undefined;
const loading = document.getElementById("loadingdiv") as HTMLDivElement;
loading.classList.remove("loading");
+2 -5
View File
@@ -136,7 +136,7 @@ class Emoji {
}
const guild = localuser.guildids.get(lookup.guild?.id as string);
if (guild) {
if (localuser.lookingguild === guild) {
if (localuser.focusGuild === guild) {
desc.textContent = I18n.emoji.found.this();
} else {
desc.textContent = I18n.emoji.found.other();
@@ -361,10 +361,7 @@ class Emoji {
let isFirst = true;
if (localuser) {
[
localuser.lookingguild,
...localuser.guilds.filter((guild) => guild !== localuser.lookingguild),
]
[localuser.focusGuild, ...localuser.guilds.filter((guild) => guild !== localuser.focusGuild)]
.filter((_) => _ !== undefined)
.filter((guild) => guild.id != "@me" && guild.emojis.length > 0)
.forEach((guild) => {
+9 -61
View File
@@ -347,8 +347,8 @@ class Guild extends SnowFlake {
return this.channels.find((_) => _.id === id);
}
recalcPrivate() {
if (this !== this.localuser.lookingguild) return;
this.localuser.channelfocus?.slowmode();
if (this !== this.localuser.focusGuild) return;
this.localuser.focusChannel?.slowmode();
}
async findAdmin() {
const menu = new Dialog(I18n.guild.admins());
@@ -525,58 +525,7 @@ class Guild extends SnowFlake {
loadResults();
}
async searchMembers(limit: number, query: string): Promise<Member[]> {
if (this.id !== "@me") {
return new Promise<Member[]>((res) => {
const nonce = Math.floor(Math.random() * 10 ** 8) + "";
this.localuser.ws!.send(
JSON.stringify({
op: 8,
d: {
guild_id: [this.id],
query,
limit,
presences: true,
nonce,
},
}),
);
this.localuser.searchMap.set(
nonce,
async (e: {
chunk_index: number;
chunk_count: number;
nonce: string;
not_found?: string[];
members?: memberjson[];
presences: presencejson[];
}) => {
console.log(e);
if (e.members && e.members[0]) {
if (e.members[0].user) {
res(
(await Promise.all(e.members.map(async (_) => await Member.new(_, this)))).filter(
(_) => _ !== undefined,
),
);
} else {
const prom1: Promise<User>[] = [];
for (const thing of e.members) {
prom1.push(this.localuser.getUser(thing.id));
}
await Promise.all(prom1);
res(
(await Promise.all(e.members.map(async (_) => await Member.new(_, this)))).filter(
(_) => _ !== undefined,
),
);
}
}
return [];
},
);
});
}
return [];
return this.localuser.searchMembers(limit, query, this);
}
async showWelcome() {
this.welcomeScreen = await (
@@ -1783,7 +1732,6 @@ class Guild extends SnowFlake {
noti.classList.add("unread");
divy.append(noti);
if (guild instanceof Guild && autoLink) {
guild.localuser.guildhtml.set(guild.id, divy);
guild.html = divy;
}
let icon: string | null;
@@ -2019,17 +1967,17 @@ class Guild extends SnowFlake {
this.noChannel(addstate);
}
removePrevChannel() {
if (this.localuser.channelfocus) {
this.localuser.channelfocus.infinite.delete();
if (this.localuser.focusChannel) {
this.localuser.focusChannel.infinite.delete();
}
if (this !== this.localuser.lookingguild) {
if (this !== this.localuser.focusGuild) {
this.loadGuild();
}
if (this.localuser.channelfocus && this.localuser.channelfocus.myhtml) {
this.localuser.channelfocus.myhtml.classList.remove("viewChannel");
if (this.localuser.focusChannel && this.localuser.focusChannel.myhtml) {
this.localuser.focusChannel.myhtml.classList.remove("viewChannel");
}
this.prevchannel = undefined;
this.localuser.channelfocus = undefined;
this.localuser.focusChannel = undefined;
const replybox = document.getElementById("replybox") as HTMLElement;
const typebox = document.getElementById("typebox") as HTMLElement;
replybox.classList.add("hideReplyBox");
+40 -38
View File
@@ -48,16 +48,18 @@ if (window.location.pathname.startsWith("/channels")) {
userInfoElement.addEventListener("click", (event) => {
event.stopImmediatePropagation();
const rect = userInfoElement.getBoundingClientRect();
if (!thisUser) return;
Localuser.userMenu.makemenu(rect.x, rect.top - 10 - window.innerHeight, thisUser);
});
const switchAccountsElement = document.getElementById("switchaccounts") as HTMLDivElement;
switchAccountsElement.addEventListener("click", async (event) => {
event.stopImmediatePropagation();
if (!thisUser) return;
Localuser.showAccountSwitcher(thisUser);
});
let thisUser: Localuser;
let thisUser: Localuser | null = null;
function regSwap(l: Localuser) {
l.onswap = (l) => {
thisUser = l;
@@ -98,9 +100,9 @@ if (window.location.pathname.startsWith("/channels")) {
regSwap(thisUser);
thisUser.initwebsocket().then(async () => {
thisUser.loaduser();
thisUser?.loaduser();
console.warn("huh");
await thisUser.init();
await thisUser?.init();
console.warn("huh2");
const loading = document.getElementById("loading") as HTMLDivElement;
loading.classList.add("doneloading");
@@ -108,27 +110,27 @@ if (window.location.pathname.startsWith("/channels")) {
loaddesc.textContent = I18n.loaded();
console.log("done loading");
if (templateID) {
thisUser.passTemplateID(templateID);
thisUser?.passTemplateID(templateID);
}
});
} catch (e) {
debugger;
console.error(e);
loaddesc.textContent = I18n.accountNotStart();
thisUser = new Localuser(-1);
thisUser = null;
}
//TODO move this to the channel/guild class, this is a weird spot
const menu = new Contextmenu<void, void>("create rightclick");
menu.addButton(
I18n.channel.createChannel(),
() => {
if (thisUser.lookingguild) {
thisUser.lookingguild.createchannels();
if (thisUser?.focusGuild) {
thisUser?.focusGuild.createchannels();
}
},
{
visible: function () {
return thisUser.lookingguild?.member.hasPermission("MANAGE_CHANNELS") || false;
return thisUser?.focusGuild?.member.hasPermission("MANAGE_CHANNELS") || false;
},
},
);
@@ -136,13 +138,13 @@ if (window.location.pathname.startsWith("/channels")) {
menu.addButton(
I18n.channel.createCatagory(),
() => {
if (thisUser.lookingguild) {
thisUser.lookingguild.createcategory();
if (thisUser?.focusGuild) {
thisUser?.focusGuild.createcategory();
}
},
{
visible: function () {
return thisUser.lookingguild?.member.hasPermission("MANAGE_CHANNELS") || false;
return thisUser?.focusGuild?.member.hasPermission("MANAGE_CHANNELS") || false;
},
},
);
@@ -165,7 +167,7 @@ if (window.location.pathname.startsWith("/channels")) {
let replyingTo: Message | null = null;
window.addEventListener("popstate", (e) => {
if (e.state instanceof Object) {
thisUser.goToState(e.state);
thisUser?.goToState(e.state);
}
//console.log(e.state,"state:3")
});
@@ -176,7 +178,7 @@ if (window.location.pathname.startsWith("/channels")) {
nonceMap.set(id, nonce);
return nonce;
}
const markdown = new MarkDown("", thisUser);
const markdown = new MarkDown("", thisUser ?? undefined);
async function sendMessage(channel: Channel, content: string) {
if (!channel.canMessageRightNow()) return;
if (channel.curCommand) {
@@ -185,13 +187,13 @@ if (window.location.pathname.startsWith("/channels")) {
}
markdown.onUpdate("", false);
replyingTo = thisUser.channelfocus ? thisUser.channelfocus.replyingto : null;
replyingTo = thisUser?.focusChannel ? thisUser.focusChannel.replyingto : null;
if (replyingTo?.div) {
replyingTo.div.classList.remove("replying");
}
if (thisUser.channelfocus) {
thisUser.channelfocus.replyingto = null;
thisUser.channelfocus.makereplybox();
if (thisUser?.focusChannel) {
thisUser.focusChannel.replyingto = null;
thisUser.focusChannel.makereplybox();
}
const attachments = images.filter((_) => document.contains(imagesHtml.get(_) || null));
while (images.length) {
@@ -238,7 +240,7 @@ if (window.location.pathname.startsWith("/channels")) {
const mobileSend = document.getElementById("mobileSend");
if (mobileSend) {
mobileSend.onclick = () => {
const channel = thisUser.channelfocus;
const channel = thisUser?.focusChannel;
if (!channel) return;
const content = MarkDown.gatherBoxText(typebox);
sendMessage(channel, content);
@@ -246,23 +248,23 @@ if (window.location.pathname.startsWith("/channels")) {
}
async function handleEnter(event: KeyboardEvent): Promise<void> {
if (event.isComposing) return;
if (event.key === "Escape" && (images.length || thisUser.channelfocus?.replyingto)) {
if (event.key === "Escape" && (images.length || thisUser?.focusChannel?.replyingto)) {
while (images.length) {
const elm = imagesHtml.get(images.pop() as Blob) as HTMLElement;
if (pasteImageElement.contains(elm)) pasteImageElement.removeChild(elm);
}
if (thisUser.channelfocus) {
thisUser.channelfocus?.replyingto?.div?.classList.remove("replying");
thisUser.channelfocus.replyingto = null;
thisUser.channelfocus.makereplybox();
if (thisUser?.focusChannel) {
thisUser.focusChannel?.replyingto?.div?.classList.remove("replying");
thisUser.focusChannel.replyingto = null;
thisUser.focusChannel.makereplybox();
}
return;
}
if (thisUser.handleKeyUp(event)) {
if (thisUser?.handleKeyUp(event)) {
return;
}
const channel = thisUser.channelfocus;
const channel = thisUser?.focusChannel;
if (!channel) return;
const content = MarkDown.gatherBoxText(typebox);
if (content === "" && event.key === "ArrowUp") {
@@ -283,7 +285,7 @@ if (window.location.pathname.startsWith("/channels")) {
typebox.addEventListener("keyup", handleEnter);
typebox.addEventListener("keydown", (event) => {
if (event.isComposing) return;
thisUser.keydown(event);
thisUser?.keydown(event);
if (event.key === "Enter" && !event.shiftKey && window.innerWidth > 600) {
event.preventDefault();
event.stopImmediatePropagation();
@@ -292,13 +294,13 @@ if (window.location.pathname.startsWith("/channels")) {
markdown.giveBox(typebox);
{
const searchBox = document.getElementById("searchBox") as CustomHTMLDivElement;
const markdown = new MarkDown("", thisUser);
const markdown = new MarkDown("", thisUser ?? undefined);
searchBox.markdown = markdown;
const searchX = document.getElementById("searchX") as HTMLElement;
searchBox.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
event.preventDefault();
thisUser.mSearch(markdown.rawString);
thisUser?.mSearch(markdown.rawString);
}
});
searchBox.addEventListener("keyup", () => {
@@ -324,7 +326,7 @@ if (window.location.pathname.startsWith("/channels")) {
searchX.classList.add("svg-search");
searchBox.parentElement!.classList.remove("searching");
searchX.classList.remove("svg-plainx");
thisUser.mSearch("");
thisUser?.mSearch("");
} else {
searchBox.parentElement!.classList.add("searching");
}
@@ -341,7 +343,7 @@ if (window.location.pathname.startsWith("/channels")) {
let imagesHtml = new WeakMap<Blob, HTMLElement>();
document.addEventListener("paste", async (e: ClipboardEvent) => {
if (!thisUser.channelfocus) return;
if (!thisUser?.focusChannel) return;
if (!e.clipboardData) return;
for (const file of Array.from(e.clipboardData.files)) {
@@ -357,7 +359,7 @@ if (window.location.pathname.startsWith("/channels")) {
await setTheme();
function userSettings(): void {
thisUser.showusersettings();
thisUser?.showusersettings();
}
(document.getElementById("settings") as HTMLImageElement).onclick = userSettings;
@@ -410,7 +412,7 @@ if (window.location.pathname.startsWith("/channels")) {
const data = e.dataTransfer;
const bg = document.getElementById("gimmefile") as HTMLDivElement;
bg.hidden = true;
if (!thisUser.channelfocus) {
if (!thisUser?.focusChannel) {
e.preventDefault();
return;
}
@@ -431,7 +433,7 @@ if (window.location.pathname.startsWith("/channels")) {
});
const pinnedM = document.getElementById("pinnedM") as HTMLElement;
pinnedM.onclick = (e) => {
thisUser.pinnedClick(pinnedM.getBoundingClientRect());
thisUser?.pinnedClick(pinnedM.getBoundingClientRect());
e.preventDefault();
e.stopImmediatePropagation();
};
@@ -439,7 +441,7 @@ if (window.location.pathname.startsWith("/channels")) {
umenu.addButton(
I18n.makePoll(),
() => {
thisUser.makePoll();
thisUser?.makePoll();
},
{
//TODO re-enable this once polls is merged
@@ -452,7 +454,7 @@ if (window.location.pathname.startsWith("/channels")) {
input.click();
input.multiple = true;
console.log("clicked");
if (!thisUser.channelfocus) return;
if (!thisUser?.focusChannel) return;
input.onchange = () => {
if (input.files) {
for (const file of Array.from(input.files)) {
@@ -479,7 +481,7 @@ if (window.location.pathname.startsWith("/channels")) {
emojiTB.onclick = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
thisUser.TBEmojiMenu(emojiTB.getBoundingClientRect());
thisUser?.TBEmojiMenu(emojiTB.getBoundingClientRect());
};
const gifTB = document.getElementById("gifTB") as HTMLElement;
@@ -487,7 +489,7 @@ if (window.location.pathname.startsWith("/channels")) {
gifTB.onclick = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
thisUser.makeGifBox(gifTB.getBoundingClientRect());
thisUser?.makeGifBox(gifTB.getBoundingClientRect());
};
const stickerTB = document.getElementById("stickerTB") as HTMLElement;
@@ -495,7 +497,7 @@ if (window.location.pathname.startsWith("/channels")) {
stickerTB.onclick = (e) => {
e.preventDefault();
e.stopImmediatePropagation();
thisUser.makeStickerBox(stickerTB.getBoundingClientRect());
thisUser?.makeStickerBox(stickerTB.getBoundingClientRect());
};
const updateIcon = document.getElementById("updateIcon");
if (updateIcon) {
+118 -94
View File
@@ -80,7 +80,6 @@ class Localuser {
initialized!: boolean;
info!: Specialuser["serverurls"];
headers!: {"Content-type": string; Authorization: string};
ready!: readyjson;
guilds!: Guild[];
guildids: Map<string, Guild> = new Map();
user!: User;
@@ -93,12 +92,11 @@ class Localuser {
set status(status: string) {
this.user.setstatus(status);
}
channelfocus: Channel | undefined;
lookingguild: Guild | undefined;
guildhtml: Map<string, HTMLDivElement> = new Map();
ws: WebSocket | undefined;
connectionSucceed = 0;
errorBackoff = 0;
focusChannel?: Channel;
focusGuild?: Guild;
private ws?: WebSocket;
private connectionSucceed = 0;
private errorBackoff = 0;
channelids: Map<string, Channel> = new Map();
readonly userMap: Map<string, User> = new Map();
voiceFactory?: VoiceFactory;
@@ -142,7 +140,7 @@ class Localuser {
onswap?.(thisUser);
}
static userMenu = this.generateUserMenu();
userResMap = new Map<string, Promise<User>>();
private userResMap = new Map<string, Promise<User>>();
async getUser(id: string) {
let user = this.userMap.get(id);
if (user) return user;
@@ -222,17 +220,56 @@ class Localuser {
);
return menu;
}
async searchMembers(limit: number, query: string, guild: Guild): Promise<Member[]> {
if (guild.id !== "@me") {
return new Promise<Member[]>((res) => {
const nonce = Math.floor(Math.random() * 10 ** 8) + "";
this.ws!.send(
JSON.stringify({
op: 8,
d: {
guild_id: [guild.id],
query,
limit,
presences: true,
nonce,
},
}),
);
this.searchMap.set(nonce, async (e) => {
console.log(e);
if (e.members && e.members[0]) {
if (e.members[0].user) {
res(
(await Promise.all(e.members.map(async (_) => await Member.new(_, guild)))).filter(
(_) => _ !== undefined,
),
);
} else {
const prom1: Promise<User>[] = [];
for (const thing of e.members) {
prom1.push(this.getUser(thing.id));
}
await Promise.all(prom1);
res(
(await Promise.all(e.members.map(async (_) => await Member.new(_, guild)))).filter(
(_) => _ !== undefined,
),
);
}
}
return [];
});
});
}
return [];
}
onswap?: (l: Localuser) => void;
constructor(userinfo: Specialuser | -1) {
constructor(userinfo: Specialuser) {
Play.playURL("/audio/sounds.jasf").then((_) => {
this.play = _;
});
//TODO get rid of this garbage
if (userinfo === -1) {
this.rights = new Rights("");
return;
}
this.userinfo = userinfo;
this.perminfo.guilds ??= {};
this.perminfo.user ??= {};
@@ -281,17 +318,6 @@ class Localuser {
mic.classList.add("svg-mic");
}
}
channelByID(id: string): Channel | void {
let channel: Channel | void = undefined;
this.guilds.forEach((_) => {
_.channels.forEach((_) => {
if (_.id === id) {
channel = _;
}
});
});
return channel;
}
trace: {trace: trace; time: Date}[] = [];
handleTrace(str: string[]) {
const json = str.map((_) => JSON.parse(_)) as trace[];
@@ -350,7 +376,6 @@ class Localuser {
this.guildFolders = ready.d.user_settings.guild_folders;
document.body.style.setProperty("--view-rest", I18n.message.viewrest());
this.initialized = true;
this.ready = ready;
this.guilds = [];
this.guildids = new Map();
this.user = new User(ready.d.user, this);
@@ -382,10 +407,9 @@ class Localuser {
this.userinfo.updateLocal();
}
this.status = this.ready.d.user_settings.status;
this.channelfocus = undefined;
this.lookingguild = undefined;
this.guildhtml = new Map();
this.status = ready.d.user_settings.status;
this.focusChannel = undefined;
this.focusGuild = undefined;
const members: {[key: string]: memberjson} = {};
if (ready.d.merged_members) {
for (const thing of ready.d.merged_members) {
@@ -438,11 +462,11 @@ class Localuser {
servers.innerHTML = "";
const channels = document.getElementById("channels") as HTMLDivElement;
channels.innerHTML = "";
if (this.channelfocus) {
this.channelfocus.infinite.delete();
if (this.focusChannel) {
this.focusChannel.infinite.delete();
}
this.lookingguild = undefined;
this.channelfocus = undefined;
this.focusGuild = undefined;
this.focusChannel = undefined;
}
giveMessage(m: messagejson) {
const c = this.channelids.get(m.channel_id);
@@ -860,7 +884,7 @@ class Localuser {
this.guildids.delete(temp.d.id);
this.guilds.splice(this.guilds.indexOf(guildy), 1);
guildy.html.remove();
if (guildy === this.lookingguild) {
if (guildy === this.focusGuild) {
this.guildids.get("@me")?.loadGuild();
this.guildids.get("@me")?.loadChannel();
}
@@ -1092,7 +1116,7 @@ class Localuser {
break;
}
case "MESSAGE_ACK": {
const channel = this.channelByID(temp.d.channel_id);
const channel = this.channelids.get(temp.d.channel_id);
if (!channel) break;
channel.lastreadmessageid = temp.d.message_id;
channel.mentions = 0;
@@ -1323,7 +1347,7 @@ class Localuser {
const guild = this.guildids.get(json.guild_id || "@me");
if (guild) {
guild.updateChannel(json);
if (json.guild_id === this.lookingguild?.id) {
if (json.guild_id === this.focusGuild?.id) {
this.loadGuild(json.guild_id);
}
}
@@ -1339,7 +1363,7 @@ class Localuser {
if (!guild) return;
if (guild.channels.find((_) => _.id === json.id)) return;
const channel = guild.createChannelpac(json);
if (json.guild_id === this.lookingguild?.id) {
if (json.guild_id === this.focusGuild?.id) {
this.loadGuild(json.guild_id, true);
}
if (channel.id === this.gotoid) {
@@ -1365,10 +1389,10 @@ class Localuser {
}
async memberListUpdate(list: memberlistupdatejson | void) {
if (this.searching) return;
const guild = this.lookingguild;
const guild = this.focusGuild;
if (!guild) return;
const channel = this.channelfocus;
const channel = this.focusChannel;
if (!channel) return;
if (channel.voice && this.voiceAllowed) {
const div = document.getElementById("sideDiv") as HTMLDivElement;
@@ -1628,18 +1652,18 @@ class Localuser {
return Emoji.emojiPicker(x, y, guildEmojis ? this : undefined);
}
async getSidePannel() {
if (this.ws && this.channelfocus) {
console.log(this.channelfocus.guild.id);
if (this.ws && this.focusChannel) {
console.log(this.focusChannel.guild.id);
this.memberListQue();
if (this.channelfocus.guild.id === "@me") {
if (this.focusChannel.guild.id === "@me") {
return;
}
if (!this.channelfocus.visible) return;
if (!this.focusChannel.visible) return;
this.ws.send(
JSON.stringify({
d: {
channels: {[this.channelfocus.id]: [[0, 99]]},
guild_id: this.channelfocus.guild.id,
channels: {[this.focusChannel.id]: [[0, 99]]},
guild_id: this.focusChannel.guild.id,
},
op: 14,
}),
@@ -1681,7 +1705,7 @@ class Localuser {
guild.delChannel(json);
}
if (json.guild_id === this.lookingguild?.id) {
if (json.guild_id === this.focusGuild?.id) {
this.loadGuild(json.guild_id, true);
}
}
@@ -1695,7 +1719,7 @@ class Localuser {
return;
}
await guild.loadChannel(location[5], true, location[6]);
this.channelfocus = this.channelids.get(location[5]);
this.focusChannel = this.channelids.get(location[5]);
}
}
loaduser(): void {
@@ -1704,8 +1728,8 @@ class Localuser {
(document.getElementById("status") as HTMLSpanElement).textContent = this.status;
}
isAdmin(): boolean {
if (this.lookingguild) {
return this.lookingguild.isAdmin();
if (this.focusGuild) {
return this.focusGuild.isAdmin();
} else {
return false;
}
@@ -1718,22 +1742,22 @@ class Localuser {
guild = this.guildids.get("@me");
}
console.log(forceReload);
if (!forceReload && this.lookingguild === guild) {
if (!forceReload && this.focusGuild === guild) {
return guild;
}
if (this.channelfocus && this.lookingguild !== guild) {
this.channelfocus.infinite.delete();
this.channelfocus = undefined;
if (this.focusChannel && this.focusGuild !== guild) {
this.focusChannel.infinite.delete();
this.focusChannel = undefined;
}
if (this.lookingguild) {
this.lookingguild.html.classList.remove("serveropen");
if (this.focusGuild) {
this.focusGuild.html.classList.remove("serveropen");
}
if (!guild) return;
if (guild.html) {
guild.html.classList.add("serveropen");
}
this.lookingguild = guild;
this.focusGuild = guild;
(document.getElementById("serverName") as HTMLElement).textContent = guild.properties.name;
const banner = document.getElementById("servertd");
console.log(guild.banner, banner);
@@ -2314,7 +2338,7 @@ class Localuser {
thing.unreads();
continue;
}
const html = this.guildhtml.get(thing.id);
const html = thing.html;
thing.unreads(html);
}
}
@@ -4027,8 +4051,8 @@ class Localuser {
};
}
async pinnedClick(rect: DOMRect) {
if (!this.channelfocus) return;
await this.channelfocus.pinnedClick(rect);
if (!this.focusChannel) return;
await this.focusChannel.pinnedClick(rect);
}
async makeStickerBox(rect: DOMRect) {
const sticker = await Sticker.stickerPicker(
@@ -4038,14 +4062,14 @@ class Localuser {
);
this.favorites.addStickerFreq(sticker.id);
console.log(sticker);
if (this.channelfocus) {
this.channelfocus.sendMessage("", {
if (this.focusChannel) {
this.focusChannel.sendMessage("", {
embeds: [],
attachments: [],
sticker_ids: [sticker.id],
replyingto: this.channelfocus.replyingto,
replyingto: this.focusChannel.replyingto,
});
this.channelfocus.replyingto = null;
this.focusChannel.replyingto = null;
}
}
@@ -4124,15 +4148,15 @@ class Localuser {
gifs.append(div);
div.onclick = () => {
if (this.channelfocus) {
this.channelfocus.sendMessage(gif.src, {
if (this.focusChannel) {
this.focusChannel.sendMessage(gif.src, {
embeds: [],
attachments: [],
sticker_ids: [],
replyingto: this.channelfocus.replyingto,
replyingto: this.focusChannel.replyingto,
});
menu.remove();
this.channelfocus.replyingto = null;
this.focusChannel.replyingto = null;
}
};
}
@@ -4403,8 +4427,8 @@ class Localuser {
}
MDFindChannel(name: string, original: string, box: HTMLDivElement, typebox: MarkDown) {
const maybe: [number, Channel][] = [];
if (this.lookingguild && this.lookingguild.id !== "@me") {
for (const channel of this.lookingguild.channels.filter((_) => _.visible)) {
if (this.focusGuild && this.focusGuild.id !== "@me") {
for (const channel of this.focusGuild.channels.filter((_) => _.visible)) {
const confidence = channel.similar(name);
if (confidence > 0) {
maybe.push([confidence, channel]);
@@ -4421,9 +4445,9 @@ class Localuser {
}
MDFineMentionGen(name: string, original: string, box: HTMLDivElement, typebox: MarkDown) {
let members: [Member | Role | User | "@everyone" | "@here", number][] = [];
if (this.lookingguild && name !== "everyone" && name !== "here") {
if (this.lookingguild.id === "@me") {
const dirrect = this.channelfocus as Group;
if (this.focusGuild && name !== "everyone" && name !== "here") {
if (this.focusGuild.id === "@me") {
const dirrect = this.focusChannel as Group;
for (const user of dirrect.users) {
const rank = user.compare(name);
@@ -4432,13 +4456,13 @@ class Localuser {
}
}
} else {
for (const member of this.lookingguild.members) {
for (const member of this.focusGuild.members) {
const rank = member.compare(name);
if (rank > 0) {
members.push([member, rank]);
}
}
for (const role of this.lookingguild.roles.filter((_) => _.id !== this.lookingguild?.id)) {
for (const role of this.focusGuild.roles.filter((_) => _.id !== this.focusGuild?.id)) {
const rank = role.compare(name);
if (rank > 0) {
members.push([role, rank]);
@@ -4477,11 +4501,11 @@ class Localuser {
);
}
MDFindMention(name: string, original: string, box: HTMLDivElement, typebox: MarkDown) {
if (this.ws && this.lookingguild) {
if (this.ws && this.focusGuild) {
this.MDFineMentionGen(name, original, box, typebox);
if (this.lookingguild.member_count <= this.lookingguild.members.size) return;
if (this.lookingguild.id !== "@me") {
this.lookingguild.searchMembers(8, name).then(async () => {
if (this.focusGuild.member_count <= this.focusGuild.members.size) return;
if (this.focusGuild.id !== "@me") {
this.focusGuild.searchMembers(8, name).then(async () => {
if (!typebox.rawString.startsWith(original)) return;
this.MDFineMentionGen(name, original, box, typebox);
});
@@ -4505,7 +4529,7 @@ class Localuser {
this.MDSearchOptions(map, original, box, typebox);
}
async findCommands(search: string, box: HTMLDivElement, md: MarkDown) {
const guild = this.lookingguild;
const guild = this.focusGuild;
if (!guild) return;
const commands = await guild.getCommands();
const sorted = commands
@@ -4521,7 +4545,7 @@ class Localuser {
"",
undefined,
() => {
this.channelfocus?.startCommand(elm);
this.focusChannel?.startCommand(elm);
return true;
},
] as const;
@@ -4620,7 +4644,7 @@ class Localuser {
);
const c = opt.addCheckboxInput(I18n.poll.mult(), () => {});
opt.addButtonInput("", I18n.submit(), () => {
const chan = this.channelfocus;
const chan = this.focusChannel;
if (!chan) return;
chan.sendMessage("", {
poll: {
@@ -4659,10 +4683,10 @@ class Localuser {
let channels = [] as Channel[];
const genPage = (page: number) => {
p.set("offset", page * 50 + "");
const guildSearch = this.lookingguild?.id !== "@me";
const guildSearch = this.focusGuild?.id !== "@me";
fetch(
this.info.api +
`${guildSearch ? `/guilds/${this.lookingguild?.id}` : `/channels/${this.channelfocus?.id}`}/messages/search/?` +
`${guildSearch ? `/guilds/${this.focusGuild?.id}` : `/channels/${this.focusChannel?.id}`}/messages/search/?` +
p.toString() +
(authorIds.length ? authorIds.map((_) => `&author_id=${_}`).join("") : "") +
(mentionIds.length ? mentionIds.map((_) => `&mentions=${_}`).join("") : "") +
@@ -4729,12 +4753,12 @@ class Localuser {
else p.set("include_nsfw", "false");
};
const userSearch = async (name: string, ids: string[]) => {
const g = this.lookingguild;
const g = this.focusGuild;
if (!g) return [];
g.searchMembers(8, name);
const members = [] as [User | Member, number][];
if (g.id === "@me") {
const dirrect = this.channelfocus as Group;
const dirrect = this.focusChannel as Group;
for (const user of dirrect.users) {
const rank = user.compare(name);
@@ -4763,7 +4787,7 @@ class Localuser {
opt.addAsyncMultiSelect(I18n.search.authors(), () => {}, userSearch, {
defaultValues: authorIds
.map((id) => {
const g = this.lookingguild;
const g = this.focusGuild;
if (!g || g.id === "@me") {
return this.userMap.get(id);
} else {
@@ -4779,7 +4803,7 @@ class Localuser {
opt.addAsyncMultiSelect(I18n.search.mentions(), () => {}, userSearch, {
defaultValues: mentionIds
.map((id) => {
const g = this.lookingguild;
const g = this.focusGuild;
if (!g || g.id === "@me") {
return this.userMap.get(id);
} else {
@@ -4791,12 +4815,12 @@ class Localuser {
}).onchange = (values: string[]) => {
mentionIds = values;
};
if (this.lookingguild?.id !== "@me")
if (this.focusGuild?.id !== "@me")
opt.addAsyncMultiSelect(
I18n.search.channels(),
() => {},
(name, ids) => {
const g = this.lookingguild;
const g = this.focusGuild;
if (!g) return [];
const c = g.channels.filter((_) => _.visible);
@@ -4823,7 +4847,7 @@ class Localuser {
defaultValues: channels.map((_) => ({name: _.name, value: _.id})),
},
).onchange = (values: string[]) => {
const g = this.lookingguild;
const g = this.focusGuild;
if (!g) return;
channels = values.map((id) => g.getChannel(id)).filter((_) => _ !== undefined);
};
@@ -4932,10 +4956,10 @@ class Localuser {
}
if (event.key === "Escape") {
if (event.ctrlKey) {
this.lookingguild?.markAsRead();
this.focusGuild?.markAsRead();
} else {
this.channelfocus?.readbottom();
this.channelfocus?.goToBottom();
this.focusChannel?.readbottom();
this.focusChannel?.goToBottom();
}
return true;
}
+2 -2
View File
@@ -127,8 +127,8 @@ class Sticker extends SnowFlake {
const topBar = document.createElement("div");
topBar.classList.add("flexltr", "emojiHeading");
const guilds = [
localuser.lookingguild,
...localuser.guilds.filter((guild) => guild !== localuser.lookingguild),
localuser.focusGuild,
...localuser.guilds.filter((guild) => guild !== localuser.focusGuild),
]
.filter((guild) => guild !== undefined)
.filter((guild) => guild.id != "@me" && guild.stickers.length > 0);
+3 -3
View File
@@ -1038,7 +1038,7 @@ class User extends SnowFlake {
async block() {
await this.changeRelationship(2);
const channel = this.localuser.channelfocus;
const channel = this.localuser.focusChannel;
if (channel) {
for (const message of channel.messages) {
message[1].generateMessage();
@@ -1048,7 +1048,7 @@ class User extends SnowFlake {
async unblock() {
await this.changeRelationship(0);
const channel = this.localuser.channelfocus;
const channel = this.localuser.focusChannel;
if (channel) {
for (const message of channel.messages) {
message[1].generateMessage();
@@ -1451,7 +1451,7 @@ class User extends SnowFlake {
...high.mutual_friends
.map((_) => new User(_, this.localuser))
.map((user) => {
const html = user.createWidget(this.localuser.lookingguild);
const html = user.createWidget(this.localuser.focusGuild);
html.onclick = (e) => {
e.stopImmediatePropagation();
e.preventDefault();