This commit is contained in:
Mirco Wittrien 2019-02-04 11:22:37 +01:00
parent 156c3bddb6
commit d1999f5d4b
3 changed files with 64 additions and 13 deletions

View File

@ -14,7 +14,8 @@ class ServerFolders {
this.patchModules = {
"Guilds":"componentDidMount",
"Guild":["componentDidMount","componentWillUnmount"]
"Guild":["componentDidMount","componentWillUnmount"],
"StandardSidebarView":"componentWillUnmount"
};
this.css = `
@ -497,8 +498,7 @@ class ServerFolders {
});
BDFDB.addEventListener(this, wrapper, "mousedown", e => {
if (BDFDB.pressedKeys.includes(17)) {
e.originalEvent.stopPropagation();
e.originalEvent.preventDefault();
BDFDB.stopEvent(e);
let dragpreview = this.createDragPreview(wrapper, e);
let updatePreview = e2 => {
this.updateDragPreview(dragpreview, e2);
@ -525,6 +525,13 @@ class ServerFolders {
}
}
processStandardSidebarView (instance, wrapper) {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.foldercontent.querySelectorAll(BDFDB.dotCN.guild + ".folder").forEach(folderdiv => {this.updateFolderNotifications(folderdiv);});
}
}
showFolderSettings (folderdiv) {
if (!folderdiv) return;
let {folderID,folderName,position,iconID,icons,copyTooltipColor,color1,color2,color3,color4,servers} = BDFDB.loadData(folderdiv.id, this, "folders") || {};
@ -557,8 +564,6 @@ class ServerFolders {
this.saveCustomIcon(folderSettingsModal);
});
BDFDB.addChildEventListener(folderSettingsModal, "click", ".btn-save", e => {
e.preventDefault();
folderName = foldernameinput.value.trim();
folderName = folderName ? folderName : null;
@ -855,7 +860,7 @@ class ServerFolders {
BDFDB.removeClass(unreaditem, BDFDB.disCN.contextmenuitemdisabled);
unreaditem.addEventListener("click", () => {
folderContext.remove();
BDFDB.clearReadNotifications(unreadServers);
BDFDB.markGuildAsRead(unreadServers);
});
}
BDFDB.appendContextMenu(folderContext, e);
@ -1080,7 +1085,7 @@ class ServerFolders {
BDFDB.createTooltip(EditServersData.name || info.name, guildcopy, {type:"right",selector:(!BDFDB.isObjectEmpty(EditServersData) ? "EditUsers-tooltip" : ""),style:`color: ${fontColor} !important; background-color: ${bgColor} !important; border-color: ${bgColor} !important;`});
});
guildcopy.addEventListener("click", e => {
e.preventDefault();
BDFDB.stopEvent(e);
if (BDFDB.pressedKeys.includes(46)) this.removeServerFromFolder(info, folderdiv);
else {
let settings = BDFDB.getAllData(this, "settings");
@ -1200,7 +1205,7 @@ class ServerFolders {
if (!data) return;
let includedServers = this.readIncludedServerList(folderdiv);
let unreadServers = BDFDB.readUnreadServerList(includedServers);
if (unreadServers.length > 0 && data.autounread) BDFDB.clearReadNotifications(unreadServers);
if (unreadServers.length > 0 && data.autounread) BDFDB.markGuildAsRead(unreadServers);
else {
let badgeAmount = 0;
let audioEnabled = false;

View File

@ -8,6 +8,24 @@ module.exports = (Plugin, Api, Vendor) => {
"RecentMentions":"componentDidMount"
};
this.RANcontextMenuMarkup =
`<div class="${BDFDB.disCN.contextmenu} RANbutton-contextmenu">
<div class="${BDFDB.disCN.contextmenuitemgroup}">
<div class="${BDFDB.disCN.contextmenuitem} readguilds-item">
<span class="DevilBro-textscrollwrapper" speed=3><div class="DevilBro-textscroll">REPLACE_context_guilds_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
<div class="${BDFDB.disCN.contextmenuitem} readmutedguilds-item">
<span class="DevilBro-textscrollwrapper" speed=3><div class="DevilBro-textscroll">REPLACE_context_mutedguilds_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
<div class="${BDFDB.disCN.contextmenuitem} readdms-item">
<span class="DevilBro-textscrollwrapper" speed=3><div class="DevilBro-textscroll">REPLACE_context_dms_text</div></span>
<div class="${BDFDB.disCN.contextmenuhint}"></div>
</div>
</div>
</div>`;
this.RANbuttonMarkup =
`<div class="${BDFDB.disCN.guild} RANbutton-frame" id="bd-pub-li" style="height: 20px; margin-bottom: 10px;">
<div class="${BDFDB.disCN.guildinner}" style="height: 20px; border-radius: 4px;">
@ -24,7 +42,9 @@ module.exports = (Plugin, Api, Vendor) => {
this.defaults = {
settings: {
includeMuted: {value:false, description:"Include muted Servers (means more API-Requests):"}
includeGuilds: {value:true, description:"unread Servers"},
includeMuted: {value:false, description:"muted unread Servers"},
includeDMs: {value:false, description:"unread DMs"}
}
};
}
@ -83,7 +103,25 @@ module.exports = (Plugin, Api, Vendor) => {
let ranbutton = BDFDB.htmlToElement(this.RANbuttonMarkup);
guildseparator.parentElement.insertBefore(ranbutton, guildseparator);
ranbutton.addEventListener("click", () => {
BDFDB.clearReadNotifications(BDFDB.getData("includeMuted", this, "settings") ? BDFDB.readServerList() : BDFDB.readUnreadServerList());
let settings = BDFDB.getAllData(this, "settings");
if (settings.includeGuilds) BDFDB.markGuildAsRead(settings.includeMuted ? BDFDB.readServerList() : BDFDB.readUnreadServerList());
if (settings.includeDMs) BDFDB.markChannelAsRead(BDFDB.readDmList());
});
ranbutton.addEventListener("contextmenu", e => {
let RANcontextMenu = BDFDB.htmlToElement(this.RANcontextMenuMarkup);
RANcontextMenu.querySelector(".readguilds-item").addEventListener("click", () => {
BDFDB.removeEles(RANcontextMenu);
BDFDB.markGuildAsRead(BDFDB.readUnreadServerList());
});
RANcontextMenu.querySelector(".readmutedguilds-item").addEventListener("click", () => {
BDFDB.removeEles(RANcontextMenu);
BDFDB.markGuildAsRead(BDFDB.readServerList());
});
RANcontextMenu.querySelector(".readdms-item").addEventListener("click", () => {
BDFDB.removeEles(RANcontextMenu);
BDFDB.markChannelAsRead(BDFDB.readDmList());
});
BDFDB.appendContextMenu(RANcontextMenu, e);
});
BDFDB.addClass(wrapper, "RAN-added");
}
@ -115,14 +153,22 @@ module.exports = (Plugin, Api, Vendor) => {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
var settings = BDFDB.getAllData(this, "settings");
var settingshtml = `<div class="${this.name}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="DevilBro-settings-inner">`;
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">When left clicking the button mark following elements as unread:</h3></div><div class="DevilBro-settings-inner-list">`;
for (let key in settings) {
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="settings ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${settings[key] ? " checked" : ""}></div></div>`;
}
settingshtml += `</div>`;
settingshtml += `</div></div>`;
let settingspanel = BDFDB.htmlToElement(settingshtml);
BDFDB.initElements(settingspanel, this);
let mutedinput = settingspanel.querySelector(".settings-switch[value='settings includeMuted']").parentElement.parentElement;
BDFDB.toggleEles(mutedinput, settings.includeGuilds);
BDFDB.addEventListener(this, settingspanel, "click", ".settings-switch[value='settings includeGuilds']", e => {
BDFDB.toggleEles(mutedinput, e.currentTarget.checked);
});
return settingspanel;
}

View File

@ -794,7 +794,7 @@ module.exports = (Plugin, Api, Vendor) => {
BDFDB.removeClass(unreaditem, BDFDB.disCN.contextmenuitemdisabled);
unreaditem.addEventListener("click", () => {
folderContext.remove();
BDFDB.clearReadNotifications(unreadServers);
BDFDB.markGuildAsRead(unreadServers);
});
}
BDFDB.appendContextMenu(folderContext, e);
@ -1139,7 +1139,7 @@ module.exports = (Plugin, Api, Vendor) => {
if (!data) return;
let includedServers = this.readIncludedServerList(folderdiv);
let unreadServers = BDFDB.readUnreadServerList(includedServers);
if (unreadServers.length > 0 && data.autounread) BDFDB.clearReadNotifications(unreadServers);
if (unreadServers.length > 0 && data.autounread) BDFDB.markGuildAsRead(unreadServers);
else {
let badgeAmount = 0;
let audioEnabled = false;