-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
127 lines (101 loc) · 4.07 KB
/
Copy pathindex.js
File metadata and controls
127 lines (101 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* eslint-disable new-cap */
const { Plugin } = require('powercord/entities');
const { React, getModule, constants: { Routes, ActionTypes }, FluxDispatcher, getModuleByDisplayName } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const { AsyncComponent } = require('powercord/components');
const { wrapInHooks } = require('powercord/util');
const Popout = AsyncComponent.fromDisplayName('Popout');
const UserPopoutContainer = AsyncComponent.from(getModule(m => m.type?.displayName === 'UserPopoutContainer'));
const { transitionTo } = getModule([ 'transitionTo' ], false);
const channelStore = getModule([ 'getDMFromUserId', 'getChannel' ], false);
const { openUserContextMenu } = getModule([ 'openUserContextMenu' ], false);
const userStore = getModule([ 'initialize', 'getCurrentUser' ], false);
const { getChannel } = getModule([ 'initialize', 'hasChannel' ], false);
module.exports = class ClickableMentions extends Plugin {
startPlugin () {
this.classes = {
...getModule([ 'cursorDefault', 'cursorPointer' ], false)
} || {};
this.patchRichMentions();
}
patchRichMentions () {
const DiscordRichComponents = getModule([ 'RoleMention', 'UserMention' ], false);
console.log(DiscordRichComponents); // Used to see what else we can patch :P
inject('clickable-umentions-slate', DiscordRichComponents, 'UserMention', (args, res) => {
const [ props ] = args;
const { children } = res?.props || {};
if (!children) {
return res;
}
if (typeof children === 'function') {
const tooltipChildren = children;
res.props.children = (tooltipProps) => this.renderUserPopout(props, tooltipChildren(tooltipProps));
} else {
res = this.renderUserPopout(props, children);
}
return res;
});
inject('clickable-cmentions-slate', DiscordRichComponents, 'ChannelMention', ([ { id: channelId } ], res) => {
const { children } = res?.props || {};
if (!children) {
return res;
}
res = React.createElement('div', {
onClick: () => {
let guildId, messageId;
FluxDispatcher.dirtyDispatch({ type: ActionTypes.LAYER_POP });
if (channelId) {
const channel = channelStore.getChannel(channelId);
if (!channel) {
return;
}
guildId = channel.guild_id;
messageId = channel.lastMessageId;
}
transitionTo(Routes.CHANNEL(guildId, channelId, messageId));
},
onContextMenu: (event) => {
const channel = channelStore.getChannel(channelId);
if (!channel) {
return;
}
let ConnectedChannel;
if (channel.isVocal()) {
ConnectedChannel = getModuleByDisplayName('ConnectedVoiceChannel', false);
} else {
ConnectedChannel = getModuleByDisplayName('ConnectedTextChannel', false);
}
return (
wrapInHooks(() => new ConnectedChannel({ channel,
guild: {} }))()
).type.DecoratedComponent({ channel }).prototype.constructor.handleContextMenu(event);
}
}, res);
return res;
});
}
renderUserPopout (props, children) {
if (!children.props) {
return children;
}
children.props.className = [ children.props.className, this.classes.cursorPointer ].filter(Boolean).join(' ');
return React.createElement(Popout, {
renderPopout: (popoutProps) => React.createElement(UserPopoutContainer, {
...popoutProps,
userId: props.id ?? null,
channelId: props.channelId ?? null,
guildId: props.guildId ?? null
}),
position: 'top'
}, (popoutProps) => {
children.props = Object.assign({}, children.props, popoutProps, { onContextMenu: (e) => {
openUserContextMenu(e, userStore.getUser(props.id ?? null), getChannel(props.channelId ?? null));
} });
return children;
});
}
pluginWillUnload () {
uninject('clickable-umentions-slate');
uninject('clickable-cmentions-slate');
}
};