This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.jsx
170 lines (137 loc) · 5.72 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const { getAllModules, constants, messages, i18n: { Messages }, React } = require('powercord/webpack');
const { Clickable, Tooltip, Icon } = require('powercord/components');
const { ChannelTypes, Permissions: DiscordPermissions } = constants;
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const { Plugin } = require('powercord/entities');
const bulk = (...filters) => {
let out = new Array(filters.length);
filters = filters.map(filter => {
if (Array.isArray(filter)) return (module) => module && filter.every(key => module[key]);
if (typeof filter === 'string') return (module) => module?.displayName === filter;
return filter;
});
getAllModules(module => {
for (const [index, filter] of filters.entries()) {
if (filter(module)) {
out[index] = module;
}
}
return out.filter(e => e).length === filters.length;
});
return out;
};
const [
Route,
ChannelItem,
ChannelClasses,
ChannelUtil,
Permissions,
Channel,
{ getChannel } = {},
{ getGuild } = {},
{ iconItem, actionIcon } = {},
UnreadStore,
Voice
] = bulk(
m => m.default?.displayName == 'RouteWithImpression',
m => m.default?.displayName == 'ChannelItem',
['wrapper', 'mainContent'],
['getChannelIconComponent'],
['getChannelPermissions'],
m => m.prototype?.isManaged,
['getDMFromUserId'],
['getGuild'],
['iconItem'],
['isForumPostUnread'],
['getVoiceStateStats']
);
const LockedScreen = require('./components/LockedScreen');
module.exports = class ShowHiddenChannels extends Plugin {
async startPlugin() {
this.patches = [];
this.can = Permissions.__powercordOriginal_can ?? Permissions.can;
this.loadStylesheet('style.css');
const _this = this;
Channel.prototype.isHidden = function () {
return ![1, 3].includes(this.type) && !_this.can(DiscordPermissions.VIEW_CHANNEL, this);
};
this.patch('shc-unread', UnreadStore, 'hasAnyUnread', (args, res) => {
return res && !getChannel(args[0])?.isHidden();
});
this.patch('shc-unread-pins', UnreadStore, 'hasUnread', (args, res) => {
return res && !getChannel(args[0])?.isHidden();
});
this.patch('shc-unread-relevant', UnreadStore, 'hasRelevantUnread', (args, res) => {
return res && !args[0].isHidden();
});
this.patch('shc-unread-notable', UnreadStore, 'hasNotableUnread', (args, res) => {
return res && !getChannel(args[0])?.isHidden();
});
this.patch('shc-permissions-can', Permissions, 'can', (args, res) => {
if (args[0] == DiscordPermissions.VIEW_CHANNEL) return true;
return res;
});
this.patch('shc-mention-count', UnreadStore, 'getMentionCount', (args, res) => {
return getChannel(args[0])?.isHidden() ? 0 : res;
});
this.patch('shc-router', Route, 'default', (args, res) => {
const id = res.props?.computedMatch?.params?.channelId;
const guild = res.props?.computedMatch?.params?.guildId;
let channel;
if (id && guild && (channel = getChannel(id)) && channel?.isHidden?.() && channel?.id != Voice.getChannelId()) {
res.props.render = () => <LockedScreen channel={channel} guild={getGuild(guild)} />;
};
return res;
});
Route.default.displayName = 'RouteWithImpression';
messages._fetchMessages = messages.fetchMessages;
messages.fetchMessages = (args) => {
if (getChannel(args.channelId)?.isHidden?.()) return;
return messages._fetchMessages(args);
};
this.patch('shc-channel-item', ChannelItem, 'default', (args, res) => {
const instance = args[0];
if (instance.channel?.isHidden()) {
const item = res.props?.children?.props;
if (item?.className) item.className += ` shc-hidden-channel shc-hidden-channel-type-${instance.channel.type}`;
const children = res.props?.children?.props?.children[1]?.props?.children[1];
if (children.props?.children) children.props.children = [
<Tooltip text={Messages.CHANNEL_LOCKED_SHORT}>
<Clickable className={[iconItem, 'shc-lock-icon-clickable'].join(' ')} style={{ display: 'block' }}>
<Icon name='LockClosed' className={actionIcon} />
</Clickable>
</Tooltip>
];
if (instance.channel.type == ChannelTypes.GUILD_VOICE && !instance.connected) {
const wrapper = findInReactTree(res, n => n.props?.className?.includes(ChannelClasses.wrapper));
if (wrapper) {
wrapper.props.onMouseDown = () => { };
wrapper.props.onMouseUp = () => { };
}
const mainContent = findInReactTree(res, n => n.props?.className?.includes(ChannelClasses.mainContent));
if (mainContent) {
mainContent.props.onClick = () => { };
mainContent.props.href = null;
}
};
}
return res;
});
ChannelItem.default.displayName = 'ChannelItem';
this.patch('shc-channel-item-icon', ChannelUtil, 'getChannelIconComponent', (args, res) => {
if (args[0]?.isHidden?.() && args[2]?.locked) args[2].locked = false;
return args;
}, true);
}
pluginWillUnload() {
delete Channel.prototype.isHidden;
messages.fetchMessages = messages._fetchMessages;
for (const patch of this.patches) uninject(patch);
}
patch(...args) {
if (!args || !args[0] || typeof args[0] !== 'string') return;
this.patches.push(args[0]);
return inject(...args);
}
};