various improvements and fixes
fixes a DM bug, and improves mention handling
This commit is contained in:
parent
a22c2f10c0
commit
127a9e8250
6 changed files with 84 additions and 34 deletions
|
@ -38,7 +38,7 @@ class Channel extends SnowFlake{
|
||||||
position: number = 0;
|
position: number = 0;
|
||||||
lastreadmessageid: string | undefined;
|
lastreadmessageid: string | undefined;
|
||||||
lastmessageid: string | undefined;
|
lastmessageid: string | undefined;
|
||||||
mentions!: number;
|
mentions=0;
|
||||||
lastpin!: string;
|
lastpin!: string;
|
||||||
move_id?: string;
|
move_id?: string;
|
||||||
typing!: number;
|
typing!: number;
|
||||||
|
@ -518,9 +518,7 @@ class Channel extends SnowFlake{
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
div.classList.add("channel");
|
div.classList.add("channel");
|
||||||
if(this.hasunreads){
|
this.unreads();
|
||||||
div.classList.add("cunread");
|
|
||||||
}
|
|
||||||
Channel.contextmenu.bindContextmenu(div, this,undefined);
|
Channel.contextmenu.bindContextmenu(div, this,undefined);
|
||||||
if(admin){
|
if(admin){
|
||||||
this.coatDropDiv(div);
|
this.coatDropDiv(div);
|
||||||
|
@ -624,7 +622,9 @@ class Channel extends SnowFlake{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readbottom(){
|
readbottom(){
|
||||||
|
this.mentions=0;
|
||||||
if(!this.hasunreads){
|
if(!this.hasunreads){
|
||||||
|
this.guild.unreads();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch(
|
fetch(
|
||||||
|
@ -637,10 +637,9 @@ class Channel extends SnowFlake{
|
||||||
);
|
);
|
||||||
this.lastreadmessageid = this.lastmessageid;
|
this.lastreadmessageid = this.lastmessageid;
|
||||||
this.guild.unreads();
|
this.guild.unreads();
|
||||||
if(this.myhtml){
|
this.unreads();
|
||||||
this.myhtml.classList.remove("cunread");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
coatDropDiv(div: HTMLDivElement, container: HTMLElement | boolean = false){
|
coatDropDiv(div: HTMLDivElement, container: HTMLElement | boolean = false){
|
||||||
div.addEventListener("dragenter", event=>{
|
div.addEventListener("dragenter", event=>{
|
||||||
console.log("enter");
|
console.log("enter");
|
||||||
|
@ -1351,6 +1350,20 @@ class Channel extends SnowFlake{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unreads(){
|
||||||
|
if(!this.hasunreads){
|
||||||
|
if(this.myhtml){
|
||||||
|
this.myhtml.classList.remove("cunread","mentioned");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(this.myhtml){
|
||||||
|
this.myhtml.classList.add("cunread");
|
||||||
|
}
|
||||||
|
if(this.mentions!==0){
|
||||||
|
this.myhtml?.classList.add("mentioned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
messageCreate(messagep: messageCreateJson): void{
|
messageCreate(messagep: messageCreateJson): void{
|
||||||
if(!this.hasPermission("VIEW_CHANNEL")){
|
if(!this.hasPermission("VIEW_CHANNEL")){
|
||||||
return;
|
return;
|
||||||
|
@ -1361,19 +1374,15 @@ class Channel extends SnowFlake{
|
||||||
this.idToNext.set(this.lastmessageid, messagez.id);
|
this.idToNext.set(this.lastmessageid, messagez.id);
|
||||||
this.idToPrev.set(messagez.id, this.lastmessageid);
|
this.idToPrev.set(messagez.id, this.lastmessageid);
|
||||||
}
|
}
|
||||||
|
if(messagez.mentionsuser(this.localuser.user)&&messagez.author!==this.localuser.user){
|
||||||
|
this.mentions++;
|
||||||
|
}
|
||||||
this.lastmessageid = messagez.id;
|
this.lastmessageid = messagez.id;
|
||||||
|
|
||||||
if(messagez.author === this.localuser.user){
|
if(messagez.author === this.localuser.user){
|
||||||
this.lastreadmessageid = messagez.id;
|
this.lastreadmessageid = messagez.id;
|
||||||
if(this.myhtml){
|
|
||||||
this.myhtml.classList.remove("cunread");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(this.myhtml){
|
|
||||||
this.myhtml.classList.add("cunread");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.unreads();
|
||||||
this.guild.unreads();
|
this.guild.unreads();
|
||||||
if(this === this.localuser.channelfocus){
|
if(this === this.localuser.channelfocus){
|
||||||
if(!this.infinitefocus){
|
if(!this.infinitefocus){
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Direct extends Guild{
|
||||||
const thischannel = new Group(json, this);
|
const thischannel = new Group(json, this);
|
||||||
this.channelids[thischannel.id] = thischannel;
|
this.channelids[thischannel.id] = thischannel;
|
||||||
this.channels.push(thischannel);
|
this.channels.push(thischannel);
|
||||||
|
this.localuser.channelids.set(thischannel.id, thischannel);
|
||||||
this.sortchannels();
|
this.sortchannels();
|
||||||
this.printServers();
|
this.printServers();
|
||||||
return thischannel;
|
return thischannel;
|
||||||
|
@ -282,8 +283,17 @@ class Direct extends Guild{
|
||||||
channelTopic.append(add);
|
channelTopic.append(add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get mentions(){
|
||||||
|
let mentions=0;
|
||||||
|
for(const thing of this.localuser.inrelation){
|
||||||
|
if(thing.relationshipType===3){
|
||||||
|
mentions+=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mentions;
|
||||||
|
}
|
||||||
giveMember(_member: memberjson){
|
giveMember(_member: memberjson){
|
||||||
console.error("not a real guild, can't give member object");
|
throw new Error("not a real guild, can't give member object");
|
||||||
}
|
}
|
||||||
getRole(/* ID: string */){
|
getRole(/* ID: string */){
|
||||||
return null;
|
return null;
|
||||||
|
@ -429,6 +439,7 @@ class Group extends Channel{
|
||||||
|
|
||||||
}
|
}
|
||||||
messageCreate(messagep: { d: messagejson }){
|
messageCreate(messagep: { d: messagejson }){
|
||||||
|
this.mentions++;
|
||||||
const messagez = new Message(messagep.d, this);
|
const messagez = new Message(messagep.d, this);
|
||||||
if(this.lastmessageid){
|
if(this.lastmessageid){
|
||||||
this.idToNext.set(this.lastmessageid, messagez.id);
|
this.idToNext.set(this.lastmessageid, messagez.id);
|
||||||
|
@ -461,20 +472,15 @@ class Group extends Channel{
|
||||||
}
|
}
|
||||||
this.unreads();
|
this.unreads();
|
||||||
if(messagez.author === this.localuser.user){
|
if(messagez.author === this.localuser.user){
|
||||||
|
this.mentions=0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(
|
if(this.localuser.lookingguild?.prevchannel === this && document.hasFocus()){
|
||||||
this.localuser.lookingguild?.prevchannel === this &&
|
|
||||||
document.hasFocus()
|
|
||||||
){
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(this.notification === "all"){
|
if(this.notification === "all"){
|
||||||
this.notify(messagez);
|
this.notify(messagez);
|
||||||
}else if(
|
}else if(this.notification === "mentions" && messagez.mentionsuser(this.localuser.user)){
|
||||||
this.notification === "mentions" &&
|
|
||||||
messagez.mentionsuser(this.localuser.user)
|
|
||||||
){
|
|
||||||
this.notify(messagez);
|
this.notify(messagez);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -588,27 +588,42 @@ class Guild extends SnowFlake{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
get mentions(){
|
||||||
|
let mentions=0;
|
||||||
|
for(const thing of this.channels){
|
||||||
|
mentions+=thing.mentions;
|
||||||
|
}
|
||||||
|
return mentions;
|
||||||
|
}
|
||||||
unreads(html?: HTMLElement | undefined){
|
unreads(html?: HTMLElement | undefined){
|
||||||
if(html){
|
if(html){
|
||||||
this.html = html;
|
this.html = html;
|
||||||
}else{
|
}else{
|
||||||
html = this.html;
|
html = this.html;
|
||||||
}
|
}
|
||||||
|
if(!html){
|
||||||
|
return;
|
||||||
|
}
|
||||||
let read = true;
|
let read = true;
|
||||||
|
let mentions=this.mentions;
|
||||||
for(const thing of this.channels){
|
for(const thing of this.channels){
|
||||||
if(thing.hasunreads){
|
if(thing.hasunreads){
|
||||||
console.log(thing);
|
|
||||||
read = false;
|
read = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!html){
|
const noti=html.children[0];
|
||||||
return;
|
if(mentions!==0){
|
||||||
|
noti.classList.add("pinged");
|
||||||
|
noti.textContent=""+mentions;
|
||||||
|
}else{
|
||||||
|
noti.textContent="";
|
||||||
|
noti.classList.remove("pinged");
|
||||||
}
|
}
|
||||||
if(read){
|
if(read){
|
||||||
html.children[0].classList.remove("notiunread");
|
noti.classList.remove("notiunread");
|
||||||
}else{
|
}else{
|
||||||
html.children[0].classList.add("notiunread");
|
noti.classList.add("notiunread");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getHTML(){
|
getHTML(){
|
||||||
|
|
|
@ -551,6 +551,9 @@ class Localuser{
|
||||||
user.relationshipType = temp.d.type;
|
user.relationshipType = temp.d.type;
|
||||||
this.inrelation.add(user);
|
this.inrelation.add(user);
|
||||||
this.relationshipsUpdate();
|
this.relationshipsUpdate();
|
||||||
|
const me=this.guildids.get("@me");
|
||||||
|
if(!me)break;
|
||||||
|
me.unreads();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "RELATIONSHIP_REMOVE":{
|
case "RELATIONSHIP_REMOVE":{
|
||||||
|
|
|
@ -243,7 +243,11 @@ class Message extends SnowFlake{
|
||||||
if(userd instanceof User){
|
if(userd instanceof User){
|
||||||
return this.mentions.includes(userd);
|
return this.mentions.includes(userd);
|
||||||
}else if(userd instanceof Member){
|
}else if(userd instanceof Member){
|
||||||
return this.mentions.includes(userd.user);
|
if(this.mentions.includes(userd.user)){
|
||||||
|
return true
|
||||||
|
}else{
|
||||||
|
return !new Set(this.mentions).isDisjointFrom(new Set(userd.roles));//if the message mentions a role the user has
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,6 +611,10 @@ span.instanceStatus {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
transition: transform .2s, height .2s;
|
transition: transform .2s, height .2s;
|
||||||
}
|
}
|
||||||
|
.servernoti:hover .unread.pinged {
|
||||||
|
transform: translate(34px, 14px);
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
.servernoti:hover .unread {
|
.servernoti:hover .unread {
|
||||||
transform: translate(-12px, 12px);
|
transform: translate(-12px, 12px);
|
||||||
height: 24px;
|
height: 24px;
|
||||||
|
@ -618,6 +622,11 @@ span.instanceStatus {
|
||||||
.serveropen .unread {
|
.serveropen .unread {
|
||||||
transform: translate(-12px, 8px) !important;
|
transform: translate(-12px, 8px) !important;
|
||||||
height: 32px !important;
|
height: 32px !important;
|
||||||
|
width: 8px !important;
|
||||||
|
|
||||||
|
}
|
||||||
|
.serveropen .unread.pinged{
|
||||||
|
color: transparent;
|
||||||
}
|
}
|
||||||
.notiunread {
|
.notiunread {
|
||||||
transform: translate(-12px, 20px);
|
transform: translate(-12px, 20px);
|
||||||
|
@ -625,18 +634,19 @@ span.instanceStatus {
|
||||||
#sentdms {
|
#sentdms {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
.unread.pinged, .servernoti:hover .unread.pinged {
|
.unread.pinged{
|
||||||
height: 16px;
|
height: 16px;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
transform: translate(28px, 28px);
|
transform: translate(34px, 34px);
|
||||||
background: var(--red);
|
background: var(--red);
|
||||||
font-size: .75rem;
|
font-size: .75rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
line-height: 15px;
|
line-height: 15px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border: 4px solid var(--servers-bg);
|
/* border: 4px solid var(--servers-bg); */
|
||||||
border-radius: 50%;
|
/* border-radius: 50%; */
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Channel Panel */
|
/* Channel Panel */
|
||||||
|
@ -711,6 +721,9 @@ span.instanceStatus {
|
||||||
background: var(--primary-text);
|
background: var(--primary-text);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
.cunread.mentioned:after{
|
||||||
|
background: var(--red);
|
||||||
|
}
|
||||||
.space {
|
.space {
|
||||||
flex: none;
|
flex: none;
|
||||||
height: 1em;
|
height: 1em;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue