Adds sorting of DMs
Adds support for sortings of DMs and inital work for unread messages along with a function to work arround an error in spacebar's API
This commit is contained in:
parent
b4ef272c2e
commit
9676c605e7
5 changed files with 67 additions and 3 deletions
|
@ -17,6 +17,16 @@ class channel{
|
|||
this.topic=JSON.topic;
|
||||
this.nsfw=JSON.nsfw;
|
||||
this.position=JSON.position;
|
||||
this.lastreadmessageid=null;
|
||||
this.lastmessageid=JSON.last_message_id;
|
||||
}
|
||||
readStateInfo(json){
|
||||
this.lastreadmessageid=json.last_message_id;
|
||||
this.mentions=json.mention_count;
|
||||
this.lastpin=json.last_pin_timestamp;
|
||||
}
|
||||
get hasunreads(){
|
||||
return this.lastmessageid===this.lastreadmessageid
|
||||
}
|
||||
get canMessage(){
|
||||
for(const thing of this.permission_overwrites){
|
||||
|
@ -368,6 +378,10 @@ class channel{
|
|||
}
|
||||
messageCreate(messagep,focus){
|
||||
const messagez=new cmessage(messagep.d);
|
||||
this.lastmessageid=messagez.id;
|
||||
if(messagez.user===thisuser.user){
|
||||
this.lastreadmessageid=messagez.id;
|
||||
}
|
||||
this.messages.unshift(messagez);
|
||||
const scrolly=document.getElementById("messagecontainer");
|
||||
this.messageids[messagez.id]=messagez;
|
||||
|
@ -378,6 +392,5 @@ class channel{
|
|||
if(shouldScroll){
|
||||
scrolly.scrollTop = scrolly.scrollHeight;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,12 @@ class dirrect extends guild{
|
|||
this.calculateReorder();
|
||||
this.printServers();
|
||||
}
|
||||
sortchannels(){
|
||||
this.headchannels.sort((a,b)=>{
|
||||
const result=(BigInt(a.lastmessageid)-BigInt(b.lastmessageid));
|
||||
return Number(-result);
|
||||
});
|
||||
}
|
||||
giveMember(member){
|
||||
console.error("not a real guild, can't give member object")
|
||||
}
|
||||
|
@ -59,6 +65,8 @@ class group extends channel{
|
|||
this.guild_id="@me";
|
||||
this.messageids={};
|
||||
this.permission_overwrites=[];
|
||||
this.lastmessageid=JSON.last_message_id;
|
||||
this.lastmessageid??=0;
|
||||
}
|
||||
createguildHTML(){
|
||||
const div=document.createElement("div")
|
||||
|
@ -80,4 +88,33 @@ class group extends channel{
|
|||
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
||||
document.getElementById("channelname").innerText="@"+this.name;
|
||||
}
|
||||
messageCreate(messagep,focus){
|
||||
const messagez=new cmessage(messagep.d);
|
||||
this.lastmessageid=messagez.id;
|
||||
if(messagez.user===thisuser.user){
|
||||
this.lastreadmessageid=messagez.id;
|
||||
}
|
||||
this.messages.unshift(messagez);
|
||||
const scrolly=document.getElementById("messagecontainer");
|
||||
this.messageids[messagez.id]=messagez;
|
||||
if(this.owner.owner.lookingguild.prevchannel===this){
|
||||
var shouldScroll=scrolly.scrollTop+scrolly.clientHeight>scrolly.scrollHeight-20;
|
||||
messages.appendChild(messagez.buildhtml(this.messages[1]));
|
||||
}
|
||||
if(shouldScroll){
|
||||
scrolly.scrollTop = scrolly.scrollHeight;
|
||||
}
|
||||
console.log(document.getElementById("channels").children)
|
||||
if(thisuser.lookingguild===this.owner){
|
||||
const channellist=document.getElementById("channels").children[0]
|
||||
for(const thing of channellist.children){
|
||||
if(thing.myinfo===this){
|
||||
channellist.prepend(thing);
|
||||
console.log(thing.myinfo);
|
||||
break;
|
||||
}
|
||||
console.log(thing.myinfo,this,thing.myinfo===this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,9 +92,12 @@ class guild{
|
|||
this.owner.channelfocus=id;
|
||||
this.channelids[id].getHTML();
|
||||
}
|
||||
sortchannels(){
|
||||
this.headchannels.sort((a,b)=>{return a.position-b.position;});
|
||||
}
|
||||
getHTML(){
|
||||
//this.printServers();
|
||||
this.headchannels.sort((a,b)=>{return a.position-b.position;});
|
||||
this.sortchannels();
|
||||
this.printServers();
|
||||
console.log("html")
|
||||
const build=document.createElement("div");
|
||||
|
|
|
@ -431,7 +431,6 @@ function initwebsocket(){
|
|||
break;
|
||||
case "READY":
|
||||
thisuser=new localuser(temp);
|
||||
console.log(temp.d.read_state.entries)
|
||||
thisuser.loaduser();
|
||||
READY=temp;
|
||||
thisuser.init();
|
||||
|
|
|
@ -21,8 +21,20 @@ class localuser{
|
|||
const temp=new member(thing[0]);
|
||||
this.guildids[temp.guild_id].giveMember(temp);
|
||||
}
|
||||
for(const thing of ready.d.read_state.entries){
|
||||
console.log(thing)
|
||||
thing.id=this.resolveGuildidFromChannelID(thing.channel_id);//currently needed due to broken server code, remove once id is the guild id
|
||||
this.guildids[thing.id].channelids[thing.channel_id].readStateInfo(thing);
|
||||
}
|
||||
this.typing=[];
|
||||
}
|
||||
resolveGuildidFromChannelID(ID){
|
||||
for(const thing of this.guilds){
|
||||
if(thing.channelids[ID]){
|
||||
return thing.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateChannel(JSON){
|
||||
this.guildids[JSON.guild_id].updateChannel(JSON);
|
||||
if(JSON.guild_id===this.lookingguild.id){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue