MutualGroupDMs: Fix in DM sidebar when no mutual friends/servers (#2976)
This commit is contained in:
parent
6628624082
commit
df454ca952
1 changed files with 36 additions and 16 deletions
|
@ -19,6 +19,7 @@
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { isNonNullish } from "@utils/guards";
|
import { isNonNullish } from "@utils/guards";
|
||||||
|
import { Logger } from "@utils/Logger";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin from "@utils/types";
|
||||||
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
||||||
import { Avatar, ChannelStore, Clickable, IconUtils, RelationshipStore, ScrollerThin, useMemo, UserStore } from "@webpack/common";
|
import { Avatar, ChannelStore, Clickable, IconUtils, RelationshipStore, ScrollerThin, useMemo, UserStore } from "@webpack/common";
|
||||||
|
@ -87,7 +88,7 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /\i\.useEffect.{0,100}(\i)\[0\]\.section/,
|
match: /\i\.useEffect.{0,100}(\i)\[0\]\.section/,
|
||||||
replace: "$self.pushSection($1, arguments[0].user);$&"
|
replace: "$self.pushSection($1,arguments[0].user);$&"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /\(0,\i\.jsx\)\(\i,\{items:\i,section:(\i)/,
|
match: /\(0,\i\.jsx\)\(\i,\{items:\i,section:(\i)/,
|
||||||
|
@ -97,14 +98,32 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: 'section:"MUTUAL_FRIENDS"',
|
find: 'section:"MUTUAL_FRIENDS"',
|
||||||
replacement: {
|
replacement: [
|
||||||
match: /\.openUserProfileModal.+?\)}\)}\)(?<=(\(0,\i\.jsxs?\)\(\i\.\i,{className:(\i)\.divider}\)).+?)/,
|
{
|
||||||
replace: "$&,$self.renderDMPageList({user: arguments[0].user, Divider: $1, listStyle: $2.list})"
|
match: /\i\|\|\i(?=\?\(0,\i\.jsxs?\)\(\i\.\i\.Overlay,)/,
|
||||||
|
replace: "$&||$self.getMutualGroupDms(arguments[0].user.id).length>0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: /\.openUserProfileModal.+?\)}\)}\)(?<=,(\i)&&(\i)&&(\(0,\i\.jsxs?\)\(\i\.\i,{className:(\i)\.divider}\)).+?)/,
|
||||||
|
replace: (m, hasMutualGuilds, hasMutualFriends, Divider, classes) => "" +
|
||||||
|
`${m},$self.renderDMPageList({user:arguments[0].user,hasDivider:${hasMutualGuilds}||${hasMutualFriends},Divider:${Divider},listStyle:${classes}.list})`
|
||||||
}
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
getMutualGroupDms(userId: string) {
|
||||||
|
try {
|
||||||
|
return getMutualGroupDms(userId);
|
||||||
|
} catch (e) {
|
||||||
|
new Logger("MutualGroupDMs").error("Failed to get mutual group dms:", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
|
||||||
pushSection(sections: any[], user: User) {
|
pushSection(sections: any[], user: User) {
|
||||||
|
try {
|
||||||
if (isBotOrSelf(user) || sections[IS_PATCHED]) return;
|
if (isBotOrSelf(user) || sections[IS_PATCHED]) return;
|
||||||
|
|
||||||
sections[IS_PATCHED] = true;
|
sections[IS_PATCHED] = true;
|
||||||
|
@ -112,11 +131,13 @@ export default definePlugin({
|
||||||
section: "MUTUAL_GDMS",
|
section: "MUTUAL_GDMS",
|
||||||
text: getMutualGDMCountText(user)
|
text: getMutualGDMCountText(user)
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
new Logger("MutualGroupDMs").error("Failed to push mutual group dms section:", e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => {
|
renderMutualGDMs: ErrorBoundary.wrap(({ user, onClose }: { user: User, onClose: () => void; }) => {
|
||||||
const mutualGDms = useMemo(() => getMutualGroupDms(user.id), [user.id]);
|
const mutualGDms = useMemo(() => getMutualGroupDms(user.id), [user.id]);
|
||||||
|
|
||||||
const entries = renderClickableGDMs(mutualGDms, onClose);
|
const entries = renderClickableGDMs(mutualGDms, onClose);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -138,14 +159,13 @@ export default definePlugin({
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
renderDMPageList: ErrorBoundary.wrap(({ user, Divider, listStyle }: { user: User, Divider: JSX.Element, listStyle: string; }) => {
|
renderDMPageList: ErrorBoundary.wrap(({ user, hasDivider, Divider, listStyle }: { user: User, hasDivider: boolean, Divider: JSX.Element, listStyle: string; }) => {
|
||||||
const mutualGDms = getMutualGroupDms(user.id);
|
const mutualGDms = getMutualGroupDms(user.id);
|
||||||
if (mutualGDms.length === 0) return null;
|
if (mutualGDms.length === 0) return null;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{Divider}
|
{hasDivider && Divider}
|
||||||
<ExpandableList
|
<ExpandableList
|
||||||
listClassName={listStyle}
|
listClassName={listStyle}
|
||||||
header={"Mutual Groups"}
|
header={"Mutual Groups"}
|
||||||
|
|
Loading…
Reference in a new issue