Fix PinDMs, SMYN, SilentTyping, ValidUser, PlatformIndicators (#1865)

This commit is contained in:
rini 2023-10-25 12:34:23 -03:00 committed by V
parent c5dd50ad8f
commit 9c60b38acc
6 changed files with 34 additions and 56 deletions

View File

@ -38,17 +38,10 @@ export default definePlugin({
},
{
find: "PrivateChannel.renderAvatar",
replacement: [
// props are shadowed by nested props so we have to do this
{
match: /let\{[^}]*applicationStream:\i[^}]*\}=(\i),/,
replace: "$&vencordProps=$1,"
},
{
match: /decorators:(\i\.isSystemDM\(\))\?(.+?):null/,
replace: "decorators:[...(typeof vencordProps=='undefined'?[]:Vencord.Api.MemberListDecorators.__getDecorators(vencordProps)), $1?$2:null]"
}
]
replacement: {
match: /decorators:(\i\.isSystemDM\(\))\?(.+?):null/,
replace: "decorators:[...Vencord.Api.MemberListDecorators.__getDecorators(arguments[0]), $1?$2:null]"
}
}
],
});

View File

@ -25,7 +25,7 @@ export default definePlugin({
authors: [Devs.TheSun],
patches: [
{
find: "UsernameDecorationTypes:",
find: '"Message Username"',
replacement: {
match: /currentUserIsPremium:.{0,70}{children:\i(?=}\))/,
replace: "$&.concat(Vencord.Api.MessageDecorations.__addDecorationsToMessage(arguments[0]))"

View File

@ -66,7 +66,7 @@ export default definePlugin({
// filter Discord's privateChannelIds list to remove pins, and pass
// pinCount as prop. This needs to be here so that the entire DM list receives
// updates on pin/unpin
match: /privateChannelIds:(\i),/,
match: /(?<=\i,{channels:\i,)privateChannelIds:(\i),/,
replace: "privateChannelIds:$1.filter(c=>!$self.isPinned(c)),pinCount:$self.usePinCount($1),"
},
{
@ -75,39 +75,39 @@ export default definePlugin({
// - Section 1: buttons for pages like Friends & Library
// - Section 2: our pinned dms
// - Section 3: the normal dm list
match: /(?<=renderRow:(\i)\.renderRow,)sections:\[\i,/,
match: /(?<=renderRow:this\.renderRow,)sections:\[\i,/,
// For some reason, adding our sections when no private channels are ready yet
// makes DMs infinitely load. Thus usePinCount returns either a single element
// array with the count, or an empty array. Due to spreading, only in the former
// case will an element be added to the outer array
// Thanks for the fix, Strencher!
replace: "$&...($1.props.pinCount ?? []),"
replace: "$&...this.props.pinCount??[],"
},
{
// Patch renderSection (renders the header) to set the text to "Pinned DMs" instead of "Direct Messages"
// lookbehind is used to lookup parameter name. We could use arguments[0], but
// if children ever is wrapped in an iife, it will break
match: /children:(\i\.\i\.Messages.DIRECT_MESSAGES)(?<=renderSection=function\((\i)\).+?)/,
match: /children:(\i\.\i\.Messages.DIRECT_MESSAGES)(?<=renderSection=(\i)=>{.+?)/,
replace: "children:$2.section===1?'Pinned DMs':$1"
},
{
// Patch channel lookup inside renderDM
// channel=channels[channelIds[row]];
match: /(?<=preRenderedChildren,(\i)=)((\i)\[\i\[\i\]\]);/,
match: /(?<=renderDM=\((\i),(\i)\)=>{.*?this.state,\i=\i\[\i\],\i=)((\i)\[\i\]);/,
// section 1 is us, manually get our own channel
// section === 1 ? getChannel(channels, row) : channels[channelIds[row]];
replace: "arguments[0]===1?$self.getChannel($3,arguments[1]):$2;"
replace: "$1===1?$self.getChannel($4,$2):$3;"
},
{
// Fix getRowHeight's check for whether this is the DMs section
// section === DMS
match: /===\i.DMS&&0/,
match: /===\i\.DMS&&0/,
// section -1 === DMS
replace: "-1$&"
},
{
// Override scrollToChannel to properly account for pinned channels
match: /(?<=else\{\i\+=)(\i)\*\(.+?(?=;)/,
match: /(?<=scrollTo\(\{to:\i\}\):\(\i\+=)(\d+)\*\(.+?(?=,)/,
replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)"
}
]
@ -115,19 +115,19 @@ export default definePlugin({
// Fix Alt Up/Down navigation
{
find: '"mod+alt+right"',
find: ".Routes.APPLICATION_STORE&&",
replacement: {
// channelIds = __OVERLAY__ ? stuff : toArray(getStaticPaths()).concat(toArray(channelIds))
match: /(?<=(\i)=__OVERLAY__\?\i:.{0,10})\.concat\((.{0,10})\)/,
// channelIds = __OVERLAY__ ? stuff : [...getStaticPaths(),...channelIds)]
match: /(?<=\i=__OVERLAY__\?\i:\[\.\.\.\i\(\),\.\.\.)\i/,
// ....concat(pins).concat(toArray(channelIds).filter(c => !isPinned(c)))
replace: ".concat($self.getSnapshot()).concat($2.filter(c=>!$self.isPinned(c)))"
replace: "$self.getSnapshot().concat($&.filter(c=>!$self.isPinned(c)))"
}
},
// fix alt+shift+up/down
{
find: '"alt+shift+down"',
find: ".getFlattenedGuildIds()],",
replacement: {
match: /(?<=return \i===\i\.ME\?)\i\.\i\.getPrivateChannelIds\(\)/,
match: /(?<=\i===\i\.ME\?)\i\.\i\.getPrivateChannelIds\(\)/,
replace: "$self.getSnapshot().concat($&.filter(c=>!$self.isPinned(c)))"
}
},

View File

@ -1,20 +1,8 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Sofia Lima
*
* 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/>.
*/
* Vencord, a Discord client mod
* Copyright (c) 2023 rini
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./styles.css";
@ -56,13 +44,13 @@ const settings = definePluginSettings({
export default definePlugin({
name: "ShowMeYourName",
description: "Display usernames next to nicks, or no nicks at all",
authors: [Devs.dzshn, Devs.TheKodeToad],
authors: [Devs.Rini, Devs.TheKodeToad],
patches: [
{
find: ".withMentionPrefix",
find: '"Message Username"',
replacement: {
match: /(?<=onContextMenu:\i,children:)\i\+\i/,
replace: "$self.renderUsername(arguments[0])"
match: /(?<=onContextMenu:\i,children:).*?\}/,
replace: "$self.renderUsername(arguments[0])}"
}
},
],

View File

@ -74,13 +74,13 @@ function SilentTypingToggle(chatBoxProps: {
export default definePlugin({
name: "SilentTyping",
authors: [Devs.Ven, Devs.dzshn],
authors: [Devs.Ven, Devs.Rini],
description: "Hide that you are typing",
patches: [
{
find: "startTyping:",
find: '.dispatch({type:"TYPING_START_LOCAL"',
replacement: {
match: /startTyping:.+?,stop/,
match: /startTyping\(\i\){.+?},stop/,
replace: "startTyping:$self.startTyping,stop"
}
},

View File

@ -21,14 +21,11 @@ import { Devs } from "@utils/constants";
import { sleep } from "@utils/misc";
import { Queue } from "@utils/Queue";
import definePlugin from "@utils/types";
import { findByCodeLazy } from "@webpack";
import { UserStore, useState } from "@webpack/common";
import type { User } from "discord-types/general";
import { UserStore, UserUtils, useState } from "@webpack/common";
import type { ComponentType, ReactNode } from "react";
const fetching = new Set<string>();
const queue = new Queue(5);
const fetchUser = findByCodeLazy("USER(") as (id: string) => Promise<User>;
interface MentionProps {
data: {
@ -88,7 +85,7 @@ function MentionWrapper({ data, UserMention, RoleMention, parse, props }: Mentio
fetching.add(id);
queue.unshift(() =>
fetchUser(id)
UserUtils.getUser(id)
.then(() => {
setUserId(id);
fetching.delete(id);
@ -122,9 +119,9 @@ export default definePlugin({
find: 'className:"mention"',
replacement: {
// mention = { react: function (data, parse, props) { if (data.userId == null) return RoleMention() else return UserMention()
match: /react:(?=function\(\i,\i,\i\).{0,50}return null==\i\?\(0,\i\.jsx\)\((\i),.+?jsx\)\((\i),\{className:"mention")/,
match: /react(?=\(\i,\i,\i\).{0,50}return null==\i\?\(0,\i\.jsx\)\((\i\.\i),.+?jsx\)\((\i\.\i),\{className:"mention")/,
// react: (...args) => OurWrapper(RoleMention, UserMention, ...args), originalReact: theirFunc
replace: "react:(...args)=>$self.renderMention($1,$2,...args),originalReact:"
replace: "react:(...args)=>$self.renderMention($1,$2,...args),originalReact"
}
}],