-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (89 loc) · 2.64 KB
/
index.js
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
const {
entities: { Plugin },
webpack: { React, getModule, getModuleByDisplayName },
util: { getOwnerInstance, getReactInstance, findInReactTree },
injector: { inject, uninject },
} = require("powercord");
const Settings = require("./components/Settings");
const BetterRepliedMessage = require("./components/BetterRepliedMessage");
const RepliedMessage = getModule(
(m) => m?.default?.displayName === "RepliedMessage",
false
);
const ChatChannelMessage = getModule(
(m) =>
m.type &&
(m.__powercordOriginal_type || m.type)
.toString()
.indexOf("useContextMenuMessage") !== -1,
false
);
const SearchChannelMessage = getModule(
(m) => m?.type?.displayName === "ChannelMessage",
false
);
module.exports = class BetterReplies extends (
Plugin
) {
async startPlugin() {
this.loadStylesheet("style.scss");
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: "Better Replies",
render: (settings) =>
React.createElement(Settings, {
settings,
plugin: this,
settingsID: this.entityID,
}),
});
inject(
"better-replies-chat-channel-message",
ChatChannelMessage,
"type",
this.channelMessage
);
ChatChannelMessage.type.displayName = "ChannelMessage";
inject(
"better-replies-search-channel-message",
SearchChannelMessage,
"type",
this.channelMessage
);
SearchChannelMessage.type.displayName = "ChannelMessage";
window.KLibrary?.Tools?.ReactTools?.rerenderAllMessages();
}
pluginWillUnload() {
uninject("better-replies-chat-channel-message");
uninject("better-replies-search-channel-message");
powercord.api.settings.unregisterSettings(this.entityID);
window.KLibrary?.Tools?.ReactTools?.rerenderAllMessages();
}
channelMessage = (args, res) => {
const repliedMessage = args?.[0]?.message?.messageReference;
const depth = parseInt(res.props?.id?.split("depth-")?.[1] ?? 0);
const messageElement =
findInReactTree(res, (r) => r.childrenRepliedMessage) ?? res.props;
if (
args?.[0]?.message?.messageReference &&
depth < this.settings.get("max-depth", 2)
) {
messageElement.childrenRepliedMessage = React.createElement(
BetterRepliedMessage,
{
referenceMode:
res.props.referenceMode ??
this.settings.get("reference-mode", "auto"),
referenceStyle:
res.props.referenceStyle ??
this.settings.get("reference-style", "better"),
settings: this.settings,
depth: depth + 1,
message_id: repliedMessage?.message_id,
channel_id: repliedMessage?.channel_id,
}
);
}
return res;
};
};