giving some love to DMs

This commit is contained in:
MathMan05 2024-09-07 18:48:22 -05:00
parent 384b666ac2
commit 515a11f110
2 changed files with 75 additions and 1 deletions

View file

@ -4,7 +4,9 @@ import { Message } from "./message.js";
import { User } from "./user.js";
import { Permissions } from "./permissions.js";
import { SnowFlake } from "./snowflake.js";
import { Contextmenu } from "./contextmenu.js";
class Direct extends Guild {
channelids;
constructor(json, owner) {
super(-1, owner, null);
this.message_notifications = 0;
@ -35,6 +37,13 @@ class Direct extends Guild {
this.printServers();
return thischannel;
}
delChannel(json) {
const channel = this.channelids[json.id];
super.delChannel(json);
if (channel) {
channel.del();
}
}
giveMember(_member) {
console.error("not a real guild, can't give member object");
}
@ -76,6 +85,21 @@ dmPermissions.setPermission("STREAM", 1);
dmPermissions.setPermission("USE_VAD", 1);
class Group extends Channel {
user;
static contextmenu = new Contextmenu("channel menu");
static setupcontextmenu() {
this.contextmenu.addbutton("Copy DM id", function () {
navigator.clipboard.writeText(this.id);
});
this.contextmenu.addbutton("Mark as read", function () {
this.readbottom();
});
this.contextmenu.addbutton("Close DM", function () {
this.deleteChannel();
});
this.contextmenu.addbutton("Copy user ID", function () {
navigator.clipboard.writeText(this.user.id);
});
}
constructor(json, owner) {
super(-1, owner, json.id);
this.owner = owner;
@ -109,6 +133,7 @@ class Group extends Channel {
}
createguildHTML() {
const div = document.createElement("div");
Group.contextmenu.bindContextmenu(div, this, undefined);
this.html = new WeakRef(div);
div.classList.add("channeleffects");
const myhtml = document.createElement("span");
@ -202,6 +227,15 @@ class Group extends Channel {
}
all = new WeakRef(document.createElement("div"));
noti = new WeakRef(document.createElement("div"));
del() {
const all = this.all.deref();
if (all) {
all.remove();
}
if (this.myhtml) {
this.myhtml.remove();
}
}
unreads() {
const sentdms = document.getElementById("sentdms"); //Need to change sometime
const current = this.all.deref();
@ -244,3 +278,4 @@ class Group extends Channel {
}
}
export { Direct, Group };
Group.setupcontextmenu();

View file

@ -3,11 +3,13 @@ import{ Channel }from"./channel.js";
import{ Message }from"./message.js";
import{ Localuser }from"./localuser.js";
import{User}from"./user.js";
import{ dirrectjson, memberjson, messagejson }from"./jsontypes.js";
import{ channeljson, dirrectjson, memberjson, messagejson }from"./jsontypes.js";
import{ Permissions }from"./permissions.js";
import { SnowFlake } from "./snowflake.js";
import { Contextmenu } from "./contextmenu.js";
class Direct extends Guild{
channelids:{[key:string]:Group};
constructor(json:dirrectjson[],owner:Localuser){
super(-1,owner,null);
this.message_notifications=0;
@ -38,6 +40,13 @@ class Direct extends Guild{
this.printServers();
return thischannel;
}
delChannel(json:channeljson){
const channel=this.channelids[json.id];
super.delChannel(json);
if(channel){
channel.del();
}
}
giveMember(_member:memberjson){
console.error("not a real guild, can't give member object");
}
@ -82,6 +91,24 @@ dmPermissions.setPermission("USE_VAD",1);
class Group extends Channel{
user:User;
static contextmenu=new Contextmenu<Group,undefined>("channel menu");
static setupcontextmenu(){
this.contextmenu.addbutton("Copy DM id",function(this:Group){
navigator.clipboard.writeText(this.id);
});
this.contextmenu.addbutton("Mark as read",function(this:Group){
this.readbottom();
});
this.contextmenu.addbutton("Close DM",function(this:Group){
this.deleteChannel();
});
this.contextmenu.addbutton("Copy user ID",function(){
navigator.clipboard.writeText(this.user.id);
})
}
constructor(json:dirrectjson,owner:Direct){
super(-1,owner,json.id);
this.owner=owner;
@ -113,6 +140,7 @@ class Group extends Channel{
}
createguildHTML(){
const div=document.createElement("div");
Group.contextmenu.bindContextmenu(div,this,undefined);
this.html=new WeakRef(div);
div.classList.add("channeleffects");
const myhtml=document.createElement("span");
@ -123,6 +151,7 @@ class Group extends Channel{
div.onclick=_=>{
this.getHTML();
};
return div;
}
async getHTML(){
@ -205,6 +234,15 @@ class Group extends Channel{
}
all:WeakRef<HTMLElement>=new WeakRef(document.createElement("div"));
noti:WeakRef<HTMLElement>=new WeakRef(document.createElement("div"));
del(){
const all=this.all.deref();
if(all){
all.remove();
}
if(this.myhtml){
this.myhtml.remove();
}
}
unreads(){
const sentdms=document.getElementById("sentdms") as HTMLDivElement;//Need to change sometime
const current=this.all.deref();
@ -246,3 +284,4 @@ class Group extends Channel{
}
}
export{Direct, Group};
Group.setupcontextmenu();