This commit is contained in:
Mirco Wittrien 2021-10-08 11:14:54 +02:00
parent 4b062eea16
commit 8b1c3ad677
4 changed files with 65 additions and 130 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB * @name BDFDB
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.9.1 * @version 1.9.2
* @description Required Library for DevilBro's Plugins * @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -19,19 +19,14 @@ module.exports = (_ => {
"info": { "info": {
"name": "BDFDB", "name": "BDFDB",
"author": "DevilBro", "author": "DevilBro",
"version": "1.9.1", "version": "1.9.2",
"description": "Required Library for DevilBro's Plugins" "description": "Required Library for DevilBro's Plugins"
}, },
"rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`, "rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`,
"changeLog": { "changeLog": {
"added": {
"data-user-id": "Added to Friends List Entries",
"data-author-is-friend": "Added to Friends Flag to Messages"
},
"fixed": { "fixed": {
"BD Browser": "Fixed compartibility issues", "Server Changes AGAIN": "Fixed Stuff for anything changing Servers",
"Server Changes": "Fixed Stuff for anything changing Servers (ServerDetails, DisplayServerAsChannels)", "BD Browser": "Fixed compartibility issues"
"React Search": "Fixed some Incompatibilities with other Plugins"
} }
} }
}; };
@ -2144,13 +2139,13 @@ module.exports = (_ => {
mapped: InternalData.ModuleUtilsConfig.PatchMap[type] mapped: InternalData.ModuleUtilsConfig.PatchMap[type]
}; };
config.nonRender = config.specialFilter || BDFDB.ObjectUtils.toArray(pluginData.patchTypes).flat(10).filter(n => n && !InternalData.ModuleUtilsConfig.InstanceFunctions.includes(n)).length > 0; config.nonRender = config.specialFilter || BDFDB.ObjectUtils.toArray(pluginData.patchTypes).flat(10).filter(n => n && !InternalData.ModuleUtilsConfig.InstanceFunctions.includes(n)).length > 0;
config.nonPrototype = !!(config.codeFind || config.propertyFind || config.nonRender); config.nonPrototype = !!(config.subComponent && config.subComponent.strings || config.stringFind || config.subComponent && config.subComponent.props || config.propertyFind || config.nonRender);
let component = InternalData.ModuleUtilsConfig.LoadedInComponents[type] && BDFDB.ObjectUtils.get(InternalComponents, InternalData.ModuleUtilsConfig.LoadedInComponents[type]); let component = InternalData.ModuleUtilsConfig.LoadedInComponents[type] && BDFDB.ObjectUtils.get(InternalComponents, InternalData.ModuleUtilsConfig.LoadedInComponents[type]);
if (component) InternalBDFDB.patchComponent(pluginData, config.nonRender ? (BDFDB.ModuleUtils.find(m => m == component && m, config.exported) || {}).exports : component, type, config); if (component) InternalBDFDB.patchComponent(pluginData, config.nonRender ? (BDFDB.ModuleUtils.find(m => m == component && m, config.exported) || {}).exports : component, type, config);
else { else {
let mappedType = config.mapped ? config.mapped + " _ _ " + type : type; let mappedType = config.mapped ? config.mapped + " _ _ " + type : type;
let name = config.subComponent || mappedType.split(" _ _ ")[0]; let name = config.subComponent && config.subComponent.name || mappedType.split(" _ _ ")[0];
if (config.mapped) for (let patchType in plugin.patchedModules) if (plugin.patchedModules[patchType][type]) { if (config.mapped) for (let patchType in plugin.patchedModules) if (plugin.patchedModules[patchType][type]) {
plugin.patchedModules[patchType][mappedType] = plugin.patchedModules[patchType][type]; plugin.patchedModules[patchType][mappedType] = plugin.patchedModules[patchType][type];
delete plugin.patchedModules[patchType][type]; delete plugin.patchedModules[patchType][type];
@ -2159,11 +2154,11 @@ module.exports = (_ => {
let patchSpecial = (func, argument) => { let patchSpecial = (func, argument) => {
let module = BDFDB.ModuleUtils[func](argument, config.exported); let module = BDFDB.ModuleUtils[func](argument, config.exported);
let exports = module && !config.exported && module.exports || module; let exports = module && !config.exported && module.exports || module;
exports && InternalBDFDB.patchComponent(pluginData, InternalBDFDB.isMemo(exports) ? exports.default : exports, mappedType, config); exports && InternalBDFDB.patchComponent(pluginData, InternalBDFDB.isMemoOrForwardRef(exports) ? exports.default : exports, mappedType, config);
}; };
if (config.classNames.length) InternalBDFDB.checkForInstance(pluginData, mappedType, config); if (config.classNames.length) InternalBDFDB.checkForInstance(pluginData, mappedType, config);
else if (config.stringFind) patchSpecial("findByString", config.stringFind); else if (config.subComponent && config.subComponent.strings || config.stringFind) patchSpecial("findByString", config.subComponent && config.subComponent.strings || config.stringFind);
else if (config.propertyFind) patchSpecial("findByProperties", config.propertyFind); else if (config.subComponent && config.subComponent.props || config.propertyFind) patchSpecial("findByProperties", config.subComponent && config.subComponent.props || config.propertyFind);
else if (config.nonRender) patchSpecial("findByName", name); else if (config.nonRender) patchSpecial("findByName", name);
else InternalBDFDB.patchComponent(pluginData, BDFDB.ModuleUtils.findByName(name), mappedType, config); else InternalBDFDB.patchComponent(pluginData, BDFDB.ModuleUtils.findByName(name), mappedType, config);
} }
@ -2180,8 +2175,8 @@ module.exports = (_ => {
let toBePatched = config.nonPrototype || !instance.prototype ? instance : instance.prototype; let toBePatched = config.nonPrototype || !instance.prototype ? instance : instance.prototype;
toBePatched = toBePatched && toBePatched.type && typeof toBePatched.type.render == "function" ? toBePatched.type : toBePatched; toBePatched = toBePatched && toBePatched.type && typeof toBePatched.type.render == "function" ? toBePatched.type : toBePatched;
if (config.subComponent) { if (config.subComponent) {
for (let pluginData of pluginDataObjs) BDFDB.PatchUtils.patch(pluginData.plugin, toBePatched, "default", {after: e => { for (let pluginData of pluginDataObjs) BDFDB.PatchUtils.patch(pluginData.plugin, toBePatched, config.subComponent.type || "default", {after: e => {
for (let patchType in pluginData.patchTypes) BDFDB.PatchUtils.patch(pluginData.plugin, e.returnValue, "type", { for (let patchType in pluginData.patchTypes) BDFDB.PatchUtils.patch(pluginData.plugin, config.subComponent.children && e.returnValue.props && e.returnValue.props.children ? e.returnValue.props.children[0] || e.returnValue.props.children : e.returnValue , "type", {
[patchType]: e2 => InternalBDFDB.initiateProcess(pluginData.plugin, type, { [patchType]: e2 => InternalBDFDB.initiateProcess(pluginData.plugin, type, {
instance: e2.thisObject, instance: e2.thisObject,
returnvalue: e2.returnValue, returnvalue: e2.returnValue,
@ -2214,8 +2209,8 @@ module.exports = (_ => {
return value && (!prop.value || [prop.value].flat(10).filter(n => typeof n == "string").some(n => value.toUpperCase().indexOf(n.toUpperCase()) == 0)); return value && (!prop.value || [prop.value].flat(10).filter(n => typeof n == "string").some(n => value.toUpperCase().indexOf(n.toUpperCase()) == 0));
}) && ins.return.type; }) && ins.return.type;
}; };
InternalBDFDB.isMemo = function (exports) { InternalBDFDB.isMemoOrForwardRef = function (exports) {
return exports && exports.default && typeof exports.default.$$typeof == "symbol" && (exports.default.$$typeof.toString() || "").indexOf("memo") > -1; return exports && exports.default && typeof exports.default.$$typeof == "symbol" && ((exports.default.$$typeof.toString() || "").indexOf("memo") > -1 || (exports.default.$$typeof.toString() || "").indexOf("forward_ref") > -1);
}; };
InternalBDFDB.checkEle = function (pluginDataObjs, ele, type, config) { InternalBDFDB.checkEle = function (pluginDataObjs, ele, type, config) {
pluginDataObjs = [pluginDataObjs].flat(10).filter(n => n); pluginDataObjs = [pluginDataObjs].flat(10).filter(n => n);
@ -2226,7 +2221,7 @@ module.exports = (_ => {
if (component) { if (component) {
if (config.nonRender) { if (config.nonRender) {
let exports = (BDFDB.ModuleUtils.find(m => m == component && m, false) || {}).exports; let exports = (BDFDB.ModuleUtils.find(m => m == component && m, false) || {}).exports;
InternalBDFDB.patchComponent(pluginDataObjs, InternalBDFDB.isMemo(exports) ? exports.default : exports, type, config); InternalBDFDB.patchComponent(pluginDataObjs, InternalBDFDB.isMemoOrForwardRef(exports) ? exports.default : exports, type, config);
} }
else InternalBDFDB.patchComponent(pluginDataObjs, component, type, config); else InternalBDFDB.patchComponent(pluginDataObjs, component, type, config);
BDFDB.PatchUtils.forceAllUpdates(pluginDataObjs.map(n => n.plugin), type); BDFDB.PatchUtils.forceAllUpdates(pluginDataObjs.map(n => n.plugin), type);
@ -3177,26 +3172,14 @@ module.exports = (_ => {
BDFDB.GuildUtils.rerenderAll = function (instant) { BDFDB.GuildUtils.rerenderAll = function (instant) {
BDFDB.TimeUtils.clear(BDFDB.GuildUtils.rerenderAll.timeout); BDFDB.TimeUtils.clear(BDFDB.GuildUtils.rerenderAll.timeout);
BDFDB.GuildUtils.rerenderAll.timeout = BDFDB.TimeUtils.timeout(_ => { BDFDB.GuildUtils.rerenderAll.timeout = BDFDB.TimeUtils.timeout(_ => {
let GuildsIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name: "Guilds", unlimited: true}); let ShakeableIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.appcontainer), {name: "Shakeable", unlimited: true, up: true});
let GuildsPrototype = BDFDB.ObjectUtils.get(GuildsIns, `${BDFDB.ReactUtils.instanceKey}.type.prototype`); let ShakeablePrototype = BDFDB.ObjectUtils.get(ShakeableIns, `${BDFDB.ReactUtils.instanceKey}.type.prototype`);
if (GuildsIns && GuildsPrototype) { if (ShakeableIns && ShakeablePrototype) {
let injectPlaceholder = returnValue => { BDFDB.PatchUtils.patch({name: "BDFDB GuildUtils"}, ShakeablePrototype, "render", {after: e => {
let [children, index] = BDFDB.ReactUtils.findParent(returnValue, {name: "ConnectedUnreadDMs"}); e.returnValue.props.children = typeof e.returnValue.props.children == "function" ? (_ => {return null;}) : [];
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement("div", {})); BDFDB.ReactUtils.forceUpdate(ShakeableIns);
BDFDB.ReactUtils.forceUpdate(GuildsIns);
};
BDFDB.PatchUtils.patch({name: "BDFDB GuildUtils"}, GuildsPrototype, "render", {after: e => {
if (typeof e.returnValue.props.children == "function") {
let childrenRender = e.returnValue.props.children;
e.returnValue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
injectPlaceholder(children);
return children;
});
}
else injectPlaceholder(e.returnValue);
}}, {once: true}); }}, {once: true});
BDFDB.ReactUtils.forceUpdate(GuildsIns); BDFDB.ReactUtils.forceUpdate(ShakeableIns);
} }
}, instant ? 0 : 1000); }, instant ? 0 : 1000);
}; };
@ -6222,13 +6205,13 @@ module.exports = (_ => {
let isDraggedGuild = this.props.draggingGuildId === this.props.guild.id; let isDraggedGuild = this.props.draggingGuildId === this.props.guild.id;
let guild = isDraggedGuild ? BDFDB.ReactUtils.createElement("div", { let guild = isDraggedGuild ? BDFDB.ReactUtils.createElement("div", {
children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.Items.DragPlaceholder, {}) children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.DragPlaceholder, {})
}) : BDFDB.ReactUtils.createElement("div", { }) : BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.guildcontainer, className: BDFDB.disCN.guildcontainer,
children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.BlobMask, { children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.BlobMask, {
selected: this.state.isDropHovering || this.props.selected || this.state.hovered, selected: this.state.isDropHovering || this.props.selected || this.state.hovered,
upperBadge: this.props.unavailable ? InternalComponents.LibraryComponents.GuildComponents.Items.renderUnavailableBadge() : InternalComponents.LibraryComponents.GuildComponents.Items.renderIconBadge(BDFDB.ObjectUtils.extract(this.props, "audio", "video", "screenshare", "liveStage", "hasLiveVoiceChannel", "participating", "participatingInStage")), upperBadge: this.props.unavailable ? LibraryModules.GuildBadgeUtils.renderUnavailableBadge() : LibraryModules.GuildBadgeUtils.renderIconBadge(BDFDB.ObjectUtils.extract(this.props, "audio", "video", "screenshare", "liveStage", "hasLiveVoiceChannel", "participating", "participatingInStage")),
lowerBadge: this.props.badge > 0 ? InternalComponents.LibraryComponents.GuildComponents.Items.renderMentionBadge(this.props.badge) : null, lowerBadge: this.props.badge > 0 ? LibraryModules.GuildBadgeUtils.renderMentionBadge(this.props.badge) : null,
lowerBadgeWidth: InternalComponents.LibraryComponents.Badges.getBadgeWidthForValue(this.props.badge), lowerBadgeWidth: InternalComponents.LibraryComponents.Badges.getBadgeWidthForValue(this.props.badge),
children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.NavItem, { children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.NavItem, {
to: { to: {

View File

@ -205,11 +205,11 @@
"EmojiPicker": {"strings": ["EMOJI_PICKER_TAB_PANEL_ID", "diversitySelector"]}, "EmojiPicker": {"strings": ["EMOJI_PICKER_TAB_PANEL_ID", "diversitySelector"]},
"FocusRing": {"props": ["FocusRingScope"]}, "FocusRing": {"props": ["FocusRingScope"]},
"GuestHomeButton": {"props": ["GuestHomeButton"]}, "GuestHomeButton": {"props": ["GuestHomeButton"]},
"Guild": {"subComponent": "ConnectedGuild"}, "Guild": {"subComponent": {"type": "default", "name": "ConnectedGuild"}},
"GuildFolder": {"class": "guildfolderwrapper", "special": [{"path": "return.memoizedProps.folderId"}, {"path": "return.memoizedProps.guildIds"}]}, "GuildFolder": {"props": ["GuildFolderComponent"]},
"GuildIcon": {"class": "avataricon"}, "GuildIcon": {"class": "avataricon"},
"GuildRoleSettings": {"class": "settingswindowcontentregion"}, "GuildRoleSettings": {"class": "settingswindowcontentregion"},
"Guilds": {"strings": ["guildsnav", "ListNavigatorProvider"]}, "Guilds": {"subComponent": {"type": "type", "children": true, "strings": ["guildsnav", "ListNavigatorProvider"]}},
"GuildSettings": {"class": "layer"}, "GuildSettings": {"class": "layer"},
"GuildSettingsBans": {"class": "guildsettingsbannedcard"}, "GuildSettingsBans": {"class": "guildsettingsbannedcard"},
"GuildSettingsEmoji": {"class": "guildsettingsemojicard"}, "GuildSettingsEmoji": {"class": "guildsettingsemojicard"},
@ -310,10 +310,11 @@
"FriendsEmptyState": {"strings": ["FriendsEmptyState", "FriendsSections"], "value": "default"}, "FriendsEmptyState": {"strings": ["FriendsEmptyState", "FriendsSections"], "value": "default"},
"GuildComponents Badge": {"name": "GuildBadge"}, "GuildComponents Badge": {"name": "GuildBadge"},
"GuildComponents BlobMask": {"name": "BlobMask"}, "GuildComponents BlobMask": {"name": "BlobMask"},
"GuildComponents DragPlaceholder": {"name": "DragPlaceholder"},
"GuildComponents Icon": {"name": "GuildIconWrapper"}, "GuildComponents Icon": {"name": "GuildIconWrapper"},
"GuildComponents Items": {"props": ["Separator", "DragPlaceholder"]},
"GuildComponents MutedText": {"props": ["useMutedUntilText"], "value": "default"}, "GuildComponents MutedText": {"props": ["useMutedUntilText"], "value": "default"},
"GuildComponents Pill": {"strings": ["opacity:1,height:", "20:8", "default.item"]}, "GuildComponents Pill": {"strings": ["opacity:1,height:", "20:8", "default.item"]},
"GuildComponents Separator": {"strings": ["className", "default.guildSeparator"]},
"Header": {"name": "Header"}, "Header": {"name": "Header"},
"HeaderBarComponents": {"name": "HeaderBarContainer"}, "HeaderBarComponents": {"name": "HeaderBarContainer"},
"Image": {"props": ["ImageReadyStates"]}, "Image": {"props": ["ImageReadyStates"]},

View File

@ -2,7 +2,7 @@
* @name FriendNotifications * @name FriendNotifications
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.7.8 * @version 1.7.9
* @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status * @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,12 +17,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "FriendNotifications", "name": "FriendNotifications",
"author": "DevilBro", "author": "DevilBro",
"version": "1.7.8", "version": "1.7.9",
"description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status" "description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status"
}, },
"changeLog": { "changeLog": {
"fixed": { "fixed": {
"Log In Option": "Now also works for Desktop Notifications" "Log In Option": "Now also Works for Desktop Notifications"
} }
} }
}; };
@ -245,7 +245,7 @@ module.exports = (_ => {
this.patchedModules = { this.patchedModules = {
after: { after: {
Guilds: "render" Guilds: "type"
} }
}; };
@ -296,6 +296,8 @@ module.exports = (_ => {
forceUpdateAll () { forceUpdateAll () {
defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), {timelog: true}, BDFDB.DataUtils.load(this, "defaultSettings")); defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), {timelog: true}, BDFDB.DataUtils.load(this, "defaultSettings"));
BDFDB.GuildUtils.rerenderAll();
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
} }
@ -734,34 +736,8 @@ module.exports = (_ => {
} }
processGuilds (e) { processGuilds (e) {
if (this.settings.general.addOnlineCount) { console.log(e);
if (typeof e.returnvalue.props.children == "function") { let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "UnreadDMs"});
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
this.checkTree(children);
return children;
}, "", this);
}
else this.checkTree(e.returnvalue);
}
}
checkTree (returnvalue) {
let tree = BDFDB.ReactUtils.findChild(returnvalue, {filter: n => n && n.props && typeof n.props.children == "function"});
if (tree) {
let childrenRender = tree.props.children;
tree.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
this.injectCounter(children);
return children;
}, "", this);
}
else this.injectCounter(returnvalue);
}
injectCounter (returnvalue) {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "ConnectedUnreadDMs"});
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(FriendOnlineCounterComponent, { if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(FriendOnlineCounterComponent, {
amount: this.getOnlineCount() amount: this.getOnlineCount()
})); }));

View File

@ -2,7 +2,7 @@
* @name ReadAllNotificationsButton * @name ReadAllNotificationsButton
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.6.8 * @version 1.6.9
* @description Adds a Clear Button to the Server List and the Mentions Popout * @description Adds a Clear Button to the Server List and the Mentions Popout
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,7 +17,7 @@ module.exports = (_ => {
"info": { "info": {
"name": "ReadAllNotificationsButton", "name": "ReadAllNotificationsButton",
"author": "DevilBro", "author": "DevilBro",
"version": "1.6.8", "version": "1.6.9",
"description": "Adds a Clear Button to the Server List and the Mentions Popout" "description": "Adds a Clear Button to the Server List and the Mentions Popout"
} }
}; };
@ -70,12 +70,11 @@ module.exports = (_ => {
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var _this; var _this;
var blacklist, clearing; var blacklist, clearing;
var settings = {};
const ReadAllButtonComponent = class ReadAllButton extends BdApi.React.Component { const ReadAllButtonComponent = class ReadAllButton extends BdApi.React.Component {
clearClick() { clearClick() {
if (settings.includeGuilds) this.clearGuilds(settings.includeMuted ? this.getGuilds() : this.getUnread()); if (_this.settings.batch.guilds) this.clearGuilds(_this.settings.batch.muted ? this.getGuilds() : this.getUnread());
if (settings.includeDMs) BDFDB.DMUtils.markAsRead(this.getPingedDMs()); if (_this.settings.batch.dms) BDFDB.DMUtils.markAsRead(this.getPingedDMs());
} }
clearGuilds(guildIds) { clearGuilds(guildIds) {
BDFDB.GuildUtils.markAsRead(guildIds.filter(id => id && !blacklist.includes(id))); BDFDB.GuildUtils.markAsRead(guildIds.filter(id => id && !blacklist.includes(id)));
@ -104,7 +103,7 @@ module.exports = (_ => {
className: BDFDB.disCNS.guildiconchildwrapper + BDFDB.disCN._readallnotificationsbuttonbutton, className: BDFDB.disCNS.guildiconchildwrapper + BDFDB.disCN._readallnotificationsbuttonbutton,
children: "read all", children: "read all",
onClick: _ => { onClick: _ => {
if (!settings.confirmClear) this.clearClick(); if (!_this.settings.general.confirmClear) this.clearClick();
else BDFDB.ModalUtils.confirm(_this, _this.labels.modal_confirmnotifications, _ => this.clearClick()); else BDFDB.ModalUtils.confirm(_this, _this.labels.modal_confirmnotifications, _ => this.clearClick());
}, },
onContextMenu: event => { onContextMenu: event => {
@ -149,18 +148,20 @@ module.exports = (_ => {
_this = this; _this = this;
this.defaults = { this.defaults = {
settings: { general: {
addClearButton: {value: true, inner: false, description: "Add a 'Clear Mentions' button to the recent mentions popout"}, addClearButton: {value: true, description: "Add a 'Clear Mentions' button to the recent mentions popout"},
confirmClear: {value: false, inner: false, description: "Ask for your confirmation before clearing reads"}, confirmClear: {value: false, description: "Ask for your confirmation before clearing reads"}
includeGuilds: {value: true, inner: true, description: "unread Servers"}, },
includeMuted: {value: false, inner: true, description: "muted unread Servers"}, batch: {
includeDMs: {value: false, inner: true, description: "unread DMs"} guilds: {value: true, description: "unread Servers"},
muted: {value: false, description: "muted unread Servers"},
dms: {value: false, description: "unread DMs"}
} }
}; };
this.patchedModules = { this.patchedModules = {
after: { after: {
Guilds: "render", Guilds: "type",
RecentMentions: "default", RecentMentions: "default",
RecentsHeader: "default" RecentsHeader: "default"
} }
@ -211,22 +212,22 @@ module.exports = (_ => {
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings", title: "Settings",
collapseStates: collapseStates, collapseStates: collapseStates,
children: Object.keys(settings).filter(key => !this.defaults.settings[key].inner).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["settings", key], keys: ["general", key],
label: this.defaults.settings[key].description, label: this.defaults.general[key].description,
value: settings[key] value: this.settings.general[key]
})).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { })).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "When left clicking the 'read all' button mark following Elements as read:", title: "When left clicking the 'read all' Button mark following Elements as read:",
first: false, first: false,
last: true, last: true,
children: Object.keys(settings).filter(key => this.defaults.settings[key].inner).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.defaults.batch).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["settings", key], keys: ["batch", key],
label: this.defaults.settings[key].description, label: this.defaults.batch[key].description,
value: settings[key] value: this.settings.batch[key]
})) }))
})) }))
})); }));
@ -274,38 +275,12 @@ module.exports = (_ => {
} }
forceUpdateAll () { forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.GuildUtils.rerenderAll();
} }
processGuilds (e) { processGuilds (e) {
if (typeof e.returnvalue.props.children == "function") { let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "UnreadDMs"});
let childrenRender = e.returnvalue.props.children;
e.returnvalue.props.children = (...args) => {
let children = childrenRender(...args);
this.checkTree(children);
return children;
};
}
else this.checkTree(e.returnvalue);
}
checkTree (returnvalue) {
let tree = BDFDB.ReactUtils.findChild(returnvalue, {filter: n => n && n.props && typeof n.props.children == "function"});
if (tree) {
let childrenRender = tree.props.children;
tree.props.children = BDFDB.TimeUtils.suppress((...args) => {
let children = childrenRender(...args);
this.handleGuilds(children);
return children;
}, "", this);
}
else this.handleGuilds(returnvalue);
}
handleGuilds (returnvalue) {
let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "ConnectedUnreadDMs"});
if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(ReadAllButtonComponent, {})); if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(ReadAllButtonComponent, {}));
} }
@ -314,7 +289,7 @@ module.exports = (_ => {
} }
processRecentsHeader (e) { processRecentsHeader (e) {
if (settings.addClearButton && e.instance.props.tab == "Recent Mentions") e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement("div", { if (this.settings.general.addClearButton && e.instance.props.tab == "Recent Mentions") e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement("div", {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: `${BDFDB.LanguageUtils.LanguageStrings.CLOSE} (${BDFDB.LanguageUtils.LanguageStrings.FORM_LABEL_ALL})`, text: `${BDFDB.LanguageUtils.LanguageStrings.CLOSE} (${BDFDB.LanguageUtils.LanguageStrings.FORM_LABEL_ALL})`,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
@ -352,7 +327,7 @@ module.exports = (_ => {
}, i * 1000); }, i * 1000);
} }
}; };
if (settings.confirmClear) BDFDB.ModalUtils.confirm(this, this.labels.modal_confirmmentions, clear); if (this.settings.general.confirmClear) BDFDB.ModalUtils.confirm(this, this.labels.modal_confirmmentions, clear);
else clear(); else clear();
} }
}) })