upgraded DMs, and fixed bugs

This commit is contained in:
MathMan05 2024-09-07 17:35:15 -05:00
parent 1502dbec17
commit 512cc95ab4
15 changed files with 161 additions and 72 deletions

View file

@ -32,7 +32,7 @@ class Channel extends SnowFlake{
permission_overwritesar:[Role,Permissions][];
topic:string;
nsfw:boolean;
position:number;
position:number=0;
lastreadmessageid:string|undefined;
lastmessageid:string|undefined;
mentions:number;
@ -353,8 +353,10 @@ class Channel extends SnowFlake{
return build;
}
static dragged:[Channel,HTMLDivElement]|[]=[];
html:WeakRef<HTMLElement>|undefined;
createguildHTML(admin=false):HTMLDivElement{
const div=document.createElement("div");
this.html=new WeakRef(div);
if(!this.hasPermission("VIEW_CHANNEL")){
let quit=true;
for(const thing of this.children){
@ -470,27 +472,11 @@ class Channel extends SnowFlake{
return div;
}
get myhtml(){
const search=(document.getElementById("channels") as HTMLDivElement).children[0].children;
if(this.guild!==this.localuser.lookingguild){
return null;
}else if(this.parent){
for(const thing of search){
if(thing["all"]===this.parent){
for(const thing2 of thing.children[1].children){
if(thing2["all"]===this){
return thing2;
}
}
}
}
if(this.html){
return this.html.deref();
}else{
for(const thing of search){
if(thing["all"]===this){
return thing;
}
}
return undefined
}
return null;
}
readbottom(){
if(!this.hasunreads){
@ -503,7 +489,7 @@ class Channel extends SnowFlake{
});
this.lastreadmessageid=this.lastmessageid;
this.guild.unreads();
if(this.myhtml!==null){
if(this.myhtml){
this.myhtml.classList.remove("cunread");
}
}
@ -673,12 +659,12 @@ class Channel extends SnowFlake{
static genid:number=0;
async getHTML(){
const id=++Channel.genid;
if(this.guild!==this.localuser.lookingguild){
this.guild.loadGuild();
}
if(this.localuser.channelfocus){
this.localuser.channelfocus.infinite.delete();
}
if(this.guild!==this.localuser.lookingguild){
this.guild.loadGuild();
}
if(this.localuser.channelfocus&&this.localuser.channelfocus.myhtml){
this.localuser.channelfocus.myhtml.classList.remove("viewChannel");
}
@ -857,7 +843,7 @@ class Channel extends SnowFlake{
this.tryfocusinfinate();
}
infinitefocus=false;
private async tryfocusinfinate(){
async tryfocusinfinate(){
if(this.infinitefocus)return;
this.infinitefocus=true;
const messages=document.getElementById("channelw") as HTMLDivElement;

View file

@ -32,10 +32,11 @@ class Direct extends Guild{
}
createChannelpac(json){
const thischannel=new Group(json,this);
this.channelids[json.id]=thischannel;
this.channelids[thischannel.id]=thischannel;
this.channels.push(thischannel);
this.calculateReorder();
this.sortchannels();
this.printServers();
return thischannel;
}
giveMember(_member:memberjson){
console.error("not a real guild, can't give member object");
@ -100,14 +101,19 @@ class Group extends Channel{
this.lastmessageid=json.last_message_id;
this.mentions=0;
this.setUpInfiniteScroller();
this.updatePosition();
}
updatePosition(){
if(this.lastmessageid){
this.position=SnowFlake.stringToUnixTime(this.lastmessageid);
}else{
this.position=0;
}
this.position=-Math.max(this.position,this.getUnixTime());
}
createguildHTML(){
const div=document.createElement("div");
this.html=new WeakRef(div);
div.classList.add("channeleffects");
const myhtml=document.createElement("span");
myhtml.textContent=this.name;
@ -156,7 +162,19 @@ class Group extends Channel{
}
}
this.unreads();
this.updatePosition();
this.infinite.addedBottom();
this.guild.sortchannels();
if(this.myhtml){
const parrent=this.myhtml.parentElement as HTMLElement;
parrent.prepend(this.myhtml);
}
if(this===this.localuser.channelfocus){
if(!this.infinitefocus){
this.tryfocusinfinate();
}
this.infinite.addedBottom();
}
if(messagez.author===this.localuser.user){
return;
}

View file

@ -365,14 +365,16 @@ class Embed{
img.classList.add("bigembedimg");
if(this.json.video){
img.onclick=async ()=>{
img.remove();
const iframe=document.createElement("iframe");
iframe.src=this.json.video.url+"?autoplay=1";
if(this.json.thumbnail.width&&this.json.thumbnail.width){
iframe.style.width=this.json.thumbnail.width+"px";
iframe.style.height=this.json.thumbnail.height+"px";
if(this.json.video){
img.remove();
const iframe=document.createElement("iframe");
iframe.src=this.json.video.url+"?autoplay=1";
if(this.json.thumbnail.width&&this.json.thumbnail.width){
iframe.style.width=this.json.thumbnail.width+"px";
iframe.style.height=this.json.thumbnail.height+"px";
}
div.append(iframe);
}
div.append(iframe);
};
}else{
img.onclick=async ()=>{

View file

@ -483,6 +483,7 @@ class Guild extends SnowFlake{
}
this.calculateReorder();
this.printServers();
return thischannel;
}
createchannels(func=this.createChannel){
let name="";

View file

@ -24,14 +24,17 @@ class InfiniteScroller{
scroll.classList.add("flexttb","scroller");
div.appendChild(scroll);
this.div=div;
this.beenloaded=false;
//this.interval=setInterval(this.updatestuff.bind(this,true),100);
this.scroll=scroll;
this.div.addEventListener("scroll",_=>{
this.checkscroll();
if(this.scroll)this.scrollTop=this.scroll.scrollTop;
this.watchForChange();
});
this.scroll.addEventListener("scroll",_=>{
this.checkscroll();
if(this.timeout===null){
this.timeout=setTimeout(this.updatestuff.bind(this),300);
}
@ -41,6 +44,8 @@ class InfiniteScroller{
{
let oldheight=0;
new ResizeObserver(_=>{
this.checkscroll();
const func=this.snapBottom();
this.updatestuff();
const change=oldheight-div.offsetHeight;
if(change>0&&this.scroll){
@ -48,6 +53,7 @@ class InfiniteScroller{
}
oldheight=div.offsetHeight;
this.watchForChange();
func();
}).observe(div);
}
new ResizeObserver(this.watchForChange.bind(this)).observe(scroll);
@ -56,13 +62,21 @@ class InfiniteScroller{
this.updatestuff();
await this.watchForChange().then(_=>{
this.updatestuff();
this.beenloaded=true;
});
return div;
}
beenloaded=false;
scrollBottom:number;
scrollTop:number;
needsupdate=true;
averageheight:number=60;
checkscroll(){
if(this.beenloaded&&this.scroll&&!document.body.contains(this.scroll)){
this.scroll=null;
this.div=null;
}
}
async updatestuff(){
this.timeout=null;
if(!this.scroll)return;

View file

@ -474,14 +474,34 @@ class Localuser{
}
}
}
createChannel(json:channeljson):void{
createChannel(json:channeljson):undefined|Channel{
json.guild_id??="@me";
const guild=this.guildids.get(json.guild_id);
if(!guild) return;
guild.createChannelpac(json);
const channel=guild.createChannelpac(json);
if(json.guild_id===this.lookingguild?.id){
this.loadGuild(json.guild_id);
}
if(channel.id===this.gotoid){
guild.loadGuild();
guild.loadChannel(channel.id);
this.gotoid=undefined;
}
}
gotoid:string|undefined;
async goToChannel(id:string){
let guild:undefined|Guild;
for(const thing of this.guilds){
if(thing.channelids[id]){
guild=thing;
}
}
if(guild){
guild.loadGuild();
guild.loadChannel(id);
}else{
this.gotoid=id;
}
}
delChannel(json:channeljson):void{
let guild_id=json.guild_id;

View file

@ -748,6 +748,7 @@ textarea:focus-visible,
width: 100%;
height: 100%;
/* aspect-ratio: 1 /20; */
max-height: 3in;
}
.embedimg {
cursor: pointer;

View file

@ -73,6 +73,8 @@ class User extends SnowFlake{
{method: "POST",
body: JSON.stringify({recipients: [this.id]}),
headers: this.localuser.headers
}).then(_=>_.json()).then(json=>{
this.localuser.goToChannel(json.id)
});
});
this.contextmenu.addbutton("Block user",function(this:User){