fix id and snowflake
This commit is contained in:
parent
5e9405207b
commit
4f80104e2e
17 changed files with 263 additions and 235 deletions
|
@ -14,7 +14,7 @@ class Message {
|
|||
mentions;
|
||||
mention_roles;
|
||||
attachments; //probably should be its own class tbh, should be Attachments[]
|
||||
id;
|
||||
snowflake;
|
||||
message_reference;
|
||||
type;
|
||||
timestamp;
|
||||
|
@ -22,6 +22,9 @@ class Message {
|
|||
static del;
|
||||
static resolve;
|
||||
div;
|
||||
get id() {
|
||||
return this.snowflake.id;
|
||||
}
|
||||
static setup() {
|
||||
this.del = new Promise(_ => { this.resolve = _; });
|
||||
Message.setupcmenu();
|
||||
|
@ -71,7 +74,7 @@ class Message {
|
|||
continue;
|
||||
}
|
||||
else if (thing === "id") {
|
||||
this.id = new SnowFlake(messagejson.id, this);
|
||||
this.snowflake = new SnowFlake(messagejson.id, this);
|
||||
continue;
|
||||
}
|
||||
this[thing] = messagejson[thing];
|
||||
|
@ -95,7 +98,7 @@ class Message {
|
|||
}
|
||||
}
|
||||
canDelete() {
|
||||
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.id === this.localuser.user.id;
|
||||
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.snowflake === this.localuser.user.snowflake;
|
||||
}
|
||||
get channel() {
|
||||
return this.owner;
|
||||
|
@ -137,14 +140,14 @@ class Message {
|
|||
return build;
|
||||
}
|
||||
async edit(content) {
|
||||
return await fetch(this.info.api.toString() + "/channels/" + this.channel.id + "/messages/" + this.id.id, {
|
||||
return await fetch(this.info.api.toString() + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
|
||||
method: "PATCH",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify({ content: content })
|
||||
});
|
||||
}
|
||||
delete() {
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id.id}`, {
|
||||
fetch(`${this.info.api.toString()}/channels/${this.channel.snowflake}/messages/${this.id}`, {
|
||||
headers: this.headers,
|
||||
method: "DELETE",
|
||||
});
|
||||
|
@ -154,22 +157,22 @@ class Message {
|
|||
this.div.innerHTML = "";
|
||||
this.div = null;
|
||||
}
|
||||
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.id];
|
||||
const regen = this.channel.messageids[prev];
|
||||
const prev = this.channel.idToPrev.get(this.snowflake);
|
||||
const next = this.channel.idToNext.get(this.snowflake);
|
||||
this.channel.idToNext.set(prev, next);
|
||||
this.channel.idToPrev.set(next, prev);
|
||||
this.channel.messageids.delete(this.snowflake);
|
||||
const regen = prev.getObject();
|
||||
if (regen) {
|
||||
regen.generateMessage();
|
||||
}
|
||||
if (this.channel.lastmessage === this) {
|
||||
this.channel.lastmessage = this.channel.messageids[prev];
|
||||
this.channel.lastmessage = prev.getObject();
|
||||
}
|
||||
}
|
||||
generateMessage(premessage = null) {
|
||||
if (!premessage) {
|
||||
premessage = this.channel.messageids[this.channel.idToNext[this.id.id]];
|
||||
premessage = this.channel.idToNext.get(this.snowflake)?.getObject();
|
||||
}
|
||||
const div = this.div;
|
||||
if (this === this.channel.replyingto) {
|
||||
|
@ -240,7 +243,7 @@ class Message {
|
|||
const newt = (new Date(this.timestamp).getTime()) / 1000;
|
||||
current = (newt - old) > 600;
|
||||
}
|
||||
const combine = (premessage?.author?.id != this.author.id) || (current) || this.message_reference;
|
||||
const combine = (premessage?.author?.snowflake != this.author.snowflake) || (current) || this.message_reference;
|
||||
if (combine) {
|
||||
const pfp = this.author.buildpfp();
|
||||
this.author.bind(pfp);
|
||||
|
@ -328,7 +331,7 @@ class Message {
|
|||
}
|
||||
buildhtml(premessage, del = Message.del) {
|
||||
if (this.div) {
|
||||
console.error(`HTML for ${this.id} already exists, aborting`);
|
||||
console.error(`HTML for ${this.snowflake} already exists, aborting`);
|
||||
return;
|
||||
}
|
||||
//premessage??=messages.lastChild;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue