snowflake and cleaning up classes
This commit is contained in:
parent
14d1c69c7d
commit
7eb3ff6cab
21 changed files with 584 additions and 361 deletions
|
@ -4,6 +4,7 @@ import { Member } from "./member.js";
|
|||
import { MarkDown } from "./markdown.js";
|
||||
import { Embed } from "./embed.js";
|
||||
import { File } from "./file.js";
|
||||
import { SnowFlake } from "./snowflake.js";
|
||||
class Message {
|
||||
static contextmenu = new Contextmenu("message menu");
|
||||
owner;
|
||||
|
@ -39,7 +40,7 @@ class Message {
|
|||
this.channel.setReplying(this);
|
||||
});
|
||||
Message.contextmenu.addbutton("Copy message id", function () {
|
||||
navigator.clipboard.writeText(this.id);
|
||||
navigator.clipboard.writeText(this.id.id);
|
||||
});
|
||||
Message.contextmenu.addbutton("Edit", function () {
|
||||
this.channel.editing = this;
|
||||
|
@ -69,6 +70,10 @@ class Message {
|
|||
this.content = new MarkDown(messagejson[thing], this.channel);
|
||||
continue;
|
||||
}
|
||||
else if (thing === "id") {
|
||||
this.id = new SnowFlake(messagejson.id, this);
|
||||
continue;
|
||||
}
|
||||
this[thing] = messagejson[thing];
|
||||
}
|
||||
for (const thing in this.embeds) {
|
||||
|
@ -132,14 +137,14 @@ class Message {
|
|||
return build;
|
||||
}
|
||||
async edit(content) {
|
||||
return await fetch(this.info.api.toString() + "/channels/" + this.channel.id + "/messages/" + this.id, {
|
||||
return await fetch(this.info.api.toString() + "/channels/" + this.channel.id + "/messages/" + this.id.id, {
|
||||
method: "PATCH",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify({ content: content })
|
||||
});
|
||||
}
|
||||
delete() {
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id}`, {
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id.id}`, {
|
||||
headers: this.headers,
|
||||
method: "DELETE",
|
||||
});
|
||||
|
@ -149,19 +154,22 @@ class Message {
|
|||
this.div.innerHTML = "";
|
||||
this.div = null;
|
||||
}
|
||||
const prev = this.channel.idToPrev[this.id];
|
||||
const next = this.channel.idToNext[this.id];
|
||||
const prev = this.channel.idToPrev[this.id.id];
|
||||
const next = this.channel.idToNext[this.id.id];
|
||||
this.channel.idToNext[prev] = next;
|
||||
this.channel.idToPrev[next] = prev;
|
||||
delete this.channel.messageids[this.id];
|
||||
delete this.channel.messageids[this.id.id];
|
||||
const regen = this.channel.messageids[prev];
|
||||
if (regen) {
|
||||
regen.generateMessage();
|
||||
}
|
||||
if (this.channel.lastmessage === this) {
|
||||
this.channel.lastmessage = this.channel.messageids[prev];
|
||||
}
|
||||
}
|
||||
generateMessage(premessage = null) {
|
||||
if (!premessage) {
|
||||
premessage = this.channel.messageids[this.channel.idToNext[this.id]];
|
||||
premessage = this.channel.messageids[this.channel.idToNext[this.id.id]];
|
||||
}
|
||||
const div = this.div;
|
||||
if (this === this.channel.replyingto) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue