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:
@@ -451,6 +451,21 @@ class channel{
|
|||||||
headers:this.headers
|
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){
|
messageCreate(messagep,focus){
|
||||||
const messagez=new cmessage(messagep.d,this);
|
const messagez=new cmessage(messagep.d,this);
|
||||||
this.lastmessageid=messagez.id;
|
this.lastmessageid=messagez.id;
|
||||||
@@ -475,6 +490,53 @@ class channel{
|
|||||||
if(shouldScroll){
|
if(shouldScroll){
|
||||||
scrolly.scrollTop = scrolly.scrollHeight;
|
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();
|
channel.setupcontextmenu();
|
||||||
|
@@ -126,6 +126,20 @@ class group extends channel{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.unreads();
|
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(){
|
unreads(){
|
||||||
const sentdms=document.getElementById("sentdms");
|
const sentdms=document.getElementById("sentdms");
|
||||||
|
@@ -11,6 +11,11 @@ class guild{
|
|||||||
this.markAsRead();
|
this.markAsRead();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
guild.contextmenu.addbutton("Notifications",function(){
|
||||||
|
console.log(this)
|
||||||
|
this.setnotifcation();
|
||||||
|
});
|
||||||
|
|
||||||
guild.contextmenu.addbutton("Leave guild",function(){
|
guild.contextmenu.addbutton("Leave guild",function(){
|
||||||
this.confirmleave();
|
this.confirmleave();
|
||||||
},null,function(_){return _.properties.owner_id!==_.member.user.id});
|
},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(){
|
confirmleave(){
|
||||||
const full= new fullscreen([
|
const full= new fullscreen([
|
||||||
"vdiv",
|
"vdiv",
|
||||||
|
@@ -28,6 +28,10 @@ class localuser{
|
|||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id]=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){
|
for(const thing of ready.d.merged_members){
|
||||||
const temp=new member(thing[0]);
|
const temp=new member(thing[0]);
|
||||||
this.guildids[temp.guild_id].giveMember(temp);
|
this.guildids[temp.guild_id].giveMember(temp);
|
||||||
|
@@ -47,11 +47,36 @@ class cmessage{
|
|||||||
this.embeds[thing]=new embed(this.embeds[thing],this);
|
this.embeds[thing]=new embed(this.embeds[thing],this);
|
||||||
}
|
}
|
||||||
this.author=new user(this.author);
|
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){
|
messageevents(obj){
|
||||||
cmessage.contextmenu.bind(obj,this)
|
cmessage.contextmenu.bind(obj,this)
|
||||||
obj.classList.add("messagediv")
|
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){
|
buildhtml(premessage){
|
||||||
//premessage??=messages.lastChild;
|
//premessage??=messages.lastChild;
|
||||||
const build = document.createElement('table');
|
const build = document.createElement('table');
|
||||||
|
Reference in New Issue
Block a user