Skip to content

Commit 1cdb123

Browse files
committed
resolver fixes and mentionAvatars resolver compat
1 parent b7d24c8 commit 1cdb123

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

src/mentionAvatars/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"$schema": "https://moonlight-mod.github.io/manifest.schema.json",
33
"id": "mentionAvatars",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"meta": {
66
"name": "Mention Avatars",
77
"tagline": "Shows avatars on user mentions",
88
"authors": ["Cynosphere"],
99
"tags": ["qol", "chat"],
1010
"source": "https://github.com/Cynosphere/moonlight-extensions",
1111
"donate": "https://ko-fi.com/Cynosphere",
12-
"changelog": "Fixes for latest Discord for the last time (relies on remapped name now)"
12+
"changelog": "Null user checking and compatibility with embed mentions updated by Resolver"
1313
},
1414
"dependencies": ["common"],
1515
"settings": {

src/mentionAvatars/webpackModules/avatar.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,17 @@ import { Avatar, AvatarSizes } from "@moonlight-mod/wp/discord/components/common
55
import { ChannelStore, UserStore } from "@moonlight-mod/wp/common_stores";
66

77
type MessageAvatarProps = {
8-
userId: string;
8+
userId: string | undefined;
9+
parsedUserId?: string;
910
channelId: string;
1011
};
1112

12-
export default function MessageAvatar({ userId, channelId }: MessageAvatarProps) {
13-
const user = useStateFromStores([UserStore], () => UserStore.getUser(userId)!, [userId]);
13+
export default function MessageAvatar({ userId, parsedUserId, channelId }: MessageAvatarProps) {
14+
const user = useStateFromStores([UserStore], () => UserStore.getUser(userId ?? parsedUserId), [userId, parsedUserId]);
1415
const channel = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(channelId), [channelId]);
1516
const guildId = channel?.getGuildId();
1617

17-
return (
18-
<Avatar
19-
// @ts-expect-error fixed next mappings
20-
className="mentionAvatar"
21-
src={user.getAvatarURL(guildId, 16)}
22-
// @ts-expect-error fixed next mappings
23-
size={AvatarSizes.SIZE_16}
24-
/>
18+
return user == null ? null : (
19+
<Avatar className="mentionAvatar" src={user.getAvatarURL(guildId, 16)} size={AvatarSizes.SIZE_16} />
2520
);
2621
}

src/resolver/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { ExtensionWebpackModule } from "@moonlight-mod/types";
1+
import { ExtensionWebpackModule, Patch } from "@moonlight-mod/types";
2+
3+
export const patches: Patch[] = [
4+
{
5+
find: "discord/modules/messages/web/UserMention",
6+
replace: [
7+
{
8+
match: /\.default\.getUser\((\i)\)/,
9+
replacement: (_, id) => `.default.getUser(${id}??arguments[0].parsedUserId)`
10+
}
11+
]
12+
}
13+
];
214

315
export const webpackModules: Record<string, ExtensionWebpackModule> = {
416
user: {

src/resolver/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"$schema": "https://moonlight-mod.github.io/manifest.schema.json",
33
"id": "resolver",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"meta": {
66
"name": "Resolver",
77
"tagline": "Resolve uncached users",
88
"description": "User resolving is done through the unknown user mention context menu, it is not and never will be automatic.\n\n-# More features eventually\u2122",
99
"authors": ["Cynosphere"],
1010
"tags": ["fixes", "chat"],
1111
"source": "https://github.com/Cynosphere/moonlight-extensions",
12-
"donate": "https://ko-fi.com/Cynosphere"
12+
"donate": "https://ko-fi.com/Cynosphere",
13+
"changelog": "Fixes for latest Discord and mentions in embeds"
1314
},
1415
"dependencies": ["contextMenu", "spacepack"],
1516
"apiLevel": 2

src/resolver/webpackModules/user.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
33
import { addItem, MenuItem } from "@moonlight-mod/wp/contextMenu_contextMenu";
44
import { ToastType, createToast, showToast } from "@moonlight-mod/wp/discord/components/common/index";
55

6-
const { getUser } = spacepack.require("discord/actions/UserActionCreators");
6+
const UserActionCreators = spacepack.require("discord/actions/UserActionCreators");
7+
// TODO: fix mapping
8+
const getUser = spacepack.findFunctionByStrings(
9+
UserActionCreators,
10+
".get({url:",
11+
".USER(",
12+
'.dispatch({type:"USER_UPDATE",user:'
13+
)!;
714
const { openUserProfileModal } = spacepack.require("discord/actions/UserProfileModalActionCreators");
815

916
const logger = moonlight.getLogger("Resolver");

0 commit comments

Comments
 (0)