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

This commit is contained in:
rini 2023-10-25 12:34:23 -03:00 committed by Luna
parent 81a31ff290
commit 2893dc492c
6 changed files with 34 additions and 56 deletions

View file

@ -38,17 +38,10 @@ export default definePlugin({
}, },
{ {
find: "PrivateChannel.renderAvatar", find: "PrivateChannel.renderAvatar",
replacement: [ 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/, match: /decorators:(\i\.isSystemDM\(\))\?(.+?):null/,
replace: "decorators:[...(typeof vencordProps=='undefined'?[]:Vencord.Api.MemberListDecorators.__getDecorators(vencordProps)), $1?$2:null]" replace: "decorators:[...Vencord.Api.MemberListDecorators.__getDecorators(arguments[0]), $1?$2:null]"
} }
]
} }
], ],
}); });

View file

@ -25,7 +25,7 @@ export default definePlugin({
authors: [Devs.TheSun], authors: [Devs.TheSun],
patches: [ patches: [
{ {
find: "UsernameDecorationTypes:", find: '"Message Username"',
replacement: { replacement: {
match: /currentUserIsPremium:.{0,70}{children:\i(?=}\))/, match: /currentUserIsPremium:.{0,70}{children:\i(?=}\))/,
replace: "$&.concat(Vencord.Api.MessageDecorations.__addDecorationsToMessage(arguments[0]))" 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 // 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 // pinCount as prop. This needs to be here so that the entire DM list receives
// updates on pin/unpin // 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)," 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 1: buttons for pages like Friends & Library
// - Section 2: our pinned dms // - Section 2: our pinned dms
// - Section 3: the normal dm list // - 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 // For some reason, adding our sections when no private channels are ready yet
// makes DMs infinitely load. Thus usePinCount returns either a single element // 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 // 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 // case will an element be added to the outer array
// Thanks for the fix, Strencher! // 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" // 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 // lookbehind is used to lookup parameter name. We could use arguments[0], but
// if children ever is wrapped in an iife, it will break // 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" replace: "children:$2.section===1?'Pinned DMs':$1"
}, },
{ {
// Patch channel lookup inside renderDM // Patch channel lookup inside renderDM
// channel=channels[channelIds[row]]; // 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 is us, manually get our own channel
// section === 1 ? getChannel(channels, row) : channels[channelIds[row]]; // 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 // Fix getRowHeight's check for whether this is the DMs section
// section === DMS // section === DMS
match: /===\i.DMS&&0/, match: /===\i\.DMS&&0/,
// section -1 === DMS // section -1 === DMS
replace: "-1$&" replace: "-1$&"
}, },
{ {
// Override scrollToChannel to properly account for pinned channels // 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,$&)" replace: "$self.getScrollOffset(arguments[0],$1,this.props.padding,this.state.preRenderedChildren,$&)"
} }
] ]
@ -115,19 +115,19 @@ export default definePlugin({
// Fix Alt Up/Down navigation // Fix Alt Up/Down navigation
{ {
find: '"mod+alt+right"', find: ".Routes.APPLICATION_STORE&&",
replacement: { replacement: {
// channelIds = __OVERLAY__ ? stuff : toArray(getStaticPaths()).concat(toArray(channelIds)) // channelIds = __OVERLAY__ ? stuff : [...getStaticPaths(),...channelIds)]
match: /(?<=(\i)=__OVERLAY__\?\i:.{0,10})\.concat\((.{0,10})\)/, match: /(?<=\i=__OVERLAY__\?\i:\[\.\.\.\i\(\),\.\.\.)\i/,
// ....concat(pins).concat(toArray(channelIds).filter(c => !isPinned(c))) // ....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 // fix alt+shift+up/down
{ {
find: '"alt+shift+down"', find: ".getFlattenedGuildIds()],",
replacement: { 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)))" replace: "$self.getSnapshot().concat($&.filter(c=>!$self.isPinned(c)))"
} }
}, },

View file

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

View file

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

View file

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