-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMHistory.plugin.js
77 lines (66 loc) · 2.02 KB
/
DMHistory.plugin.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
/**
* @name DMHistory
* @description Allows you to see users that DMs have closed or users you've directly messaged
* @author kaan
* @version 1.0.4
*/
const { Patcher, Webpack, React } = BdApi;
class DMHistory {
constructor() {
this.Settings = BdApi.React.createContext();
this.PrivateDMs = Webpack.getByKeys("openPrivateChannel");
this.FriendRow = Webpack.getByStrings("isActiveRow:!1");
this.PresenceStore = BdApi.Webpack.getStore("PresenceStore");
this.UserStore = BdApi.Webpack.getStore("UserStore");
this.ChannelStore = BdApi.Webpack.getStore("ChannelStore");
}
start() {
this.Patch = Patcher.before(
"IforgotANameIaHateBetterDiscord",
this.PrivateDMs,
"closePrivateChannel",
(a, b) => {
const ClosedChannel = b[0];
const Channel = this.ChannelStore.getChannel(ClosedChannel);
Channel.recipients.forEach( (userId) => {
let Users = BdApi.Data.load("DMHistory", "ClosedUsers") || [];
if (!Users?.includes(userId)) Users.push(userId);
BdApi.Data.save("DMHistory", "ClosedUsers", Users);
} )
}
);
}
stop() {
this.Patch();
}
getSettingsPanel() {
return React.createElement(
this.Settings.Provider,
{ value: this },
React.createElement(this.SettingsPanel.bind(this))
);
}
SettingsPanel() {
const Users = BdApi.Data.load("DMHistory", "ClosedUsers") || [];
const UserRows = [];
Users.forEach( (userId) => {
if (userId) {
UserRows.push(
React.createElement(this.FriendRow, {
user: this.UserStore.getUser(userId),
activities: [],
type: 1,
status: this.PresenceStore.getStatus(userId),
})
);
}
})
const maxPanelHeight = "300px";
const panelStyle = {
maxHeight: maxPanelHeight,
overflowY: "auto",
};
return React.createElement("div", { style: panelStyle }, UserRows);
}
}
module.exports = DMHistory;