Notification support
Be warned, there's either a bug in the server or notification level setting isn't implemented on the server side
This commit is contained in:
parent
0d5e4fc94b
commit
31f3fef52d
5 changed files with 141 additions and 0 deletions
|
@ -451,6 +451,21 @@ class channel{
|
|||
headers:this.headers
|
||||
})
|
||||
}
|
||||
get notification(){
|
||||
let notinumber=this.message_notifications;
|
||||
if(+notinumber===3){notinumber=null;}
|
||||
notinumber??=this.owner.message_notifications;
|
||||
switch(+notinumber){
|
||||
case 0:
|
||||
return "all";
|
||||
case 1:
|
||||
return "mentions";
|
||||
case 2:
|
||||
return "none";
|
||||
case 3:
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
messageCreate(messagep,focus){
|
||||
const messagez=new cmessage(messagep.d,this);
|
||||
this.lastmessageid=messagez.id;
|
||||
|
@ -475,6 +490,53 @@ class channel{
|
|||
if(shouldScroll){
|
||||
scrolly.scrollTop = scrolly.scrollHeight;
|
||||
}
|
||||
if(messagez.author===this.owner.owner.user){
|
||||
return;
|
||||
}
|
||||
if(this.owner.owner.lookingguild.prevchannel===this&&document.hasFocus()){
|
||||
return;
|
||||
}
|
||||
if(this.notification==="all"){
|
||||
this.notify(messagez);
|
||||
}else if(this.notification==="mentions"&&messagez.mentionsuser(this.owner.owner.user)){
|
||||
this.notify(messagez);
|
||||
}
|
||||
}
|
||||
notititle(message){
|
||||
return message.author.username+" > "+this.owner.properties.name+" > "+this.name;
|
||||
}
|
||||
notify(message){
|
||||
{
|
||||
const voicy=new voice("sin",800);
|
||||
voicy.play()
|
||||
setTimeout(_=>{voicy.freq=1000},50);
|
||||
setTimeout(_=>{voicy.freq=1300},100);
|
||||
setTimeout(_=>{voicy.stop()},150);
|
||||
}
|
||||
if (!("Notification" in window)) {
|
||||
|
||||
} else if (Notification.permission === "granted") {
|
||||
let noticontent=markdown(message.content).textContent;
|
||||
noticontent||=message.embeds[0].json.title;
|
||||
noticontent||=markdown(message.embeds[0].json.description).textContent;
|
||||
noticontent||="Blank Message";
|
||||
let imgurl=null;
|
||||
const images=message.getimages();
|
||||
if(images.length){
|
||||
const image = images[0];
|
||||
imgurl||=image.proxy_url;
|
||||
imgurl||=image.url;
|
||||
}
|
||||
const notification = new Notification(this.notititle(message),{
|
||||
body:noticontent,
|
||||
icon:message.author.getpfpsrc(),
|
||||
image:imgurl,
|
||||
});
|
||||
} else if (Notification.permission !== "denied") {
|
||||
Notification.requestPermission().then((permission) => {
|
||||
this.notify(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
channel.setupcontextmenu();
|
||||
|
|
|
@ -126,6 +126,20 @@ class group extends channel{
|
|||
}
|
||||
}
|
||||
this.unreads();
|
||||
if(messagez.author===this.owner.owner.user){
|
||||
return;
|
||||
}
|
||||
if(this.owner.owner.lookingguild.prevchannel===this&&document.hasFocus()){
|
||||
return;
|
||||
}
|
||||
if(this.notification==="all"){
|
||||
this.notify(messagez);
|
||||
}else if(this.notification==="mentions"&&messagez.mentionsuser(this.owner.owner.user)){
|
||||
this.notify(messagez);
|
||||
}
|
||||
}
|
||||
notititle(message){
|
||||
return message.author.username;
|
||||
}
|
||||
unreads(){
|
||||
const sentdms=document.getElementById("sentdms");
|
||||
|
|
|
@ -11,6 +11,11 @@ class guild{
|
|||
this.markAsRead();
|
||||
});
|
||||
|
||||
guild.contextmenu.addbutton("Notifications",function(){
|
||||
console.log(this)
|
||||
this.setnotifcation();
|
||||
});
|
||||
|
||||
guild.contextmenu.addbutton("Leave guild",function(){
|
||||
this.confirmleave();
|
||||
},null,function(_){return _.properties.owner_id!==_.member.user.id});
|
||||
|
@ -67,6 +72,37 @@ class guild{
|
|||
}
|
||||
}
|
||||
}
|
||||
notisetting(settings){
|
||||
this.message_notifications=settings.message_notifications;
|
||||
}
|
||||
setnotifcation(){
|
||||
let noti=this.message_notifications
|
||||
const notiselect=new fullscreen(
|
||||
["vdiv",
|
||||
["radio","select notifications type",
|
||||
["all","only mentions","none"],
|
||||
function(e){
|
||||
noti=["all","only mentions","none"].indexOf(e);
|
||||
},
|
||||
noti
|
||||
],
|
||||
["button","","submit",_=>{
|
||||
fetch(info.api.toString()+"/v9/users/@me/guilds/settings",{
|
||||
method:"PATCH",
|
||||
headers:this.headers,
|
||||
body:JSON.stringify({
|
||||
"guilds":{
|
||||
[this.id]:{
|
||||
"message_notifications": noti
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
this.message_notifications=noti;
|
||||
}]
|
||||
]);
|
||||
notiselect.show();
|
||||
}
|
||||
confirmleave(){
|
||||
const full= new fullscreen([
|
||||
"vdiv",
|
||||
|
|
|
@ -28,6 +28,10 @@ class localuser{
|
|||
this.guilds.push(temp);
|
||||
this.guildids[temp.id]=temp;
|
||||
}
|
||||
console.log(ready.d.user_guild_settings.entries)
|
||||
for(const thing of ready.d.user_guild_settings.entries){
|
||||
this.guildids[thing.guild_id].notisetting(thing);
|
||||
}
|
||||
for(const thing of ready.d.merged_members){
|
||||
const temp=new member(thing[0]);
|
||||
this.guildids[temp.guild_id].giveMember(temp);
|
||||
|
|
|
@ -47,11 +47,36 @@ class cmessage{
|
|||
this.embeds[thing]=new embed(this.embeds[thing],this);
|
||||
}
|
||||
this.author=new user(this.author);
|
||||
for(const thing in this.mentions){
|
||||
this.mentions[thing]=new user(this.mentions[thing]);
|
||||
}
|
||||
if(this.mentions.length||this.mention_roles.length){//currently mention_roles isn't implemented on the spacebar servers
|
||||
console.log(this.mentions,this.mention_roles)
|
||||
}
|
||||
if(this.mentionsuser(this.owner.owner.owner.user)){
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
messageevents(obj){
|
||||
cmessage.contextmenu.bind(obj,this)
|
||||
obj.classList.add("messagediv")
|
||||
}
|
||||
mentionsuser(userd){
|
||||
if(userd instanceof user){
|
||||
return this.mentions.includes(userd);
|
||||
}else if(userd instanceof member){
|
||||
return this.mentions.includes(userd.user);
|
||||
}
|
||||
}
|
||||
getimages(){
|
||||
const build=[];
|
||||
for(const thing of this.attachments){
|
||||
if(thing.content_type.startsWith('image/')){
|
||||
build.push(thing);
|
||||
}
|
||||
}
|
||||
return build;
|
||||
}
|
||||
buildhtml(premessage){
|
||||
//premessage??=messages.lastChild;
|
||||
const build = document.createElement('table');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue