Various bug fixes
This commit is contained in:
parent
cbf657afeb
commit
3b55b28260
7 changed files with 97 additions and 16 deletions
|
@ -346,18 +346,22 @@ class channel{
|
|||
}
|
||||
this.children=build;
|
||||
}
|
||||
grabmoremessages(){
|
||||
if(this.messages.length===0){
|
||||
async grabmoremessages(){
|
||||
if(this.messages.length===0||this.allthewayup){
|
||||
return;
|
||||
}
|
||||
const out=this;
|
||||
fetch("https://api.old.server.spacebar.chat/api/channels/"+this.id+"/messages?before="+this.messages[this.messages.length-1].id+"&limit=100",{
|
||||
|
||||
await fetch("https://api.old.server.spacebar.chat/api/channels/"+this.id+"/messages?before="+this.messages[this.messages.length-1].id+"&limit=100",{
|
||||
method:"GET",
|
||||
headers:{Authorization:token}
|
||||
}).then((j)=>{return j.json()}).then(function(responce){
|
||||
//messages.innerHTML = '';
|
||||
//responce.reverse()
|
||||
let next
|
||||
if(responce.length===0){
|
||||
out.allthewayup=true;
|
||||
}
|
||||
for(const i in responce){
|
||||
let messager
|
||||
if(!next){
|
||||
|
@ -381,6 +385,7 @@ class channel{
|
|||
}
|
||||
//out.buildmessages();
|
||||
})
|
||||
return;
|
||||
}
|
||||
buildmessage(message,next){
|
||||
const built=message.buildhtml(next);
|
||||
|
|
|
@ -18,6 +18,7 @@ class dirrect extends guild{
|
|||
this.channelids[temp.id]=temp;
|
||||
}
|
||||
this.headchannels=this.channels;
|
||||
this.mentions=0;
|
||||
}
|
||||
createChannelpac(JSON){
|
||||
const thischannel=new group(JSON,owner);
|
||||
|
@ -44,6 +45,11 @@ class dirrect extends guild{
|
|||
isAdmin(){
|
||||
return false;
|
||||
}
|
||||
unreaddms(){
|
||||
for(const thing of this.channels){
|
||||
thing.unreads();
|
||||
}
|
||||
}
|
||||
}
|
||||
class group extends channel{
|
||||
constructor(JSON,owner){
|
||||
|
@ -91,7 +97,7 @@ class group extends channel{
|
|||
messageCreate(messagep,focus){
|
||||
const messagez=new cmessage(messagep.d);
|
||||
this.lastmessageid=messagez.id;
|
||||
if(messagez.user===thisuser.user){
|
||||
if(messagez.author===thisuser.user){
|
||||
this.lastreadmessageid=messagez.id;
|
||||
}
|
||||
this.messages.unshift(messagez);
|
||||
|
@ -116,5 +122,42 @@ class group extends channel{
|
|||
console.log(thing.myinfo,this,thing.myinfo===this);
|
||||
}
|
||||
}
|
||||
this.unreads();
|
||||
}
|
||||
unreads(){
|
||||
const sentdms=document.getElementById("sentdms");
|
||||
let current=null;
|
||||
for(const thing of sentdms.children){
|
||||
console.log(thing.all)
|
||||
if(thing.all===this){
|
||||
current=thing;
|
||||
}
|
||||
}
|
||||
console.log(current,this.hasunreads);
|
||||
if(this.hasunreads){
|
||||
if(current){current.noti.innerText=this.mentions;return;}
|
||||
const div=document.createElement("div");
|
||||
div.classList.add("servernoti");
|
||||
const noti=document.createElement("div");
|
||||
noti.classList.add("unread","notiunread","pinged");
|
||||
noti.innerText=this.mentions;
|
||||
div.noti=noti;
|
||||
div.append(noti)
|
||||
const buildpfp=this.user.buildpfp();
|
||||
div.all=this;
|
||||
buildpfp.classList.add("mentioned");
|
||||
console.log(this);
|
||||
div.append(buildpfp)
|
||||
sentdms.append(div);
|
||||
div.onclick=function(){
|
||||
this.all.owner.loadGuild();
|
||||
this.all.getHTML();
|
||||
}
|
||||
}else if(current){
|
||||
console.log("remove")
|
||||
current.remove();
|
||||
}else{
|
||||
console.log(sentdms.children)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ class guild{
|
|||
}
|
||||
}
|
||||
console.log(read);
|
||||
if(!html){return;}
|
||||
if(read){
|
||||
html.children[0].classList.remove("notiunread");
|
||||
}else{
|
||||
|
|
|
@ -651,11 +651,15 @@ document.getElementById("messagecontainer").addEventListener("scroll",(e)=>{
|
|||
const messagecontainer=document.getElementById("messagecontainer")
|
||||
if(messagecontainer.scrollTop<2000){
|
||||
if(!triggered){
|
||||
thisuser.lookingguild.prevchannel.grabmoremessages();
|
||||
thisuser.lookingguild.prevchannel.grabmoremessages().then(()=>{
|
||||
triggered=false;
|
||||
if(messagecontainer.scrollTop===0){
|
||||
messagecontainer.scrollTop=1;
|
||||
}
|
||||
});
|
||||
}
|
||||
triggered=true;
|
||||
}else{
|
||||
triggered=false;
|
||||
if(Math.abs(messagecontainer.scrollHeight-messagecontainer.scrollTop-messagecontainer.clientHeight) < 3){
|
||||
thisuser.lookingguild.prevchannel.readbottom();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class localuser{
|
|||
this.typing=[];
|
||||
}
|
||||
resolveGuildidFromChannelID(ID){
|
||||
const resolve=this.guilds.find(guild => guild.channelids[ID])
|
||||
let resolve=this.guilds.find(guild => guild.channelids[ID])
|
||||
resolve??=undefined;
|
||||
return resolve;
|
||||
}
|
||||
|
@ -98,11 +98,17 @@ class localuser{
|
|||
this.all.loadGuild();
|
||||
this.all.loadChannel();
|
||||
}
|
||||
const sentdms=document.createElement("div");
|
||||
sentdms.classList.add("sentdms");
|
||||
serverlist.append(sentdms);
|
||||
sentdms.id="sentdms";
|
||||
|
||||
const br=document.createElement("hr")
|
||||
br.classList.add("lightbr")
|
||||
br.classList.add("lightbr");
|
||||
serverlist.appendChild(br)
|
||||
for(const thing of this.guilds){
|
||||
if(thing instanceof dirrect){
|
||||
thing.unreaddms();
|
||||
continue;
|
||||
}
|
||||
const divy=document.createElement("div");
|
||||
|
@ -151,7 +157,7 @@ class localuser{
|
|||
console.log(this.guildhtml)
|
||||
for(const thing of this.guilds){
|
||||
if(thing.id==="@me"){continue;}
|
||||
thing.unreads(this.guildhtml[thing.id])
|
||||
thing.unreads(this.guildhtml[thing.id]);
|
||||
}
|
||||
}
|
||||
typeingStart(typing){
|
||||
|
|
|
@ -4,6 +4,7 @@ class cmessage{
|
|||
this[thing]=messagejson[thing];
|
||||
}
|
||||
this.author=new user(this.author);
|
||||
console.log(this.type)
|
||||
}
|
||||
messageevents(obj){
|
||||
obj.classList.add("messagediv")
|
||||
|
@ -16,6 +17,7 @@ class cmessage{
|
|||
//premessage??=messages.lastChild;
|
||||
const build = document.createElement('table');
|
||||
const div=document.createElement("div");
|
||||
|
||||
if(this.message_reference){
|
||||
const replyline=document.createElement("div");
|
||||
const line=document.createElement("hr");
|
||||
|
@ -50,9 +52,10 @@ class cmessage{
|
|||
this.messageevents(div);
|
||||
messagelist.push(div)
|
||||
build.classList.add("message");
|
||||
if(this.content!=""||this.attachments.length!=0){
|
||||
div.appendChild(build);
|
||||
if({0:true,19:true}[this.type]||this.attachments.length!=0){
|
||||
const pfpRow = document.createElement('th');
|
||||
div.appendChild(build)
|
||||
|
||||
let pfpparent, current
|
||||
if(premessage!=null){
|
||||
pfpparent=premessage.pfpparent;
|
||||
|
@ -122,7 +125,8 @@ class cmessage{
|
|||
div.appendChild(attatch)
|
||||
}
|
||||
//
|
||||
}else{
|
||||
}else if(this.type===7){
|
||||
|
||||
const text=document.createElement("th");
|
||||
|
||||
const texttxt=document.createElement("table");
|
||||
|
@ -133,9 +137,15 @@ class cmessage{
|
|||
div.txt=messaged;
|
||||
messaged.innerText="welcome: "+this.author.username;
|
||||
const messagedwrap=document.createElement("tr")
|
||||
messagedwrap.appendChild(messaged)
|
||||
texttxt.appendChild(messagedwrap)
|
||||
messagedwrap.appendChild(messaged);
|
||||
|
||||
const time=document.createElement("span");
|
||||
time.innerText=" "+formatTime(new Date(this.timestamp));
|
||||
time.classList.add("timestamp");
|
||||
messagedwrap.append(time);
|
||||
|
||||
texttxt.appendChild(messagedwrap)
|
||||
console.log(div)
|
||||
}
|
||||
div.userid=this.author.id;
|
||||
div.all=this;
|
||||
|
@ -162,6 +172,6 @@ function formatTime(date) {
|
|||
} else if (isYesterday) {
|
||||
return `Yesterday at ${formatTime(date)}`;
|
||||
} else {
|
||||
return date.toLocaleDateString();
|
||||
return `${date.toLocaleDateString()} at ${formatTime(date)}`;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -594,11 +594,12 @@ span{
|
|||
}
|
||||
|
||||
.unread{
|
||||
aspect-ratio : 1 / 1;
|
||||
position:absolute;
|
||||
background:white;
|
||||
height:.075in;
|
||||
width:.075in;
|
||||
transition:transform .2s;
|
||||
transition:transform .2s,background .2s,height .2s,width .2s;
|
||||
transform:translate(-.20in,.2in);
|
||||
z-index:10;
|
||||
border-radius: 50%;
|
||||
|
@ -609,6 +610,17 @@ span{
|
|||
.notiunread{
|
||||
transform:translate(0in,.2in);
|
||||
}
|
||||
.pinged{
|
||||
aspect-ratio : 1 / 1;
|
||||
transform:translate(0in,.4in);
|
||||
background:red;
|
||||
height:.15in;
|
||||
width:.15in;
|
||||
text-align: center;
|
||||
}
|
||||
.cunread{
|
||||
box-shadow: inset .024in 0 white;
|
||||
}
|
||||
.servernoti{
|
||||
position:relative;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue