2022-10-23 09:44:21 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { Flex } from "../components/Flex";
|
2022-10-25 08:53:06 +00:00
|
|
|
import { Devs } from "../utils/constants";
|
2022-10-23 09:44:21 +00:00
|
|
|
import { ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "../utils/modal";
|
|
|
|
import definePlugin, { OptionType } from "../utils/types";
|
|
|
|
import { Settings } from "../Vencord";
|
|
|
|
import { waitFor } from "../webpack";
|
|
|
|
import { Button, ChannelStore, Text } from "../webpack/common";
|
|
|
|
|
2022-10-24 21:22:39 +00:00
|
|
|
const CONNECT = 1048576n;
|
2022-10-23 09:44:21 +00:00
|
|
|
const VIEW_CHANNEL = 1024n;
|
|
|
|
|
|
|
|
let can = (permission, channel) => true;
|
|
|
|
waitFor(m => m.can && m.initialize, m => ({ can } = m));
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "ShowHiddenChannels",
|
|
|
|
description: "Show hidden channels",
|
|
|
|
authors: [
|
|
|
|
{
|
|
|
|
name: "BigDuck",
|
|
|
|
id: 1024588272623681609n
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Average React Enjoyer",
|
|
|
|
id: 1004904120056029256n
|
2022-10-24 21:22:39 +00:00
|
|
|
},
|
2022-10-25 08:53:06 +00:00
|
|
|
Devs.D3SOX,
|
2022-10-23 09:44:21 +00:00
|
|
|
],
|
|
|
|
options: {
|
|
|
|
hideUnreads: {
|
|
|
|
description: "Hide unreads",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true,
|
|
|
|
restartNeeded: true // Restart is needed to refresh channel list
|
|
|
|
}
|
|
|
|
},
|
|
|
|
patches: [
|
|
|
|
{
|
|
|
|
// RenderLevel defines if a channel is hidden, collapsed in category, visible, etc
|
|
|
|
find: ".CannotShow",
|
|
|
|
replacement: {
|
|
|
|
match: /renderLevel:(\w+)\.CannotShow/g,
|
2022-10-24 21:22:39 +00:00
|
|
|
replace: "renderLevel:Vencord.Plugins.plugins.ShowHiddenChannels.shouldShow(this.record, this.category, this.isMuted) ? $1.Show : $1.CannotShow"
|
2022-10-23 09:44:21 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-10-24 21:22:39 +00:00
|
|
|
// This is where the logic that chooses the icon is, we override it to be a locked voice channel if it's hidden
|
2022-10-23 09:44:21 +00:00
|
|
|
find: ".rulesChannelId))",
|
|
|
|
replacement: {
|
|
|
|
match: /(\w+)\.locked(.*?)switch\((\w+)\.type\)({case \w+\.\w+\.GUILD_ANNOUNCEMENT)/g,
|
|
|
|
replace: "Vencord.Plugins.plugins.ShowHiddenChannels.isHiddenChannel($3)||$1.locked$2switch($3._isHiddenChannel?2:$3.type)$4"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-10-24 21:22:39 +00:00
|
|
|
// Prevents Discord from trying to fetch message and create a 403 error
|
|
|
|
find: "fetchMessages:function",
|
|
|
|
replacement: {
|
|
|
|
match: /fetchMessages:function\((\w)\){/g,
|
|
|
|
replace: "fetchMessages:function($1){if(Vencord.Plugins.plugins.ShowHiddenChannels.isHiddenChannel($1)) return;"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Don't switch to the channel if it's hidden, but show a modal instead
|
|
|
|
find: ".selectGuild(",
|
|
|
|
replacement: {
|
|
|
|
match: /(function \w+\(\w\)\{var (\w)=\w+\(\w\);)/g,
|
|
|
|
replace: "$1if(Vencord.Plugins.plugins.ShowHiddenChannels.channelSelected($2?.params))return;"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Prevent categories from disappearing when they're collapsed
|
|
|
|
find: ".prototype.shouldShowEmptyCategory=function(){",
|
|
|
|
replacement: {
|
|
|
|
match: /(\.prototype\.shouldShowEmptyCategory=function\(\){)/g,
|
|
|
|
replace: "$1return true;"
|
|
|
|
}
|
2022-10-23 09:44:21 +00:00
|
|
|
},
|
|
|
|
{
|
2022-10-24 21:22:39 +00:00
|
|
|
// Hide unreads
|
2022-10-23 09:44:21 +00:00
|
|
|
find: "?\"button\":\"link\"",
|
|
|
|
predicate: () => Settings.plugins.ShowHiddenChannels.hideUnreads === true,
|
|
|
|
replacement: {
|
|
|
|
match: /(\w)\.connected,(\w)=(\w\.unread),(\w=\w\.canHaveDot)/g,
|
|
|
|
replace: "$1.connected,$2=Vencord.Plugins.plugins.ShowHiddenChannels.isHiddenChannel($1.channel)?false:$3,$4"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2022-10-24 21:22:39 +00:00
|
|
|
shouldShow(channel, category, isMuted) {
|
|
|
|
if (!this.isHiddenChannel(channel)) return false;
|
|
|
|
if (!category) return false;
|
|
|
|
if (channel.type === 0 && category.guild?.hideMutedChannels && isMuted) return false;
|
|
|
|
|
|
|
|
return !category.isCollapsed;
|
|
|
|
},
|
2022-10-23 09:44:21 +00:00
|
|
|
isHiddenChannel(channel) {
|
|
|
|
if (!channel) return false;
|
2022-10-24 21:22:39 +00:00
|
|
|
if (channel.channelId)
|
|
|
|
channel = ChannelStore.getChannel(channel.channelId);
|
|
|
|
if (!channel || channel.isDM() || channel.isGroupDM() || channel.isMultiUserDM())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// check for disallowed voice channels too so that they get hidden when collapsing the category
|
|
|
|
channel._isHiddenChannel = !can(VIEW_CHANNEL, channel) || (channel.type === 2 && !can(CONNECT, channel));
|
2022-10-23 09:44:21 +00:00
|
|
|
return channel._isHiddenChannel;
|
|
|
|
},
|
|
|
|
channelSelected(channelData) {
|
2022-10-24 21:22:39 +00:00
|
|
|
if (!channelData) return false;
|
2022-10-23 09:44:21 +00:00
|
|
|
const channel = ChannelStore.getChannel(channelData.channelId);
|
2022-10-24 21:22:39 +00:00
|
|
|
if (!channel) return false;
|
2022-10-23 09:44:21 +00:00
|
|
|
const isHidden = this.isHiddenChannel(channel);
|
2022-10-24 21:22:39 +00:00
|
|
|
// check for type again, otherwise it would show it for hidden stage channels
|
|
|
|
if (channel.type === 0 && isHidden) {
|
|
|
|
const lastMessageDate = channel.lastActiveTimestamp ? new Date(channel.lastActiveTimestamp).toLocaleString() : null;
|
|
|
|
|
2022-10-23 09:44:21 +00:00
|
|
|
openModal(modalProps => (
|
|
|
|
<ModalRoot size={ModalSize.SMALL} {...modalProps}>
|
|
|
|
<ModalHeader>
|
|
|
|
<Flex>
|
|
|
|
<Text variant="heading-md/bold">{channel.name}</Text>
|
|
|
|
{(channel.isNSFW() && (
|
|
|
|
<Text style={{ backgroundColor: "var(--status-danger)", borderRadius: "8px", paddingLeft: 4, paddingRight: 4 }} variant="heading-md/normal">
|
|
|
|
NSFW
|
|
|
|
</Text>
|
|
|
|
))}
|
|
|
|
</Flex>
|
|
|
|
</ModalHeader>
|
|
|
|
<ModalContent style={{ marginBottom: 10, marginTop: 10, marginRight: 8, marginLeft: 8 }}>
|
|
|
|
<Text variant="text-md/normal">You don't have the permission to view the messages in this channel.</Text>
|
|
|
|
{(channel.topic || "").length > 0 && (
|
|
|
|
<>
|
|
|
|
<Text variant="text-md/bold" style={{ marginTop: 10 }}>
|
|
|
|
Topic:
|
|
|
|
</Text>
|
|
|
|
<Text variant="code">{channel.topic}</Text>
|
|
|
|
</>
|
|
|
|
)}
|
2022-10-24 21:22:39 +00:00
|
|
|
{lastMessageDate && (
|
|
|
|
<>
|
|
|
|
<Text variant="text-md/bold" style={{ marginTop: 10 }}>
|
|
|
|
Last message sent:
|
|
|
|
</Text>
|
|
|
|
<Text variant="code">{lastMessageDate}</Text>
|
|
|
|
</>
|
|
|
|
)}
|
2022-10-23 09:44:21 +00:00
|
|
|
</ModalContent>
|
|
|
|
<ModalFooter>
|
|
|
|
<Flex>
|
|
|
|
<Button
|
|
|
|
onClick={modalProps.onClose}
|
|
|
|
size={Button.Sizes.SMALL}
|
|
|
|
color={Button.Colors.PRIMARY}
|
|
|
|
>
|
|
|
|
Continue
|
|
|
|
</Button>
|
|
|
|
</Flex>
|
|
|
|
</ModalFooter>
|
|
|
|
</ModalRoot>
|
|
|
|
));
|
2022-10-24 21:22:39 +00:00
|
|
|
}
|
2022-10-23 09:44:21 +00:00
|
|
|
return isHidden;
|
|
|
|
}
|
|
|
|
});
|