Correcting names, and deleting message
There is a known regresion for the MESSAGE_CREATE event while it's not on screen, though I have not been able to replicate it while I'm looking for it. If you see this bug, please let me know the conditions it happens under
This commit is contained in:
parent
845c7f6612
commit
ac939e5fb6
17 changed files with 473 additions and 166 deletions
|
@ -31,6 +31,7 @@ class Channel {
|
||||||
message_notifications;
|
message_notifications;
|
||||||
allthewayup;
|
allthewayup;
|
||||||
static contextmenu = new Contextmenu("channel menu");
|
static contextmenu = new Contextmenu("channel menu");
|
||||||
|
replyingto;
|
||||||
static setupcontextmenu() {
|
static setupcontextmenu() {
|
||||||
Channel.contextmenu.addbutton("Copy channel id", function () {
|
Channel.contextmenu.addbutton("Copy channel id", function () {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
|
@ -68,7 +69,6 @@ class Channel {
|
||||||
for (const thing of JSON.permission_overwrites) {
|
for (const thing of JSON.permission_overwrites) {
|
||||||
this.permission_overwrites[thing.id] = new Permissions(thing.allow, thing.deny);
|
this.permission_overwrites[thing.id] = new Permissions(thing.allow, thing.deny);
|
||||||
}
|
}
|
||||||
console.log(this.permission_overwrites);
|
|
||||||
this.topic = JSON.topic;
|
this.topic = JSON.topic;
|
||||||
this.nsfw = JSON.nsfw;
|
this.nsfw = JSON.nsfw;
|
||||||
this.position = JSON.position;
|
this.position = JSON.position;
|
||||||
|
@ -94,21 +94,31 @@ class Channel {
|
||||||
this.lastpin = json.last_pin_timestamp;
|
this.lastpin = json.last_pin_timestamp;
|
||||||
}
|
}
|
||||||
get hasunreads() {
|
get hasunreads() {
|
||||||
return this.lastmessageid !== this.lastreadmessageid && this.type !== 4;
|
if (!this.hasPermission("VIEW_CHANNEL")) {
|
||||||
}
|
|
||||||
get canMessage() {
|
|
||||||
console.log("this should run");
|
|
||||||
for (const thing of Object.entries(this.permission_overwrites)) {
|
|
||||||
const perm = thing[1].getPermision("SEND_MESSAGES");
|
|
||||||
if (perm === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (perm === -1) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return this.lastmessageid !== this.lastreadmessageid && this.type !== 4;
|
||||||
}
|
}
|
||||||
|
hasPermission(name, member = this.guild.member) {
|
||||||
|
if (member.isAdmin()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
for (const thing of member.roles) {
|
||||||
|
if (this.permission_overwrites[thing.id]) {
|
||||||
|
let perm = this.permission_overwrites[thing.id].getPermision(name);
|
||||||
|
if (perm) {
|
||||||
|
return perm === 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (thing.permissions.getPermision(name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
get canMessage() {
|
||||||
|
return this.hasPermission("SEND_MESSAGES");
|
||||||
|
}
|
||||||
sortchildren() {
|
sortchildren() {
|
||||||
this.children.sort((a, b) => { return a.position - b.position; });
|
this.children.sort((a, b) => { return a.position - b.position; });
|
||||||
}
|
}
|
||||||
|
@ -144,6 +154,17 @@ class Channel {
|
||||||
static dragged = [];
|
static dragged = [];
|
||||||
createguildHTML(admin = false) {
|
createguildHTML(admin = false) {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
|
if (!this.hasPermission("VIEW_CHANNEL")) {
|
||||||
|
let quit = true;
|
||||||
|
for (const thing of this.children) {
|
||||||
|
if (thing.hasPermission("VIEW_CHANNEL")) {
|
||||||
|
quit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (quit) {
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
}
|
||||||
div["all"] = this;
|
div["all"] = this;
|
||||||
div.draggable = admin;
|
div.draggable = admin;
|
||||||
div.addEventListener("dragstart", (e) => { Channel.dragged = [this, div]; e.stopImmediatePropagation(); });
|
div.addEventListener("dragstart", (e) => { Channel.dragged = [this, div]; e.stopImmediatePropagation(); });
|
||||||
|
@ -383,34 +404,38 @@ class Channel {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getHTML() {
|
async getHTML() {
|
||||||
if (this.guild !== this.localuser.lookingguild) {
|
if (this.guild !== this.localuser.lookingguild) {
|
||||||
this.guild.loadGuild();
|
this.guild.loadGuild();
|
||||||
}
|
}
|
||||||
this.guild.prevchannel = this;
|
this.guild.prevchannel = this;
|
||||||
this.localuser.channelfocus = this;
|
this.localuser.channelfocus = this;
|
||||||
this.putmessages();
|
const prom = Message.wipeChanel();
|
||||||
|
await this.putmessages();
|
||||||
|
await prom;
|
||||||
|
this.buildmessages();
|
||||||
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
||||||
document.getElementById("channelname").textContent = "#" + this.name;
|
document.getElementById("channelname").textContent = "#" + this.name;
|
||||||
console.log(this);
|
console.log(this);
|
||||||
document.getElementById("typebox").disabled = !this.canMessage;
|
document.getElementById("typebox").disabled = !this.canMessage;
|
||||||
}
|
}
|
||||||
putmessages() {
|
async putmessages() {
|
||||||
const out = this;
|
if (this.messages.length >= 100) {
|
||||||
fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=100", {
|
return;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
const j = await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=100", {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
}).then((j) => { return j.json(); }).then(responce => {
|
});
|
||||||
document.getElementById("messages").innerHTML = '';
|
const responce = await j.json();
|
||||||
for (const thing of responce) {
|
for (const thing of responce) {
|
||||||
const messager = new Message(thing, this);
|
const messager = new Message(thing, this);
|
||||||
if (out.messageids[messager.id] == undefined) {
|
if (this.messageids[messager.id] === undefined) {
|
||||||
out.messageids[messager.id] = messager;
|
this.messageids[messager.id] = messager;
|
||||||
out.messages.push(messager);
|
this.messages.push(messager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.buildmessages();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(JSON) {
|
||||||
const build = [];
|
const build = [];
|
||||||
|
@ -565,6 +590,9 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageCreate(messagep) {
|
messageCreate(messagep) {
|
||||||
|
if (!this.hasPermission("VIEW_CHANNEL")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const messagez = new Message(messagep.d, this);
|
const messagez = new Message(messagep.d, this);
|
||||||
this.lastmessageid = messagez.id;
|
this.lastmessageid = messagez.id;
|
||||||
if (messagez.author === this.localuser.user) {
|
if (messagez.author === this.localuser.user) {
|
||||||
|
|
|
@ -52,11 +52,15 @@ class Contextmenu {
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
bind(obj, addinfo = undefined) {
|
bind(obj, addinfo = undefined) {
|
||||||
obj.addEventListener("contextmenu", (event) => {
|
const func = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
this.makemenu(event.clientX, event.clientY, addinfo, obj);
|
this.makemenu(event.clientX, event.clientY, addinfo, obj);
|
||||||
});
|
};
|
||||||
|
obj.addEventListener("contextmenu", func);
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
static keepOnScreen(obj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Message } from "./message.js";
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
class Direct extends Guild {
|
class Direct extends Guild {
|
||||||
constructor(JSON, owner) {
|
constructor(JSON, owner) {
|
||||||
super(-1, owner);
|
super(-1, owner, null);
|
||||||
this.message_notifications = 0;
|
this.message_notifications = 0;
|
||||||
console.log(JSON);
|
console.log(JSON);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -97,10 +97,16 @@ class Group extends Channel {
|
||||||
};
|
};
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
getHTML() {
|
async getHTML() {
|
||||||
|
if (this.guild !== this.localuser.lookingguild) {
|
||||||
|
this.guild.loadGuild();
|
||||||
|
}
|
||||||
|
const prom = Message.wipeChanel();
|
||||||
this.guild.prevchannel = this;
|
this.guild.prevchannel = this;
|
||||||
this.localuser.channelfocus = this;
|
this.localuser.channelfocus = this;
|
||||||
this.putmessages();
|
await this.putmessages();
|
||||||
|
await prom;
|
||||||
|
this.buildmessages();
|
||||||
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
||||||
document.getElementById("channelname").textContent = "@" + this.name;
|
document.getElementById("channelname").textContent = "@" + this.name;
|
||||||
}
|
}
|
||||||
|
@ -186,5 +192,11 @@ class Group extends Channel {
|
||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isAdmin() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hasPermission(name, member) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export { Direct, Group };
|
export { Direct, Group };
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Channel } from "./channel.js";
|
||||||
import { Contextmenu } from "./contextmenu.js";
|
import { Contextmenu } from "./contextmenu.js";
|
||||||
import { Role } from "./role.js";
|
import { Role } from "./role.js";
|
||||||
import { Fullscreen } from "./fullscreen.js";
|
import { Fullscreen } from "./fullscreen.js";
|
||||||
|
import { Member } from "./member.js";
|
||||||
class Guild {
|
class Guild {
|
||||||
owner;
|
owner;
|
||||||
headers;
|
headers;
|
||||||
|
@ -52,15 +53,12 @@ class Guild {
|
||||||
},null,_=>{return thisuser.isAdmin()})
|
},null,_=>{return thisuser.isAdmin()})
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
constructor(JSON, owner) {
|
constructor(JSON, owner, member) {
|
||||||
if (JSON === -1) {
|
if (JSON === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
if (!this.owner) {
|
|
||||||
console.error("localuser was not included, please fix");
|
|
||||||
}
|
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
this.channelids = {};
|
this.channelids = {};
|
||||||
this.id = JSON.id;
|
this.id = JSON.id;
|
||||||
|
@ -74,6 +72,7 @@ class Guild {
|
||||||
this.roles.push(roleh);
|
this.roles.push(roleh);
|
||||||
this.roleids[roleh.id] = roleh;
|
this.roleids[roleh.id] = roleh;
|
||||||
}
|
}
|
||||||
|
Member.resolve(member, this).then(_ => this.member = _);
|
||||||
for (const thing of JSON.channels) {
|
for (const thing of JSON.channels) {
|
||||||
const temp = new Channel(thing, this);
|
const temp = new Channel(thing, this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
|
@ -353,19 +352,10 @@ class Guild {
|
||||||
body: JSON.stringify(build)
|
body: JSON.stringify(build)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fillMember(member) {
|
|
||||||
const realroles = [];
|
|
||||||
for (const thing of member.roles) {
|
|
||||||
realroles.push(this.getRole(thing));
|
|
||||||
}
|
|
||||||
member.roles = realroles;
|
|
||||||
return member;
|
|
||||||
}
|
|
||||||
giveMember(member) {
|
|
||||||
this.fillMember(member);
|
|
||||||
this.member = member;
|
|
||||||
}
|
|
||||||
getRole(ID) {
|
getRole(ID) {
|
||||||
|
if (!this.roleids[ID]) {
|
||||||
|
console.error(`role id ${ID} does not exist`, this.roleids);
|
||||||
|
}
|
||||||
return this.roleids[ID];
|
return this.roleids[ID];
|
||||||
}
|
}
|
||||||
hasRole(r) {
|
hasRole(r) {
|
||||||
|
|
|
@ -128,11 +128,12 @@ async function enter(event) {
|
||||||
channel.editing = null;
|
channel.editing = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
replyingto = thisuser.channelfocus.replyingto;
|
||||||
let replying = replyingto?.all;
|
let replying = replyingto?.all;
|
||||||
if (replyingto) {
|
if (replyingto) {
|
||||||
replyingto.classList.remove("replying");
|
replyingto.classList.remove("replying");
|
||||||
}
|
}
|
||||||
replyingto = false;
|
thisuser.channelfocus.replyingto = null;
|
||||||
channel.sendMessage(typebox.value, {
|
channel.sendMessage(typebox.value, {
|
||||||
attachments: images,
|
attachments: images,
|
||||||
replyingto: replying,
|
replyingto: replying,
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { Guild } from "./guild.js";
|
||||||
import { Direct } from "./direct.js";
|
import { Direct } from "./direct.js";
|
||||||
import { Voice } from "./audio.js";
|
import { Voice } from "./audio.js";
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
import { Member } from "./member.js";
|
|
||||||
import { markdown } from "./markdown.js";
|
import { markdown } from "./markdown.js";
|
||||||
import { Fullscreen } from "./fullscreen.js";
|
import { Fullscreen } from "./fullscreen.js";
|
||||||
import { setTheme } from "./login.js";
|
import { setTheme } from "./login.js";
|
||||||
|
@ -48,8 +47,12 @@ class Localuser {
|
||||||
this.channelfocus = null;
|
this.channelfocus = null;
|
||||||
this.lookingguild = null;
|
this.lookingguild = null;
|
||||||
this.guildhtml = {};
|
this.guildhtml = {};
|
||||||
|
const members = {};
|
||||||
|
for (const thing of ready.d.merged_members) {
|
||||||
|
members[thing[0].guild_id] = thing[0];
|
||||||
|
}
|
||||||
for (const thing of ready.d.guilds) {
|
for (const thing of ready.d.guilds) {
|
||||||
const temp = new Guild(thing, this);
|
const temp = new Guild(thing, this, members[thing.id]);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id] = temp;
|
this.guildids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
|
@ -62,11 +65,6 @@ class Localuser {
|
||||||
for (const thing of ready.d.user_guild_settings.entries) {
|
for (const thing of ready.d.user_guild_settings.entries) {
|
||||||
this.guildids[thing.guild_id].notisetting(thing);
|
this.guildids[thing.guild_id].notisetting(thing);
|
||||||
}
|
}
|
||||||
for (const thing of ready.d.merged_members) {
|
|
||||||
const guild = this.guildids[thing[0].guild_id];
|
|
||||||
const temp = new Member(thing[0], guild);
|
|
||||||
guild.giveMember(temp);
|
|
||||||
}
|
|
||||||
for (const thing of ready.d.read_state.entries) {
|
for (const thing of ready.d.read_state.entries) {
|
||||||
const guild = this.resolveChannelFromID(thing.id).guild;
|
const guild = this.resolveChannelFromID(thing.id).guild;
|
||||||
if (guild === undefined) {
|
if (guild === undefined) {
|
||||||
|
@ -130,6 +128,10 @@ class Localuser {
|
||||||
this.messageCreate(temp);
|
this.messageCreate(temp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "MESSAGE_DELETE":
|
||||||
|
console.log(temp.d);
|
||||||
|
this.guildids[temp.d.guild_id].channelids[temp.d.channel_id].messageids[temp.d.id].deleteEvent();
|
||||||
|
break;
|
||||||
case "READY":
|
case "READY":
|
||||||
this.gottenReady(temp);
|
this.gottenReady(temp);
|
||||||
this.genusersettings();
|
this.genusersettings();
|
||||||
|
@ -193,7 +195,7 @@ class Localuser {
|
||||||
}
|
}
|
||||||
case "GUILD_CREATE":
|
case "GUILD_CREATE":
|
||||||
{
|
{
|
||||||
const guildy = new Guild(temp.d, this);
|
const guildy = new Guild(temp.d, this, this.user);
|
||||||
this.guilds.push(guildy);
|
this.guilds.push(guildy);
|
||||||
this.guildids[guildy.id] = guildy;
|
this.guildids[guildy.id] = guildy;
|
||||||
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseperator"));
|
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseperator"));
|
||||||
|
@ -236,7 +238,6 @@ class Localuser {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resolveChannelFromID(ID) {
|
resolveChannelFromID(ID) {
|
||||||
console.log(this.guilds.find(guild => guild.channelids[ID]).channelids);
|
|
||||||
let resolve = this.guilds.find(guild => guild.channelids[ID]).channelids[ID];
|
let resolve = this.guilds.find(guild => guild.channelids[ID]).channelids[ID];
|
||||||
resolve ??= undefined;
|
resolve ??= undefined;
|
||||||
return resolve;
|
return resolve;
|
||||||
|
|
|
@ -1,27 +1,45 @@
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
|
import { Guild } from "./guild.js";
|
||||||
class Member {
|
class Member {
|
||||||
static already = {};
|
static already = {};
|
||||||
owner;
|
owner;
|
||||||
user;
|
user;
|
||||||
roles;
|
roles;
|
||||||
constructor(memberjson, owner) {
|
error;
|
||||||
if (!owner) {
|
constructor(memberjson, owner, error = false) {
|
||||||
console.error("Guild not included in the creation of a member object");
|
this.error = error;
|
||||||
}
|
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
let membery = memberjson;
|
let membery = memberjson;
|
||||||
|
this.roles = [];
|
||||||
|
if (!error) {
|
||||||
if (memberjson.guild_member) {
|
if (memberjson.guild_member) {
|
||||||
membery = memberjson.guild_member;
|
membery = memberjson.guild_member;
|
||||||
this.user = memberjson.user;
|
this.user = memberjson.user;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (const thing of Object.keys(membery)) {
|
for (const thing of Object.keys(membery)) {
|
||||||
if (thing === "guild") {
|
if (thing === "guild") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (thing === "owner") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (thing === "roles") {
|
||||||
|
for (const strrole of membery["roles"]) {
|
||||||
|
const role = this.guild.getRole(strrole);
|
||||||
|
this.roles.push(role);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this[thing] = membery[thing];
|
this[thing] = membery[thing];
|
||||||
}
|
}
|
||||||
|
if (error) {
|
||||||
|
this.user = memberjson;
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.user = new User(this.user, owner.localuser);
|
this.user = new User(this.user, owner.localuser);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
get guild() {
|
get guild() {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +49,17 @@ class Member {
|
||||||
get info() {
|
get info() {
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
static async resolve(user, guild) {
|
static async resolve(unkown, guild) {
|
||||||
|
if (!(guild instanceof Guild)) {
|
||||||
|
console.error(guild);
|
||||||
|
}
|
||||||
|
let user;
|
||||||
|
if (unkown instanceof User) {
|
||||||
|
user = unkown;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new Member(unkown, guild);
|
||||||
|
}
|
||||||
if (guild.id === "@me") {
|
if (guild.id === "@me") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -48,13 +76,19 @@ class Member {
|
||||||
const promoise = fetch(guild.info.api.toString() + "/v9/users/" + user.id + "/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id=" + guild.id, { headers: guild.headers }).then(_ => _.json()).then(json => {
|
const promoise = fetch(guild.info.api.toString() + "/v9/users/" + user.id + "/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id=" + guild.id, { headers: guild.headers }).then(_ => _.json()).then(json => {
|
||||||
const memb = new Member(json, guild);
|
const memb = new Member(json, guild);
|
||||||
Member.already[guild.id][user.id] = memb;
|
Member.already[guild.id][user.id] = memb;
|
||||||
guild.fillMember(memb);
|
|
||||||
console.log("resolved");
|
console.log("resolved");
|
||||||
return memb;
|
return memb;
|
||||||
});
|
});
|
||||||
Member.already[guild.id][user.id] = promoise;
|
Member.already[guild.id][user.id] = promoise;
|
||||||
|
try {
|
||||||
return await promoise;
|
return await promoise;
|
||||||
}
|
}
|
||||||
|
catch (_) {
|
||||||
|
const memb = new Member(user, guild, true);
|
||||||
|
Member.already[guild.id][user.id] = memb;
|
||||||
|
return memb;
|
||||||
|
}
|
||||||
|
}
|
||||||
hasRole(ID) {
|
hasRole(ID) {
|
||||||
console.log(this.roles, ID);
|
console.log(this.roles, ID);
|
||||||
for (const thing of this.roles) {
|
for (const thing of this.roles) {
|
||||||
|
@ -74,6 +108,11 @@ class Member {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
isAdmin() {
|
isAdmin() {
|
||||||
|
for (const role of this.roles) {
|
||||||
|
if (role.permissions.getPermision("ADMINISTRATOR")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return this.guild.properties.owner_id === this.user.id;
|
return this.guild.properties.owner_id === this.user.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,25 @@ class Message {
|
||||||
author;
|
author;
|
||||||
mentions;
|
mentions;
|
||||||
mention_roles;
|
mention_roles;
|
||||||
attachments;
|
attachments; //probably should be its own class tbh, should be Attachments[]
|
||||||
id;
|
id;
|
||||||
message_reference;
|
message_reference;
|
||||||
type;
|
type;
|
||||||
timestamp;
|
timestamp;
|
||||||
content;
|
content;
|
||||||
|
static del;
|
||||||
|
static resolve;
|
||||||
|
div;
|
||||||
|
static setup() {
|
||||||
|
this.del = new Promise(_ => { this.resolve = _; });
|
||||||
|
Message.setupcmenu();
|
||||||
|
}
|
||||||
|
static async wipeChanel() {
|
||||||
|
this.resolve();
|
||||||
|
document.getElementById("messages").innerHTML = "";
|
||||||
|
await Promise.allSettled([this.resolve]);
|
||||||
|
this.del = new Promise(_ => { this.resolve = _; });
|
||||||
|
}
|
||||||
static setupcmenu() {
|
static setupcmenu() {
|
||||||
Message.contextmenu.addbutton("Copy raw text", function () {
|
Message.contextmenu.addbutton("Copy raw text", function () {
|
||||||
navigator.clipboard.writeText(this.content);
|
navigator.clipboard.writeText(this.content);
|
||||||
|
@ -46,6 +59,9 @@ class Message {
|
||||||
this.channel.editing = this;
|
this.channel.editing = this;
|
||||||
document.getElementById("typebox").value = this.content;
|
document.getElementById("typebox").value = this.content;
|
||||||
}, null, _ => { return _.author.id === _.localuser.user.id; });
|
}, null, _ => { return _.author.id === _.localuser.user.id; });
|
||||||
|
Message.contextmenu.addbutton("Delete message", function () {
|
||||||
|
this.delete();
|
||||||
|
}, null, _ => { return _.canDelete(); });
|
||||||
}
|
}
|
||||||
constructor(messagejson, owner) {
|
constructor(messagejson, owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -68,6 +84,9 @@ class Message {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
canDelete() {
|
||||||
|
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.id === this.localuser.user.id;
|
||||||
|
}
|
||||||
get channel() {
|
get channel() {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +100,12 @@ class Message {
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
messageevents(obj) {
|
messageevents(obj) {
|
||||||
Message.contextmenu.bind(obj, this);
|
const func = Message.contextmenu.bind(obj, this);
|
||||||
|
this.div = obj;
|
||||||
|
Message.del.then(_ => {
|
||||||
|
obj.removeEventListener("click", func);
|
||||||
|
this.div = null;
|
||||||
|
});
|
||||||
obj.classList.add("messagediv");
|
obj.classList.add("messagediv");
|
||||||
}
|
}
|
||||||
mentionsuser(userd) {
|
mentionsuser(userd) {
|
||||||
|
@ -108,10 +132,32 @@ class Message {
|
||||||
body: JSON.stringify({ content: content })
|
body: JSON.stringify({ content: content })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
buildhtml(premessage) {
|
delete() {
|
||||||
//premessage??=messages.lastChild;
|
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id}`, {
|
||||||
|
headers: this.headers,
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
deleteEvent() {
|
||||||
|
if (this.div) {
|
||||||
|
this.div.innerHTML = "";
|
||||||
|
this.div = null;
|
||||||
|
}
|
||||||
|
const index = this.channel.messages.indexOf(this);
|
||||||
|
this.channel.messages.splice(this.channel.messages.indexOf(this), 1);
|
||||||
|
delete this.channel.messageids[this.id];
|
||||||
|
const regen = this.channel.messages[index - 1];
|
||||||
|
if (regen) {
|
||||||
|
regen.generateMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generateMessage(premessage = null) {
|
||||||
|
if (!premessage) {
|
||||||
|
premessage = this.channel.messages[this.channel.messages.indexOf(this) + 1];
|
||||||
|
}
|
||||||
|
const div = this.div;
|
||||||
|
div.innerHTML = "";
|
||||||
const build = document.createElement('table');
|
const build = document.createElement('table');
|
||||||
const div = document.createElement("div");
|
|
||||||
if (this.message_reference) {
|
if (this.message_reference) {
|
||||||
const replyline = document.createElement("div");
|
const replyline = document.createElement("div");
|
||||||
const line = document.createElement("hr");
|
const line = document.createElement("hr");
|
||||||
|
@ -124,7 +170,23 @@ class Message {
|
||||||
const reply = document.createElement("div");
|
const reply = document.createElement("div");
|
||||||
username.classList.add("username");
|
username.classList.add("username");
|
||||||
Member.resolve(this.author, this.guild).then(_ => {
|
Member.resolve(this.author, this.guild).then(_ => {
|
||||||
|
if (!_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
console.log(_.error);
|
||||||
|
if (_.error) {
|
||||||
|
username.textContent += "Error";
|
||||||
|
alert("Should've gotten here");
|
||||||
|
const error = document.createElement("span");
|
||||||
|
error.textContent = "!";
|
||||||
|
error.classList.add("membererror");
|
||||||
|
username.after(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
username.style.color = _.getColor();
|
username.style.color = _.getColor();
|
||||||
|
}).catch(_ => {
|
||||||
|
console.log(_);
|
||||||
});
|
});
|
||||||
reply.classList.add("replytext");
|
reply.classList.add("replytext");
|
||||||
replyline.appendChild(reply);
|
replyline.appendChild(reply);
|
||||||
|
@ -150,7 +212,6 @@ class Message {
|
||||||
const pfpRow = document.createElement('th');
|
const pfpRow = document.createElement('th');
|
||||||
let pfpparent, current;
|
let pfpparent, current;
|
||||||
if (premessage != null) {
|
if (premessage != null) {
|
||||||
pfpparent = premessage.pfpparent;
|
|
||||||
pfpparent ??= premessage;
|
pfpparent ??= premessage;
|
||||||
let pfpparent2 = pfpparent.all;
|
let pfpparent2 = pfpparent.all;
|
||||||
pfpparent2 ??= pfpparent;
|
pfpparent2 ??= pfpparent;
|
||||||
|
@ -158,7 +219,7 @@ class Message {
|
||||||
const newt = (new Date(this.timestamp).getTime()) / 1000;
|
const newt = (new Date(this.timestamp).getTime()) / 1000;
|
||||||
current = (newt - old) > 600;
|
current = (newt - old) > 600;
|
||||||
}
|
}
|
||||||
const combine = (premessage?.userid != this.author.id && premessage?.author?.id != this.author.id) || (current) || this.message_reference;
|
const combine = (premessage?.author?.id != this.author.id) || (current) || this.message_reference;
|
||||||
if (combine) {
|
if (combine) {
|
||||||
const pfp = this.author.buildpfp();
|
const pfp = this.author.buildpfp();
|
||||||
this.author.profileclick(pfp);
|
this.author.profileclick(pfp);
|
||||||
|
@ -181,6 +242,14 @@ class Message {
|
||||||
if (!_) {
|
if (!_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
if (_.error) {
|
||||||
|
const error = document.createElement("span");
|
||||||
|
error.textContent = "!";
|
||||||
|
error.classList.add("membererror");
|
||||||
|
username.after(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
username.style.color = _.getColor();
|
username.style.color = _.getColor();
|
||||||
});
|
});
|
||||||
username.textContent = this.author.username;
|
username.textContent = this.author.username;
|
||||||
|
@ -254,10 +323,19 @@ class Message {
|
||||||
messagedwrap.append(time);
|
messagedwrap.append(time);
|
||||||
texttxt.appendChild(messagedwrap);
|
texttxt.appendChild(messagedwrap);
|
||||||
}
|
}
|
||||||
div["userid"] = this.author.id;
|
|
||||||
div["all"] = this;
|
div["all"] = this;
|
||||||
return (div);
|
return (div);
|
||||||
}
|
}
|
||||||
|
buildhtml(premessage) {
|
||||||
|
if (this.div) {
|
||||||
|
console.error(`HTML for ${this} already exists, aborting`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//premessage??=messages.lastChild;
|
||||||
|
const div = document.createElement("div");
|
||||||
|
this.div = div;
|
||||||
|
return this.generateMessage(premessage);
|
||||||
|
}
|
||||||
createunknown(fname, fsize, src) {
|
createunknown(fname, fsize, src) {
|
||||||
const div = document.createElement("table");
|
const div = document.createElement("table");
|
||||||
div.classList.add("unknownfile");
|
div.classList.add("unknownfile");
|
||||||
|
@ -314,5 +392,5 @@ function formatTime(date) {
|
||||||
return `${date.toLocaleDateString()} at ${formatTime(date)}`;
|
return `${date.toLocaleDateString()} at ${formatTime(date)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message.setupcmenu();
|
Message.setup();
|
||||||
export { Message };
|
export { Message };
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {markdown} from "./markdown.js";
|
||||||
import {Guild} from "./guild.js";
|
import {Guild} from "./guild.js";
|
||||||
import { Localuser } from "./localuser.js";
|
import { Localuser } from "./localuser.js";
|
||||||
import { Permissions } from "./permissions.js";
|
import { Permissions } from "./permissions.js";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface NotificationOptions {
|
interface NotificationOptions {
|
||||||
image?: string
|
image?: string
|
||||||
|
@ -38,6 +39,7 @@ class Channel{
|
||||||
message_notifications:number;
|
message_notifications:number;
|
||||||
allthewayup:boolean;
|
allthewayup:boolean;
|
||||||
static contextmenu=new Contextmenu("channel menu");
|
static contextmenu=new Contextmenu("channel menu");
|
||||||
|
replyingto:HTMLDivElement;
|
||||||
static setupcontextmenu(){
|
static setupcontextmenu(){
|
||||||
Channel.contextmenu.addbutton("Copy channel id",function(){
|
Channel.contextmenu.addbutton("Copy channel id",function(){
|
||||||
console.log(this)
|
console.log(this)
|
||||||
|
@ -79,7 +81,6 @@ class Channel{
|
||||||
for(const thing of JSON.permission_overwrites){
|
for(const thing of JSON.permission_overwrites){
|
||||||
this.permission_overwrites[thing.id]=new Permissions(thing.allow,thing.deny);
|
this.permission_overwrites[thing.id]=new Permissions(thing.allow,thing.deny);
|
||||||
}
|
}
|
||||||
console.log(this.permission_overwrites)
|
|
||||||
this.topic=JSON.topic;
|
this.topic=JSON.topic;
|
||||||
this.nsfw=JSON.nsfw;
|
this.nsfw=JSON.nsfw;
|
||||||
this.position=JSON.position;
|
this.position=JSON.position;
|
||||||
|
@ -104,21 +105,29 @@ class Channel{
|
||||||
this.mentions??=0;
|
this.mentions??=0;
|
||||||
this.lastpin=json.last_pin_timestamp;
|
this.lastpin=json.last_pin_timestamp;
|
||||||
}
|
}
|
||||||
get hasunreads(){
|
get hasunreads():boolean{
|
||||||
|
if(!this.hasPermission("VIEW_CHANNEL")){return false;}
|
||||||
return this.lastmessageid!==this.lastreadmessageid&&this.type!==4;
|
return this.lastmessageid!==this.lastreadmessageid&&this.type!==4;
|
||||||
}
|
}
|
||||||
get canMessage(){
|
hasPermission(name:string,member=this.guild.member):boolean{
|
||||||
console.log("this should run");
|
if(member.isAdmin()){
|
||||||
for(const thing of Object.entries(this.permission_overwrites)){
|
return true;
|
||||||
const perm=thing[1].getPermision("SEND_MESSAGES");
|
}
|
||||||
if(perm===1){
|
for(const thing of member.roles){
|
||||||
return true
|
if(this.permission_overwrites[thing.id]){
|
||||||
|
let perm=this.permission_overwrites[thing.id].getPermision(name);
|
||||||
|
if(perm){
|
||||||
|
return perm===1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(thing.permissions.getPermision(name)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(perm===-1){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
get canMessage():boolean{
|
||||||
return true;
|
return this.hasPermission("SEND_MESSAGES");
|
||||||
}
|
}
|
||||||
sortchildren(){
|
sortchildren(){
|
||||||
this.children.sort((a,b)=>{return a.position-b.position});
|
this.children.sort((a,b)=>{return a.position-b.position});
|
||||||
|
@ -153,8 +162,19 @@ class Channel{
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
static dragged=[];
|
static dragged=[];
|
||||||
createguildHTML(admin=false){
|
createguildHTML(admin=false):HTMLDivElement{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
|
if(!this.hasPermission("VIEW_CHANNEL")){
|
||||||
|
let quit=true
|
||||||
|
for(const thing of this.children){
|
||||||
|
if(thing.hasPermission("VIEW_CHANNEL")){
|
||||||
|
quit=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(quit){
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
}
|
||||||
div["all"]=this;
|
div["all"]=this;
|
||||||
div.draggable=admin;
|
div.draggable=admin;
|
||||||
div.addEventListener("dragstart",(e)=>{Channel.dragged=[this,div];e.stopImmediatePropagation()})
|
div.addEventListener("dragstart",(e)=>{Channel.dragged=[this,div];e.stopImmediatePropagation()})
|
||||||
|
@ -392,34 +412,35 @@ class Channel{
|
||||||
headers:this.headers
|
headers:this.headers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
getHTML(){
|
async getHTML(){
|
||||||
if(this.guild!==this.localuser.lookingguild){
|
if(this.guild!==this.localuser.lookingguild){
|
||||||
this.guild.loadGuild();
|
this.guild.loadGuild();
|
||||||
}
|
}
|
||||||
this.guild.prevchannel=this;
|
this.guild.prevchannel=this;
|
||||||
this.localuser.channelfocus=this;
|
this.localuser.channelfocus=this;
|
||||||
this.putmessages();
|
const prom=Message.wipeChanel();
|
||||||
|
await this.putmessages();
|
||||||
|
await prom;
|
||||||
|
this.buildmessages();
|
||||||
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
||||||
document.getElementById("channelname").textContent="#"+this.name;
|
document.getElementById("channelname").textContent="#"+this.name;
|
||||||
console.log(this);
|
console.log(this);
|
||||||
(document.getElementById("typebox") as HTMLInputElement).disabled=!this.canMessage;
|
(document.getElementById("typebox") as HTMLInputElement).disabled=!this.canMessage;
|
||||||
}
|
}
|
||||||
putmessages(){
|
async putmessages(){
|
||||||
const out=this;
|
if(this.messages.length>=100){return};
|
||||||
fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{
|
const j=await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
}).then((j)=>{return j.json()}).then(responce=>{
|
})
|
||||||
document.getElementById("messages").innerHTML = '';
|
const responce=await j.json();
|
||||||
for(const thing of responce){
|
for(const thing of responce){
|
||||||
const messager=new Message(thing,this)
|
const messager=new Message(thing,this)
|
||||||
if(out.messageids[messager.id]==undefined){
|
if(this.messageids[messager.id]===undefined){
|
||||||
out.messageids[messager.id]=messager;
|
this.messageids[messager.id]=messager;
|
||||||
out.messages.push(messager);
|
this.messages.push(messager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.buildmessages();
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
delChannel(JSON){
|
delChannel(JSON){
|
||||||
const build=[];
|
const build=[];
|
||||||
|
@ -569,6 +590,7 @@ class Channel{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageCreate(messagep:any):void{
|
messageCreate(messagep:any):void{
|
||||||
|
if(!this.hasPermission("VIEW_CHANNEL")){return}
|
||||||
const messagez=new Message(messagep.d,this);
|
const messagez=new Message(messagep.d,this);
|
||||||
this.lastmessageid=messagez.id;
|
this.lastmessageid=messagez.id;
|
||||||
if(messagez.author===this.localuser.user){
|
if(messagez.author===this.localuser.user){
|
||||||
|
|
|
@ -50,11 +50,16 @@ class Contextmenu{
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
bind(obj:HTMLElement,addinfo:any=undefined){
|
bind(obj:HTMLElement,addinfo:any=undefined){
|
||||||
obj.addEventListener("contextmenu", (event) => {
|
const func=(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
this.makemenu(event.clientX,event.clientY,addinfo,obj)
|
this.makemenu(event.clientX,event.clientY,addinfo,obj)
|
||||||
});
|
}
|
||||||
|
obj.addEventListener("contextmenu", func);
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
static keepOnScreen(obj:HTMLElement){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
|
|
|
@ -3,10 +3,11 @@ import { Channel } from "./channel.js";
|
||||||
import { Message } from "./message.js";
|
import { Message } from "./message.js";
|
||||||
import { Localuser } from "./localuser.js";
|
import { Localuser } from "./localuser.js";
|
||||||
import {User} from "./user.js";
|
import {User} from "./user.js";
|
||||||
|
import { Member } from "./member.js";
|
||||||
|
|
||||||
class Direct extends Guild{
|
class Direct extends Guild{
|
||||||
constructor(JSON,owner:Localuser){
|
constructor(JSON,owner:Localuser){
|
||||||
super(-1,owner);
|
super(-1,owner,null);
|
||||||
this.message_notifications=0;
|
this.message_notifications=0;
|
||||||
console.log(JSON);
|
console.log(JSON);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
|
@ -98,10 +99,16 @@ class Group extends Channel{
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
getHTML(){
|
async getHTML(){
|
||||||
|
if(this.guild!==this.localuser.lookingguild){
|
||||||
|
this.guild.loadGuild();
|
||||||
|
}
|
||||||
|
const prom=Message.wipeChanel();
|
||||||
this.guild.prevchannel=this;
|
this.guild.prevchannel=this;
|
||||||
this.localuser.channelfocus=this;
|
this.localuser.channelfocus=this;
|
||||||
this.putmessages();
|
await this.putmessages();
|
||||||
|
await prom;
|
||||||
|
this.buildmessages();
|
||||||
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
||||||
document.getElementById("channelname").textContent="@"+this.name;
|
document.getElementById("channelname").textContent="@"+this.name;
|
||||||
}
|
}
|
||||||
|
@ -183,5 +190,11 @@ class Group extends Channel{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isAdmin(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
hasPermission(name: string, member?: Member): boolean {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export {Direct, Group};
|
export {Direct, Group};
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Guild{
|
||||||
roles:Role[];
|
roles:Role[];
|
||||||
roleids:{[key:string]:Role};
|
roleids:{[key:string]:Role};
|
||||||
prevchannel:Channel;
|
prevchannel:Channel;
|
||||||
message_notifications
|
message_notifications:number;
|
||||||
headchannels:Channel[];
|
headchannels:Channel[];
|
||||||
position:number;
|
position:number;
|
||||||
parent_id:string;
|
parent_id:string;
|
||||||
|
@ -60,16 +60,13 @@ class Guild{
|
||||||
},null,_=>{return thisuser.isAdmin()})
|
},null,_=>{return thisuser.isAdmin()})
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
constructor(JSON,owner:Localuser){
|
constructor(JSON,owner:Localuser,member){
|
||||||
|
|
||||||
if(JSON===-1){
|
if(JSON===-1){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
if(!this.owner){
|
|
||||||
console.error("localuser was not included, please fix")
|
|
||||||
}
|
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.id=JSON.id;
|
this.id=JSON.id;
|
||||||
|
@ -83,6 +80,7 @@ class Guild{
|
||||||
this.roles.push(roleh)
|
this.roles.push(roleh)
|
||||||
this.roleids[roleh.id]=roleh;
|
this.roleids[roleh.id]=roleh;
|
||||||
}
|
}
|
||||||
|
Member.resolve(member,this).then(_=>this.member=_);
|
||||||
for(const thing of JSON.channels){
|
for(const thing of JSON.channels){
|
||||||
const temp=new Channel(thing,this);
|
const temp=new Channel(thing,this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
|
@ -360,19 +358,8 @@ class Guild{
|
||||||
body:JSON.stringify(build)
|
body:JSON.stringify(build)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fillMember(member:Member){
|
getRole(ID:string):Role{
|
||||||
const realroles=[];
|
if(!this.roleids[ID]){console.error(`role id ${ID} does not exist`,this.roleids)}
|
||||||
for(const thing of member.roles){
|
|
||||||
realroles.push(this.getRole(thing));
|
|
||||||
}
|
|
||||||
member.roles=realroles;
|
|
||||||
return member;
|
|
||||||
}
|
|
||||||
giveMember(member:Member){
|
|
||||||
this.fillMember(member);
|
|
||||||
this.member=member;
|
|
||||||
}
|
|
||||||
getRole(ID){
|
|
||||||
return this.roleids[ID];
|
return this.roleids[ID];
|
||||||
}
|
}
|
||||||
hasRole(r:Role|string){
|
hasRole(r:Role|string){
|
||||||
|
@ -382,7 +369,7 @@ class Guild{
|
||||||
}
|
}
|
||||||
return this.member.hasRole(r as string);
|
return this.member.hasRole(r as string);
|
||||||
}
|
}
|
||||||
loadChannel(ID=undefined){
|
loadChannel(ID:string=undefined){
|
||||||
if(ID&&this.channelids[ID]){
|
if(ID&&this.channelids[ID]){
|
||||||
this.channelids[ID].getHTML();
|
this.channelids[ID].getHTML();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -142,11 +142,12 @@ async function enter(event){
|
||||||
channel.editing.edit((typebox).value);
|
channel.editing.edit((typebox).value);
|
||||||
channel.editing=null;
|
channel.editing=null;
|
||||||
}else{
|
}else{
|
||||||
|
replyingto= thisuser.channelfocus.replyingto;
|
||||||
let replying=replyingto?.all;
|
let replying=replyingto?.all;
|
||||||
if(replyingto){
|
if(replyingto){
|
||||||
replyingto.classList.remove("replying");
|
replyingto.classList.remove("replying");
|
||||||
}
|
}
|
||||||
replyingto=false;
|
thisuser.channelfocus.replyingto=null;
|
||||||
channel.sendMessage(typebox.value,{
|
channel.sendMessage(typebox.value,{
|
||||||
attachments:images,
|
attachments:images,
|
||||||
replyingto:replying,
|
replyingto:replying,
|
||||||
|
|
|
@ -49,8 +49,13 @@ class Localuser{
|
||||||
this.channelfocus=null;
|
this.channelfocus=null;
|
||||||
this.lookingguild=null;
|
this.lookingguild=null;
|
||||||
this.guildhtml={};
|
this.guildhtml={};
|
||||||
|
const members={};
|
||||||
|
for(const thing of ready.d.merged_members){
|
||||||
|
members[thing[0].guild_id]=thing[0];
|
||||||
|
}
|
||||||
|
|
||||||
for(const thing of ready.d.guilds){
|
for(const thing of ready.d.guilds){
|
||||||
const temp=new Guild(thing,this);
|
const temp=new Guild(thing,this,members[thing.id]);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id]=temp;
|
this.guildids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
|
@ -59,15 +64,13 @@ class Localuser{
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id]=temp;
|
this.guildids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
console.log(ready.d.user_guild_settings.entries)
|
console.log(ready.d.user_guild_settings.entries);
|
||||||
|
|
||||||
|
|
||||||
for(const thing of ready.d.user_guild_settings.entries){
|
for(const thing of ready.d.user_guild_settings.entries){
|
||||||
this.guildids[thing.guild_id].notisetting(thing);
|
this.guildids[thing.guild_id].notisetting(thing);
|
||||||
}
|
}
|
||||||
for(const thing of ready.d.merged_members){
|
|
||||||
const guild=this.guildids[thing[0].guild_id]
|
|
||||||
const temp=new Member(thing[0],guild);
|
|
||||||
guild.giveMember(temp);
|
|
||||||
}
|
|
||||||
for(const thing of ready.d.read_state.entries){
|
for(const thing of ready.d.read_state.entries){
|
||||||
const guild=this.resolveChannelFromID(thing.id).guild;
|
const guild=this.resolveChannelFromID(thing.id).guild;
|
||||||
if(guild===undefined){
|
if(guild===undefined){
|
||||||
|
@ -134,6 +137,10 @@ class Localuser{
|
||||||
this.messageCreate(temp);
|
this.messageCreate(temp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "MESSAGE_DELETE":
|
||||||
|
console.log(temp.d);
|
||||||
|
this.guildids[temp.d.guild_id].channelids[temp.d.channel_id].messageids[temp.d.id].deleteEvent();
|
||||||
|
break;
|
||||||
case "READY":
|
case "READY":
|
||||||
this.gottenReady(temp);
|
this.gottenReady(temp);
|
||||||
this.genusersettings();
|
this.genusersettings();
|
||||||
|
@ -196,7 +203,7 @@ class Localuser{
|
||||||
}
|
}
|
||||||
case "GUILD_CREATE":
|
case "GUILD_CREATE":
|
||||||
{
|
{
|
||||||
const guildy=new Guild(temp.d,this);
|
const guildy=new Guild(temp.d,this,this.user);
|
||||||
this.guilds.push(guildy);
|
this.guilds.push(guildy);
|
||||||
this.guildids[guildy.id]=guildy;
|
this.guildids[guildy.id]=guildy;
|
||||||
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(),document.getElementById("bottomseperator"));
|
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(),document.getElementById("bottomseperator"));
|
||||||
|
@ -239,7 +246,6 @@ class Localuser{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resolveChannelFromID(ID:string):Channel{
|
resolveChannelFromID(ID:string):Channel{
|
||||||
console.log(this.guilds.find(guild => guild.channelids[ID]).channelids)
|
|
||||||
let resolve=this.guilds.find(guild => guild.channelids[ID]).channelids[ID];
|
let resolve=this.guilds.find(guild => guild.channelids[ID]).channelids[ID];
|
||||||
resolve??=undefined;
|
resolve??=undefined;
|
||||||
return resolve;
|
return resolve;
|
||||||
|
|
|
@ -6,20 +6,36 @@ class Member{
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
user:User;
|
user:User;
|
||||||
roles:Role[];
|
roles:Role[];
|
||||||
constructor(memberjson,owner:Guild){
|
error:boolean;
|
||||||
if(!owner){console.error("Guild not included in the creation of a member object")}
|
constructor(memberjson,owner:Guild,error=false){
|
||||||
|
this.error=error;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
let membery=memberjson;
|
let membery=memberjson;
|
||||||
|
this.roles=[];
|
||||||
|
if(!error){
|
||||||
if(memberjson.guild_member){
|
if(memberjson.guild_member){
|
||||||
membery=memberjson.guild_member;
|
membery=memberjson.guild_member;
|
||||||
this.user=memberjson.user;
|
this.user=memberjson.user;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for(const thing of Object.keys(membery)){
|
for(const thing of Object.keys(membery)){
|
||||||
if(thing==="guild"){continue}
|
if(thing==="guild"){continue}
|
||||||
|
if(thing==="owner"){continue}
|
||||||
|
if(thing==="roles"){
|
||||||
|
for(const strrole of membery["roles"]){
|
||||||
|
const role=this.guild.getRole(strrole);
|
||||||
|
this.roles.push(role);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
this[thing]=membery[thing];
|
this[thing]=membery[thing];
|
||||||
}
|
}
|
||||||
|
if(error){
|
||||||
|
this.user=memberjson as User;
|
||||||
|
}else{
|
||||||
this.user=new User(this.user,owner.localuser);
|
this.user=new User(this.user,owner.localuser);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
get guild(){
|
get guild(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +45,16 @@ class Member{
|
||||||
get info(){
|
get info(){
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
static async resolve(user:User,guild:Guild){
|
static async resolve(unkown:User|object,guild:Guild):Promise<Member>{
|
||||||
|
if(!(guild instanceof Guild)){
|
||||||
|
console.error(guild)
|
||||||
|
}
|
||||||
|
let user:User;
|
||||||
|
if(unkown instanceof User){
|
||||||
|
user=unkown as User;
|
||||||
|
}else{
|
||||||
|
return new Member(unkown,guild);
|
||||||
|
}
|
||||||
if(guild.id==="@me"){return null}
|
if(guild.id==="@me"){return null}
|
||||||
if(!Member.already[guild.id]){
|
if(!Member.already[guild.id]){
|
||||||
Member.already[guild.id]={};
|
Member.already[guild.id]={};
|
||||||
|
@ -43,12 +68,17 @@ class Member{
|
||||||
const promoise= fetch(guild.info.api.toString()+"/v9/users/"+user.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+guild.id,{headers:guild.headers}).then(_=>_.json()).then(json=>{
|
const promoise= fetch(guild.info.api.toString()+"/v9/users/"+user.id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+guild.id,{headers:guild.headers}).then(_=>_.json()).then(json=>{
|
||||||
const memb=new Member(json,guild);
|
const memb=new Member(json,guild);
|
||||||
Member.already[guild.id][user.id]=memb;
|
Member.already[guild.id][user.id]=memb;
|
||||||
guild.fillMember(memb);
|
|
||||||
console.log("resolved")
|
console.log("resolved")
|
||||||
return memb
|
return memb
|
||||||
});
|
})
|
||||||
Member.already[guild.id][user.id]=promoise;
|
Member.already[guild.id][user.id]=promoise;
|
||||||
return await promoise;
|
try{
|
||||||
|
return await promoise
|
||||||
|
}catch(_){
|
||||||
|
const memb=new Member(user,guild,true);
|
||||||
|
Member.already[guild.id][user.id]=memb;
|
||||||
|
return memb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hasRole(ID:string){
|
hasRole(ID:string){
|
||||||
console.log(this.roles,ID);
|
console.log(this.roles,ID);
|
||||||
|
@ -69,6 +99,11 @@ class Member{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
isAdmin(){
|
isAdmin(){
|
||||||
|
for(const role of this.roles){
|
||||||
|
if(role.permissions.getPermision("ADMINISTRATOR")){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return this.guild.properties.owner_id===this.user.id;
|
return this.guild.properties.owner_id===this.user.id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,25 @@ class Message{
|
||||||
author:User;
|
author:User;
|
||||||
mentions:User[];
|
mentions:User[];
|
||||||
mention_roles:Role[];
|
mention_roles:Role[];
|
||||||
attachments;
|
attachments;//probably should be its own class tbh, should be Attachments[]
|
||||||
id:string;
|
id:string;
|
||||||
message_reference;
|
message_reference;
|
||||||
type:number;
|
type:number;
|
||||||
timestamp:number;
|
timestamp:number;
|
||||||
content;
|
content:string;
|
||||||
|
static del:Promise<void>;
|
||||||
|
static resolve:Function;
|
||||||
|
div:HTMLDivElement;
|
||||||
|
static setup(){
|
||||||
|
this.del=new Promise(_=>{this.resolve=_});
|
||||||
|
Message.setupcmenu();
|
||||||
|
}
|
||||||
|
static async wipeChanel(){
|
||||||
|
this.resolve();
|
||||||
|
document.getElementById("messages").innerHTML="";
|
||||||
|
await Promise.allSettled([this.resolve]);
|
||||||
|
this.del=new Promise(_=>{this.resolve=_})
|
||||||
|
}
|
||||||
static setupcmenu(){
|
static setupcmenu(){
|
||||||
Message.contextmenu.addbutton("Copy raw text",function(){
|
Message.contextmenu.addbutton("Copy raw text",function(){
|
||||||
navigator.clipboard.writeText(this.content);
|
navigator.clipboard.writeText(this.content);
|
||||||
|
@ -51,8 +64,11 @@ class Message{
|
||||||
this.channel.editing=this;
|
this.channel.editing=this;
|
||||||
(document.getElementById("typebox") as HTMLInputElement).value=this.content;
|
(document.getElementById("typebox") as HTMLInputElement).value=this.content;
|
||||||
},null,_=>{return _.author.id===_.localuser.user.id});
|
},null,_=>{return _.author.id===_.localuser.user.id});
|
||||||
|
Message.contextmenu.addbutton("Delete message",function(){
|
||||||
|
this.delete();
|
||||||
|
},null,_=>{return _.canDelete()})
|
||||||
}
|
}
|
||||||
constructor(messagejson,owner){
|
constructor(messagejson,owner:Channel){
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
for(const thing of Object.keys(messagejson)){
|
for(const thing of Object.keys(messagejson)){
|
||||||
|
@ -73,6 +89,9 @@ class Message{
|
||||||
console.log(this);
|
console.log(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
canDelete(){
|
||||||
|
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author.id===this.localuser.user.id;
|
||||||
|
}
|
||||||
get channel(){
|
get channel(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
@ -85,11 +104,16 @@ class Message{
|
||||||
get info(){
|
get info(){
|
||||||
return this.owner.info;
|
return this.owner.info;
|
||||||
}
|
}
|
||||||
messageevents(obj){
|
messageevents(obj:HTMLDivElement){
|
||||||
Message.contextmenu.bind(obj,this)
|
const func=Message.contextmenu.bind(obj,this);
|
||||||
obj.classList.add("messagediv")
|
this.div=obj;
|
||||||
|
Message.del.then(_=>{
|
||||||
|
obj.removeEventListener("click",func);
|
||||||
|
this.div=null;
|
||||||
|
})
|
||||||
|
obj.classList.add("messagediv");
|
||||||
}
|
}
|
||||||
mentionsuser(userd){
|
mentionsuser(userd:User|Member){
|
||||||
if(userd instanceof User){
|
if(userd instanceof User){
|
||||||
return this.mentions.includes(userd);
|
return this.mentions.includes(userd);
|
||||||
}else if(userd instanceof Member){
|
}else if(userd instanceof Member){
|
||||||
|
@ -112,11 +136,32 @@ class Message{
|
||||||
body:JSON.stringify({content:content})
|
body:JSON.stringify({content:content})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
buildhtml(premessage){
|
delete(){
|
||||||
//premessage??=messages.lastChild;
|
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id}`,{
|
||||||
|
headers:this.headers,
|
||||||
|
method:"DELETE",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
deleteEvent(){
|
||||||
|
if(this.div){
|
||||||
|
this.div.innerHTML="";
|
||||||
|
this.div=null;
|
||||||
|
}
|
||||||
|
const index=this.channel.messages.indexOf(this);
|
||||||
|
this.channel.messages.splice(this.channel.messages.indexOf(this),1);
|
||||||
|
delete this.channel.messageids[this.id];
|
||||||
|
const regen=this.channel.messages[index-1]
|
||||||
|
if(regen){
|
||||||
|
regen.generateMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
generateMessage(premessage:Message=null){
|
||||||
|
if(!premessage){
|
||||||
|
premessage=this.channel.messages[this.channel.messages.indexOf(this)+1];
|
||||||
|
}
|
||||||
|
const div=this.div;
|
||||||
|
div.innerHTML="";
|
||||||
const build = document.createElement('table');
|
const build = document.createElement('table');
|
||||||
const div=document.createElement("div");
|
|
||||||
|
|
||||||
if(this.message_reference){
|
if(this.message_reference){
|
||||||
const replyline=document.createElement("div");
|
const replyline=document.createElement("div");
|
||||||
const line=document.createElement("hr");
|
const line=document.createElement("hr");
|
||||||
|
@ -130,7 +175,21 @@ class Message{
|
||||||
username.classList.add("username");
|
username.classList.add("username");
|
||||||
|
|
||||||
Member.resolve(this.author,this.guild).then(_=>{
|
Member.resolve(this.author,this.guild).then(_=>{
|
||||||
|
if(!_) {return};
|
||||||
|
console.log(_.error);
|
||||||
|
if(_.error){
|
||||||
|
username.textContent+="Error";
|
||||||
|
alert("Should've gotten here")
|
||||||
|
const error=document.createElement("span");
|
||||||
|
error.textContent="!";
|
||||||
|
error.classList.add("membererror");
|
||||||
|
username.after(error);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
username.style.color=_.getColor();
|
username.style.color=_.getColor();
|
||||||
|
}).catch(_=>{
|
||||||
|
console.log(_)
|
||||||
});
|
});
|
||||||
|
|
||||||
reply.classList.add("replytext");
|
reply.classList.add("replytext");
|
||||||
|
@ -161,7 +220,6 @@ class Message{
|
||||||
|
|
||||||
let pfpparent, current
|
let pfpparent, current
|
||||||
if(premessage!=null){
|
if(premessage!=null){
|
||||||
pfpparent=premessage.pfpparent;
|
|
||||||
pfpparent??=premessage;
|
pfpparent??=premessage;
|
||||||
let pfpparent2=pfpparent.all;
|
let pfpparent2=pfpparent.all;
|
||||||
pfpparent2??=pfpparent;
|
pfpparent2??=pfpparent;
|
||||||
|
@ -169,7 +227,7 @@ class Message{
|
||||||
const newt=(new Date(this.timestamp).getTime())/1000;
|
const newt=(new Date(this.timestamp).getTime())/1000;
|
||||||
current=(newt-old)>600;
|
current=(newt-old)>600;
|
||||||
}
|
}
|
||||||
const combine=(premessage?.userid!=this.author.id&&premessage?.author?.id!=this.author.id)||(current)||this.message_reference
|
const combine=(premessage?.author?.id!=this.author.id)||(current)||this.message_reference
|
||||||
if(combine){
|
if(combine){
|
||||||
const pfp=this.author.buildpfp();
|
const pfp=this.author.buildpfp();
|
||||||
this.author.profileclick(pfp);
|
this.author.profileclick(pfp);
|
||||||
|
@ -189,7 +247,15 @@ class Message{
|
||||||
username.classList.add("username")
|
username.classList.add("username")
|
||||||
this.author.profileclick(username);
|
this.author.profileclick(username);
|
||||||
Member.resolve(this.author,this.guild).then(_=>{
|
Member.resolve(this.author,this.guild).then(_=>{
|
||||||
if(!_){return}
|
if(!_) {return};
|
||||||
|
if(_.error){
|
||||||
|
const error=document.createElement("span");
|
||||||
|
error.textContent="!";
|
||||||
|
error.classList.add("membererror");
|
||||||
|
username.after(error);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
username.style.color=_.getColor();
|
username.style.color=_.getColor();
|
||||||
})
|
})
|
||||||
username.textContent=this.author.username;
|
username.textContent=this.author.username;
|
||||||
|
@ -266,10 +332,16 @@ class Message{
|
||||||
|
|
||||||
texttxt.appendChild(messagedwrap)
|
texttxt.appendChild(messagedwrap)
|
||||||
}
|
}
|
||||||
div["userid"]=this.author.id;
|
|
||||||
div["all"]=this;
|
div["all"]=this;
|
||||||
return(div)
|
return(div)
|
||||||
}
|
}
|
||||||
|
buildhtml(premessage:Message){
|
||||||
|
if(this.div){console.error(`HTML for ${this} already exists, aborting`);return;}
|
||||||
|
//premessage??=messages.lastChild;
|
||||||
|
const div=document.createElement("div");
|
||||||
|
this.div=div;
|
||||||
|
return this.generateMessage(premessage);
|
||||||
|
}
|
||||||
createunknown(fname,fsize,src){
|
createunknown(fname,fsize,src){
|
||||||
const div=document.createElement("table");
|
const div=document.createElement("table");
|
||||||
div.classList.add("unknownfile");
|
div.classList.add("unknownfile");
|
||||||
|
@ -328,5 +400,5 @@ function formatTime(date) {
|
||||||
return `${date.toLocaleDateString()} at ${formatTime(date)}`;
|
return `${date.toLocaleDateString()} at ${formatTime(date)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message.setupcmenu();
|
Message.setup();
|
||||||
export { Message };
|
export { Message };
|
||||||
|
|
|
@ -138,7 +138,7 @@ h2 {
|
||||||
|
|
||||||
.pfp {
|
.pfp {
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
width: .5in;
|
width: 0.5in;
|
||||||
height: .5in;
|
height: .5in;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -599,9 +599,12 @@ textarea {
|
||||||
#settings {
|
#settings {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
border-radius: .1in;
|
border-radius: .3in;
|
||||||
transition: background 1s;
|
transition: background 1s;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-size: .25in;
|
||||||
|
width: .3in;
|
||||||
|
height: .3in;
|
||||||
}
|
}
|
||||||
|
|
||||||
#settings:hover {
|
#settings:hover {
|
||||||
|
@ -975,3 +978,13 @@ span {
|
||||||
.spaceright{
|
.spaceright{
|
||||||
margin-right:.1in;
|
margin-right:.1in;
|
||||||
}
|
}
|
||||||
|
.membererror{
|
||||||
|
display:inline-block;
|
||||||
|
background:#656500;
|
||||||
|
height:.15in;
|
||||||
|
width:.15in;
|
||||||
|
border-radius:.1in;
|
||||||
|
text-align:center;
|
||||||
|
border:solid black .03in;
|
||||||
|
margin-left:.025in;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue