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
|
@ -7,6 +7,7 @@ import {markdown} from "./markdown.js";
|
|||
import {Guild} from "./guild.js";
|
||||
import { Localuser } from "./localuser.js";
|
||||
import { Permissions } from "./permissions.js";
|
||||
|
||||
declare global {
|
||||
interface NotificationOptions {
|
||||
image?: string
|
||||
|
@ -38,6 +39,7 @@ class Channel{
|
|||
message_notifications:number;
|
||||
allthewayup:boolean;
|
||||
static contextmenu=new Contextmenu("channel menu");
|
||||
replyingto:HTMLDivElement;
|
||||
static setupcontextmenu(){
|
||||
Channel.contextmenu.addbutton("Copy channel id",function(){
|
||||
console.log(this)
|
||||
|
@ -79,7 +81,6 @@ class Channel{
|
|||
for(const thing of JSON.permission_overwrites){
|
||||
this.permission_overwrites[thing.id]=new Permissions(thing.allow,thing.deny);
|
||||
}
|
||||
console.log(this.permission_overwrites)
|
||||
this.topic=JSON.topic;
|
||||
this.nsfw=JSON.nsfw;
|
||||
this.position=JSON.position;
|
||||
|
@ -104,21 +105,29 @@ class Channel{
|
|||
this.mentions??=0;
|
||||
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;
|
||||
}
|
||||
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
|
||||
hasPermission(name:string,member=this.guild.member):boolean{
|
||||
if(member.isAdmin()){
|
||||
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(perm===-1){
|
||||
return false;
|
||||
if(thing.permissions.getPermision(name)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
get canMessage():boolean{
|
||||
return this.hasPermission("SEND_MESSAGES");
|
||||
}
|
||||
sortchildren(){
|
||||
this.children.sort((a,b)=>{return a.position-b.position});
|
||||
|
@ -153,8 +162,19 @@ class Channel{
|
|||
return build;
|
||||
}
|
||||
static dragged=[];
|
||||
createguildHTML(admin=false){
|
||||
createguildHTML(admin=false):HTMLDivElement{
|
||||
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.draggable=admin;
|
||||
div.addEventListener("dragstart",(e)=>{Channel.dragged=[this,div];e.stopImmediatePropagation()})
|
||||
|
@ -392,34 +412,35 @@ class Channel{
|
|||
headers:this.headers
|
||||
})
|
||||
}
|
||||
getHTML(){
|
||||
async getHTML(){
|
||||
if(this.guild!==this.localuser.lookingguild){
|
||||
this.guild.loadGuild();
|
||||
}
|
||||
this.guild.prevchannel=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);
|
||||
document.getElementById("channelname").textContent="#"+this.name;
|
||||
console.log(this);
|
||||
(document.getElementById("typebox") as HTMLInputElement).disabled=!this.canMessage;
|
||||
}
|
||||
putmessages(){
|
||||
const out=this;
|
||||
fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{
|
||||
async putmessages(){
|
||||
if(this.messages.length>=100){return};
|
||||
const j=await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{
|
||||
method: 'GET',
|
||||
headers: this.headers,
|
||||
}).then((j)=>{return j.json()}).then(responce=>{
|
||||
document.getElementById("messages").innerHTML = '';
|
||||
for(const thing of responce){
|
||||
const messager=new Message(thing,this)
|
||||
if(out.messageids[messager.id]==undefined){
|
||||
out.messageids[messager.id]=messager;
|
||||
out.messages.push(messager);
|
||||
}
|
||||
}
|
||||
out.buildmessages();
|
||||
})
|
||||
const responce=await j.json();
|
||||
for(const thing of responce){
|
||||
const messager=new Message(thing,this)
|
||||
if(this.messageids[messager.id]===undefined){
|
||||
this.messageids[messager.id]=messager;
|
||||
this.messages.push(messager);
|
||||
}
|
||||
}
|
||||
}
|
||||
delChannel(JSON){
|
||||
const build=[];
|
||||
|
@ -569,6 +590,7 @@ class Channel{
|
|||
}
|
||||
}
|
||||
messageCreate(messagep:any):void{
|
||||
if(!this.hasPermission("VIEW_CHANNEL")){return}
|
||||
const messagez=new Message(messagep.d,this);
|
||||
this.lastmessageid=messagez.id;
|
||||
if(messagez.author===this.localuser.user){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue