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

@ -23,7 +23,7 @@ class Channel extends SnowFlake {
permission_overwritesar; permission_overwritesar;
topic; topic;
nsfw; nsfw;
position; position = 0;
lastreadmessageid; lastreadmessageid;
lastmessageid; lastmessageid;
mentions; mentions;
@ -340,8 +340,10 @@ class Channel extends SnowFlake {
return build; return build;
} }
static dragged = []; static dragged = [];
html;
createguildHTML(admin = false) { createguildHTML(admin = false) {
const div = document.createElement("div"); const div = document.createElement("div");
this.html = new WeakRef(div);
if (!this.hasPermission("VIEW_CHANNEL")) { if (!this.hasPermission("VIEW_CHANNEL")) {
let quit = true; let quit = true;
for (const thing of this.children) { for (const thing of this.children) {
@ -457,29 +459,12 @@ class Channel extends SnowFlake {
return div; return div;
} }
get myhtml() { get myhtml() {
const search = document.getElementById("channels").children[0].children; if (this.html) {
if (this.guild !== this.localuser.lookingguild) { return this.html.deref();
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;
}
}
}
}
} }
else { else {
for (const thing of search) { return undefined;
if (thing["all"] === this) {
return thing;
}
}
} }
return null;
} }
readbottom() { readbottom() {
if (!this.hasunreads) { if (!this.hasunreads) {
@ -492,7 +477,7 @@ class Channel extends SnowFlake {
}); });
this.lastreadmessageid = this.lastmessageid; this.lastreadmessageid = this.lastmessageid;
this.guild.unreads(); this.guild.unreads();
if (this.myhtml !== null) { if (this.myhtml) {
this.myhtml.classList.remove("cunread"); this.myhtml.classList.remove("cunread");
} }
} }
@ -663,12 +648,12 @@ class Channel extends SnowFlake {
static genid = 0; static genid = 0;
async getHTML() { async getHTML() {
const id = ++Channel.genid; const id = ++Channel.genid;
if (this.guild !== this.localuser.lookingguild) {
this.guild.loadGuild();
}
if (this.localuser.channelfocus) { if (this.localuser.channelfocus) {
this.localuser.channelfocus.infinite.delete(); this.localuser.channelfocus.infinite.delete();
} }
if (this.guild !== this.localuser.lookingguild) {
this.guild.loadGuild();
}
if (this.localuser.channelfocus && this.localuser.channelfocus.myhtml) { if (this.localuser.channelfocus && this.localuser.channelfocus.myhtml) {
this.localuser.channelfocus.myhtml.classList.remove("viewChannel"); this.localuser.channelfocus.myhtml.classList.remove("viewChannel");
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -495,10 +495,31 @@ class Localuser {
const guild = this.guildids.get(json.guild_id); const guild = this.guildids.get(json.guild_id);
if (!guild) if (!guild)
return; return;
guild.createChannelpac(json); const channel = guild.createChannelpac(json);
if (json.guild_id === this.lookingguild?.id) { if (json.guild_id === this.lookingguild?.id) {
this.loadGuild(json.guild_id); this.loadGuild(json.guild_id);
} }
if (channel.id === this.gotoid) {
guild.loadGuild();
guild.loadChannel(channel.id);
this.gotoid = undefined;
}
}
gotoid;
async goToChannel(id) {
let 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) { delChannel(json) {
let guild_id = json.guild_id; let guild_id = json.guild_id;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -24,14 +24,17 @@ class InfiniteScroller{
scroll.classList.add("flexttb","scroller"); scroll.classList.add("flexttb","scroller");
div.appendChild(scroll); div.appendChild(scroll);
this.div=div; this.div=div;
this.beenloaded=false;
//this.interval=setInterval(this.updatestuff.bind(this,true),100); //this.interval=setInterval(this.updatestuff.bind(this,true),100);
this.scroll=scroll; this.scroll=scroll;
this.div.addEventListener("scroll",_=>{ this.div.addEventListener("scroll",_=>{
this.checkscroll();
if(this.scroll)this.scrollTop=this.scroll.scrollTop; if(this.scroll)this.scrollTop=this.scroll.scrollTop;
this.watchForChange(); this.watchForChange();
}); });
this.scroll.addEventListener("scroll",_=>{ this.scroll.addEventListener("scroll",_=>{
this.checkscroll();
if(this.timeout===null){ if(this.timeout===null){
this.timeout=setTimeout(this.updatestuff.bind(this),300); this.timeout=setTimeout(this.updatestuff.bind(this),300);
} }
@ -41,6 +44,8 @@ class InfiniteScroller{
{ {
let oldheight=0; let oldheight=0;
new ResizeObserver(_=>{ new ResizeObserver(_=>{
this.checkscroll();
const func=this.snapBottom();
this.updatestuff(); this.updatestuff();
const change=oldheight-div.offsetHeight; const change=oldheight-div.offsetHeight;
if(change>0&&this.scroll){ if(change>0&&this.scroll){
@ -48,6 +53,7 @@ class InfiniteScroller{
} }
oldheight=div.offsetHeight; oldheight=div.offsetHeight;
this.watchForChange(); this.watchForChange();
func();
}).observe(div); }).observe(div);
} }
new ResizeObserver(this.watchForChange.bind(this)).observe(scroll); new ResizeObserver(this.watchForChange.bind(this)).observe(scroll);
@ -56,13 +62,21 @@ class InfiniteScroller{
this.updatestuff(); this.updatestuff();
await this.watchForChange().then(_=>{ await this.watchForChange().then(_=>{
this.updatestuff(); this.updatestuff();
this.beenloaded=true;
}); });
return div; return div;
} }
beenloaded=false;
scrollBottom:number; scrollBottom:number;
scrollTop:number; scrollTop:number;
needsupdate=true; needsupdate=true;
averageheight:number=60; averageheight:number=60;
checkscroll(){
if(this.beenloaded&&this.scroll&&!document.body.contains(this.scroll)){
this.scroll=null;
this.div=null;
}
}
async updatestuff(){ async updatestuff(){
this.timeout=null; this.timeout=null;
if(!this.scroll)return; 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"; json.guild_id??="@me";
const guild=this.guildids.get(json.guild_id); const guild=this.guildids.get(json.guild_id);
if(!guild) return; if(!guild) return;
guild.createChannelpac(json); const channel=guild.createChannelpac(json);
if(json.guild_id===this.lookingguild?.id){ if(json.guild_id===this.lookingguild?.id){
this.loadGuild(json.guild_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{ delChannel(json:channeljson):void{
let guild_id=json.guild_id; let guild_id=json.guild_id;

View file

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

View file

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