UBR v1.0.9

This commit is contained in:
1Lighty 2020-10-29 21:52:10 +01:00
parent e1ecad65d7
commit cd113940e5
2 changed files with 156 additions and 174 deletions

View File

@ -1,4 +1,7 @@
# [UnreadBadgesRedux](https://1lighty.github.io/BetterDiscordStuff/?plugin=UnreadBadgesRedux "UnreadBadgesRedux") Changelog # [UnreadBadgesRedux](https://1lighty.github.io/BetterDiscordStuff/?plugin=UnreadBadgesRedux "UnreadBadgesRedux") Changelog
### 1.0.9
- Fixed not working on channels.
### 1.0.8 ### 1.0.8
- Fixed not working on channels. - Fixed not working on channels.

View File

@ -41,7 +41,7 @@ module.exports = (() => {
twitter_username: '' twitter_username: ''
} }
], ],
version: '1.0.8', version: '1.0.9',
description: 'Adds a number badge to server icons and channels.', description: 'Adds a number badge to server icons and channels.',
github: 'https://github.com/1Lighty', github: 'https://github.com/1Lighty',
github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/UnreadBadgesRedux/UnreadBadgesRedux.plugin.js' github_raw: 'https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/UnreadBadgesRedux/UnreadBadgesRedux.plugin.js'
@ -50,7 +50,7 @@ module.exports = (() => {
{ {
title: 'fixed', title: 'fixed',
type: 'fixed', type: 'fixed',
items: ['Fixed not working on channels.'] items: ['Fixed not working on channels, again.']
} }
], ],
defaultConfig: [ defaultConfig: [
@ -246,12 +246,12 @@ module.exports = (() => {
XenoLib.Notifications.error(`[**${this.name}**] Failed to start! Please update it, press CTRL + R, or ${GuildStore.getGuild(XenoLib.supportServerId) ? 'go to <#639665366380838924>' : '[join my support server](https://discord.gg/NYvWdN5)'} for further assistance.`, { timeout: 0 }); XenoLib.Notifications.error(`[**${this.name}**] Failed to start! Please update it, press CTRL + R, or ${GuildStore.getGuild(XenoLib.supportServerId) ? 'go to <#639665366380838924>' : '[join my support server](https://discord.gg/NYvWdN5)'} for further assistance.`, { timeout: 0 });
try { try {
this.onStop(); this.onStop();
} catch (e) {} } catch (e) { }
} }
}; };
try { try {
ModalStack.popWithKey(`${this.name}_DEP_MODAL`); ModalStack.popWithKey(`${this.name}_DEP_MODAL`);
} catch (e) {} } catch (e) { }
} }
onStart() { onStart() {
this.promises = { state: { cancelled: false } }; this.promises = { state: { cancelled: false } };
@ -311,13 +311,10 @@ module.exports = (() => {
} }
async patchChannelItem(promiseState) { async patchChannelItem(promiseState) {
const selector = `.${XenoLib.getSingleClass('modeUnread wrapper', true)}`; const TextChannel = await ReactComponents.getComponentByName('TextChannel', `.${XenoLib.getSingleClass('mentionsBadge containerDefault')}`);
const ChannelItem = await ReactComponents.getComponentByName('ChannelItem', selector);
if (!ChannelItem.selector) ChannelItem.selector = selector;
if (promiseState.cancelled) return; if (promiseState.cancelled) return;
const settings = this.settings; const settings = this.settings;
const MentionsBadgeClassname = XenoLib.getClass('iconVisibility mentionsBadge'); const MentionsBadgeClassname = XenoLib.getClass('iconVisibility mentionsBadge');
const IconsChildren = XenoLib.getClass('modeMuted children');
function UnreadBadge(e) { function UnreadBadge(e) {
const unreadCount = StoresModule.useStateFromStores([UnreadStore], () => { const unreadCount = StoresModule.useStateFromStores([UnreadStore], () => {
if ((e.muted && !settings.misc.mutedChannels) || !settings.misc.channels) return 0; if ((e.muted && !settings.misc.mutedChannels) || !settings.misc.channels) return 0;
@ -334,30 +331,13 @@ module.exports = (() => {
BadgesModule.NumberBadge({ count: unreadCount, color: e.muted ? ColorConverter.darkenColor(settings.misc.backgroundColor, settings.misc.mutedChannelBadgeDarkness * 100) : settings.misc.backgroundColor, style: { color: e.muted ? ColorConverter.darkenColor(settings.misc.textColor, settings.misc.mutedChannelBadgeDarkness * 100) : settings.misc.textColor } }) BadgesModule.NumberBadge({ count: unreadCount, color: e.muted ? ColorConverter.darkenColor(settings.misc.backgroundColor, settings.misc.mutedChannelBadgeDarkness * 100) : settings.misc.backgroundColor, style: { color: e.muted ? ColorConverter.darkenColor(settings.misc.textColor, settings.misc.mutedChannelBadgeDarkness * 100) : settings.misc.textColor } })
); );
} }
Patcher.after(ChannelItem.component.prototype, 'renderIcons', (_this, args, ret) => { Patcher.after(TextChannel.component.prototype, 'render', (_this, _, ret) => {
const props = Utilities.findInReactTree(ret, e => e && Array.isArray(e.children) && e.children.find(e => e && e.type && e.type.displayName === 'ConnectedEditButton'));
if (!props || !props.children) return;
const badge = React.createElement(UnreadBadge, { channelId: _this.props.channel.id, muted: _this.props.muted && !_this.props.selected }); const badge = React.createElement(UnreadBadge, { channelId: _this.props.channel.id, muted: _this.props.muted && !_this.props.selected });
if (!ret) { props.children.splice(this.settings.misc.channelsDisplayOnLeft ? 0 : 2, 0, badge);
return React.createElement(
'div',
{
onClick: e => e.stopPropagation(),
className: IconsChildren
},
badge
);
}
/* children is a refernce to the children prop within the component, which is bad
so appending it without slicing first would append it to the components props
children array
*/
const props = Utilities.findInReactTree(ret, e => Array.isArray(e.children) && e.children.find(e => e && e.type && e.type.displayName === 'ConnectedEditButton'));
if (!props) return;
const buttons = props.children.slice(0);
if (!buttons) return;
buttons.splice(this.settings.misc.channelsDisplayOnLeft ? 0 : 2, 0, badge);
props.children = buttons;
}); });
ChannelItem.forceUpdateAll(); TextChannel.forceUpdateAll();
} }
async patchGuildFolder(promiseState) { async patchGuildFolder(promiseState) {
@ -594,7 +574,7 @@ module.exports = (() => {
n = (n, e) => n && n._config && n._config.info && n._config.info.version && i(n._config.info.version, e), n = (n, e) => n && n._config && n._config.info && n._config.info.version && i(n._config.info.version, e),
e = BdApi.getPlugin('ZeresPluginLibrary'), e = BdApi.getPlugin('ZeresPluginLibrary'),
o = BdApi.getPlugin('XenoLib'); o = BdApi.getPlugin('XenoLib');
n(e, '1.2.23') && (ZeresPluginLibraryOutdated = !0), n(o, '1.3.26') && (XenoLibOutdated = !0); n(e, '1.2.14') && (ZeresPluginLibraryOutdated = !0), n(o, '1.3.17') && (XenoLibOutdated = !0);
} }
} catch (i) { } catch (i) {
console.error('Error checking if libraries are out of date', i); console.error('Error checking if libraries are out of date', i);
@ -618,8 +598,7 @@ module.exports = (() => {
getDescription() { getDescription() {
return this.description + ' You are missing libraries for this plugin, please enable the plugin and click Download Now.'; return this.description + ' You are missing libraries for this plugin, please enable the plugin and click Download Now.';
} }
start() {} stop() { }
stop() {}
handleMissingLib() { handleMissingLib() {
const a = BdApi.findModuleByProps('openModal', 'hasModalOpen'); const a = BdApi.findModuleByProps('openModal', 'hasModalOpen');
if (a && a.hasModalOpen(`${this.name}_DEP_MODAL`)) return; if (a && a.hasModalOpen(`${this.name}_DEP_MODAL`)) return;
@ -674,7 +653,7 @@ module.exports = (() => {
b('https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/1XenoLib.plugin.js', (b, f, g) => { b('https://raw.githubusercontent.com/1Lighty/BetterDiscordPlugins/master/Plugins/1XenoLib.plugin.js', (b, f, g) => {
try { try {
if (b || 200 !== f.statusCode) return a.closeModal(m), i(); if (b || 200 !== f.statusCode) return a.closeModal(m), i();
c.writeFile(d.join(e, '1XenoLib.plugin.js'), g, () => {}); c.writeFile(d.join(e, '1XenoLib.plugin.js'), g, () => { });
} catch (b) { } catch (b) {
console.error('Fatal error downloading XenoLib', b), a.closeModal(m), i(); console.error('Fatal error downloading XenoLib', b), a.closeModal(m), i();
} }
@ -684,7 +663,7 @@ module.exports = (() => {
? b('https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js', (b, g, h) => { ? b('https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js', (b, g, h) => {
try { try {
if (b || 200 !== g.statusCode) return a.closeModal(m), i(); if (b || 200 !== g.statusCode) return a.closeModal(m), i();
c.writeFile(d.join(e, '0PluginLibrary.plugin.js'), h, () => {}), f(); c.writeFile(d.join(e, '0PluginLibrary.plugin.js'), h, () => { }), f();
} catch (b) { } catch (b) {
console.error('Fatal error downloading ZeresPluginLibrary', b), a.closeModal(m), i(); console.error('Fatal error downloading ZeresPluginLibrary', b), a.closeModal(m), i();
} }
@ -693,7 +672,7 @@ module.exports = (() => {
} }
}, },
b, b,
{ onClose: () => {} } { onClose: () => { } }
) )
) )
); );