From 01970f336bb532d8feca55e640138157cc0e4b3c Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 12 Jun 2024 16:05:49 -0500 Subject: [PATCH] Guild context menu plus prep for guild creation --- webpage/contextmenu.js | 5 +++-- webpage/guild.js | 43 ++++++++++++++++++++++++++++++++++++++++++ webpage/localuser.js | 18 +++++++++++++++++- webpage/style.css | 22 +++++++++++++++++++-- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/webpage/contextmenu.js b/webpage/contextmenu.js index c5a4433..3672a59 100644 --- a/webpage/contextmenu.js +++ b/webpage/contextmenu.js @@ -4,8 +4,8 @@ class contextmenu{ this.buttons=[] } - addbutton(text,onclick,img=null,shown=_=>{return true}){ - this.buttons.push([text,onclick,img,shown]) + addbutton(text,onclick,img=null,shown=_=>true,enabled=_=>true){ + this.buttons.push([text,onclick,img,shown,enabled]) return {}; } makemenu(x,y,addinfo,obj){ @@ -15,6 +15,7 @@ class contextmenu{ if(!thing[3](addinfo)){continue;} const textb=document.createElement("tr"); const intext=document.createElement("button") + intext.disabled=!thing[4](); textb.button=intext; intext.classList.add("contextbutton") intext.innerText=thing[0] diff --git a/webpage/guild.js b/webpage/guild.js index ed28b2d..602782c 100644 --- a/webpage/guild.js +++ b/webpage/guild.js @@ -1,4 +1,30 @@ class guild{ + static contextmenu=new contextmenu("channel menu"); + static setupcontextmenu(){ + guild.contextmenu.addbutton("Copy Guild id",function(){ + console.log(this) + navigator.clipboard.writeText(this.id); + }) + + guild.contextmenu.addbutton("Mark as read",function(){ + console.log(this) + this.markAsRead(); + }) + + guild.contextmenu.addbutton("Create Invite",function(){ + console.log(this); + },null,_=>true,_=>false); + /* -----things left for later----- + guild.contextmenu.addbutton("Leave Guild",function(){ + console.log(this) + this.deleteChannel(); + },null,_=>{return thisuser.isAdmin()}) + + guild.contextmenu.addbutton("Mute Guild",function(){ + editchannelf(this); + },null,_=>{return thisuser.isAdmin()}) + */ + } constructor(JSON,owner){ if(JSON===-1){ return; @@ -131,6 +157,22 @@ class guild{ isAdmin(){ return this.member.isAdmin() } + async markAsRead(){ + const build={read_states:[]}; + for(const thing of this.channels){ + if(thing.hasunreads){ + build.read_states.push({channel_id:thing.id,message_id:thing.lastmessageid,read_state_type:0}); + thing.lastreadmessageid=thing.lastmessageid; + thing.myhtml.classList.remove("cunread"); + } + } + this.unreads(); + fetch(info.api.toString()+"/v9/read-states/ack-bulk",{ + method:"POST", + headers:{"Content-type": "application/json; charset=UTF-8",Authorization:token}, + body:JSON.stringify(build) + }) + } fillMember(member){ member.guild=this; const realroles=[]; @@ -221,3 +263,4 @@ class guild{ }) } } +guild.setupcontextmenu(); diff --git a/webpage/localuser.js b/webpage/localuser.js index a8f3915..f1ba25f 100644 --- a/webpage/localuser.js +++ b/webpage/localuser.js @@ -120,7 +120,7 @@ class localuser{ this.guildhtml[thing.id]=divy; if(thing.properties.icon!=null){ const img=document.createElement("img"); - img.classList.add("pfp","servericon") + img.classList.add("pfp","servericon"); img.src=info.cdn.toString()+"icons/"+thing.properties.id+"/"+thing.properties.icon+".png"; divy.appendChild(img) img.all=thing; @@ -129,6 +129,7 @@ class localuser{ this.all.loadGuild(); this.all.loadChannel(); } + guild.contextmenu.bind(img,thing); }else{ const div=document.createElement("div"); let build=""; @@ -143,9 +144,24 @@ class localuser{ this.all.loadGuild(); this.all.loadChannel(); } + guild.contextmenu.bind(div,thing) } serverlist.append(divy); } + { + const br=document.createElement("hr") + br.classList.add("lightbr"); + serverlist.appendChild(br); + + const div=document.createElement("div"); + div.innerText="+"; + div.classList.add("addserver","servericon") + serverlist.appendChild(div) + div.onclick=function(){ + console.log("clicked :3") + } + + } this.unreads(); } messageCreate(messagep){ diff --git a/webpage/style.css b/webpage/style.css index 7087c16..3400b5e 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -86,7 +86,13 @@ samp { width: calc(100% - .6cm); height: calc(100% - .75in); } - +.contextbutton:disabled{ + cursor:not-allowed; + border-width:0px; +} +.contextbutton:disabled:hover{ + background-color: var(--channels-bg); +} .profile { display: inline-block; position: absolute; @@ -285,6 +291,7 @@ p { width: fit-content; cursor: pointer; font-weight: bold; + word-break:normal; } .username:hover { text-decoration: underline; @@ -397,7 +404,18 @@ p { user-select: none; cursor: pointer; } - +.addserver{ + border-radius: 50%; + width: .5in; + height: .5in; + background-color: var(--blank-bg); + display: flex; + justify-content: center; + align-items: center; + font-size: 200%; + user-select: none; + cursor: pointer; +} #channelw { width: 100%; display: inline-block;