Update LastMessageDate.plugin.js
This commit is contained in:
parent
3d1fd09dcb
commit
5c6c4a2e3c
|
@ -2,7 +2,7 @@
|
|||
* @name LastMessageDate
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 1.3.1
|
||||
* @version 1.3.2
|
||||
* @description Displays the Last Message Date of a Member for the current Server/DM in the UserPopout and UserModal
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -57,9 +57,69 @@ module.exports = (_ => {
|
|||
}
|
||||
} : (([Plugin, BDFDB]) => {
|
||||
var _this;
|
||||
var loadedUsers, requestedUsers, queuedInstances, languages;
|
||||
var loadedUsers, requestedUsers, queuedInstances;
|
||||
var currentPopout, currentProfile;
|
||||
|
||||
const LastMessageDateComponents = class LastMessageDate extends BdApi.React.Component {
|
||||
render() {
|
||||
if (!loadedUsers[this.props.guildId]) loadedUsers[this.props.guildId] = {};
|
||||
if (!requestedUsers[this.props.guildId]) requestedUsers[this.props.guildId] = {};
|
||||
if (!queuedInstances[this.props.guildId]) queuedInstances[this.props.guildId] = {};
|
||||
if (loadedUsers[this.props.guildId][this.props.user.id] === undefined && !requestedUsers[this.props.guildId][this.props.user.id]) {
|
||||
requestedUsers[this.props.guildId][this.props.user.id] = true;
|
||||
queuedInstances[this.props.guildId][this.props.user.id] = [].concat(queuedInstances[this.props.guildId][this.props.user.id]).filter(n => n);
|
||||
BDFDB.LibraryModules.APIUtils.get({
|
||||
url: this.props.isGuild ? BDFDB.DiscordConstants.Endpoints.SEARCH_GUILD(this.props.guildId) : BDFDB.DiscordConstants.Endpoints.SEARCH_CHANNEL(this.props.channelId),
|
||||
query: BDFDB.LibraryModules.APIEncodeUtils.stringify({author_id: this.props.user.id})
|
||||
}).then(result => {
|
||||
delete requestedUsers[this.props.guildId][this.props.user.id];
|
||||
if (typeof result.body.retry_after != "number") {
|
||||
if (result.body.messages && Array.isArray(result.body.messages[0])) {
|
||||
for (let message of result.body.messages[0]) if (message.hit && message.author.id == this.props.user.id) loadedUsers[this.props.guildId][this.props.user.id] = message;
|
||||
}
|
||||
else loadedUsers[this.props.guildId][this.props.user.id] = null;
|
||||
BDFDB.ReactUtils.forceUpdate(queuedInstances[this.props.guildId][this.props.user.id]);
|
||||
delete queuedInstances[this.props.guildId][this.props.user.id];
|
||||
}
|
||||
else BDFDB.TimeUtils.timeout(_ => BDFDB.ReactUtils.forceUpdate(this), result.body.retry_after + 500);
|
||||
});
|
||||
}
|
||||
if (loadedUsers[this.props.guildId][this.props.user.id] === undefined) {
|
||||
if (queuedInstances[this.props.guildId][this.props.user.id].indexOf(this) == -1) queuedInstances[this.props.guildId][this.props.user.id].push(this);
|
||||
return null;
|
||||
}
|
||||
let channel = loadedUsers[this.props.guildId][this.props.user.id] && BDFDB.LibraryStores.ChannelStore.getChannel(loadedUsers[this.props.guildId][this.props.user.id].channel_id);
|
||||
let icon = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
|
||||
className: BDFDB.disCN._lastmessagedateicon,
|
||||
nativeClass: false,
|
||||
name: BDFDB.LibraryComponents.SvgIcon.Names.NUMPAD
|
||||
});
|
||||
return BDFDB.ReactUtils.createElement(this.props.isInPopout ? BDFDB.LibraryComponents.UserPopoutSection : BDFDB.ReactUtils.Fragment, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Heading, {
|
||||
className: !this.props.isInPopout ? BDFDB.disCN.userprofileinfosectionheader : BDFDB.disCN.userpopoutsectiontitle,
|
||||
variant: "eyebrow",
|
||||
children: _this.labels.last_message
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.membersince, !this.props.isInPopout && BDFDB.disCN.userprofileinfotext),
|
||||
children: [
|
||||
!channel ? icon : BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
text: channel.guild_id ? "#" + channel.name : BDFDB.LanguageUtils.LanguageStrings.DIRECT_MESSAGES,
|
||||
children: icon
|
||||
}),
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Text, {
|
||||
className: this.props.isInPopout && BDFDB.disCN.userpopoutsectionbody,
|
||||
variant: "text-sm/normal",
|
||||
children: loadedUsers[this.props.guildId][this.props.user.id] ? BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.lastMessageDate, new Date(loadedUsers[this.props.guildId][this.props.user.id].timestamp)) : "---"
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return class LastMessageDate extends Plugin {
|
||||
onLoad () {
|
||||
_this = this;
|
||||
|
@ -68,9 +128,6 @@ module.exports = (_ => {
|
|||
queuedInstances = {};
|
||||
|
||||
this.defaults = {
|
||||
general: {
|
||||
displayText: {value: true, description: "Display '{{presuffix}}' in the Date"}
|
||||
},
|
||||
places: {
|
||||
userPopout: {value: true, description: "User Popouts"},
|
||||
userProfile: {value: true, description: "User Profile Modal"}
|
||||
|
@ -80,16 +137,24 @@ module.exports = (_ => {
|
|||
}
|
||||
};
|
||||
|
||||
this.patchedModules = {
|
||||
after: {
|
||||
UserPopoutExperimentWrapper: "default",
|
||||
UserPopoutContainer: "type",
|
||||
UsernameSection: "default",
|
||||
UserPopoutInfo: "UserPopoutInfo",
|
||||
UserProfile: "default",
|
||||
UserProfileHeader: "default"
|
||||
}
|
||||
this.modulePatches = {
|
||||
before: [
|
||||
"UserPopout",
|
||||
"UserProfile"
|
||||
],
|
||||
after: [
|
||||
"UserMemberSinceSection",
|
||||
"UserProfileBody"
|
||||
]
|
||||
};
|
||||
|
||||
this.css = `
|
||||
${BDFDB.dotCN._lastmessagedateicon} {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
color: var(--interactive-normal);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
onStart () {
|
||||
|
@ -97,9 +162,7 @@ module.exports = (_ => {
|
|||
if (BDFDB.ObjectUtils.is(e.methodArguments[0]) && e.methodArguments[0].type == "MESSAGE_CREATE" && e.methodArguments[0].message) {
|
||||
let message = e.methodArguments[0].message;
|
||||
let guildId = message.guild_id || message.channel_id;
|
||||
if (guildId && loadedUsers[guildId] && loadedUsers[guildId][message.author.id]) {
|
||||
loadedUsers[guildId][message.author.id] = new Date(message.timestamp);
|
||||
}
|
||||
if (guildId && loadedUsers[guildId] && loadedUsers[guildId][message.author.id]) loadedUsers[guildId][message.author.id] = message;
|
||||
}
|
||||
}});
|
||||
|
||||
|
@ -167,203 +230,161 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
|
||||
processUserPopoutExperimentWrapper (e) {
|
||||
processUserPopout (e) {
|
||||
currentPopout = e.instance;
|
||||
}
|
||||
|
||||
processUserPopoutContainer (e) {
|
||||
currentPopout = e.instance;
|
||||
}
|
||||
|
||||
processUsernameSection (e) {
|
||||
if (currentPopout && e.instance.props.user && this.settings.places.userPopout) {
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: ["CopiableField", "ColoredFluxTag"]});
|
||||
if (index > -1) this.injectDate(children, index + 1, e.instance.props.user, currentPopout.props.guildId);
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopoutInfo (e) {
|
||||
if (currentPopout && e.instance.props.user && this.settings.places.userPopout) {
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: ["DiscordTag", "ColoredFluxTag"]});
|
||||
if (index > -1) this.injectDate(children, index + 1, e.instance.props.user, currentPopout.props.guildId);
|
||||
}
|
||||
processUserMemberSinceSection (e) {
|
||||
if (!currentPopout) return;
|
||||
let user = e.instance.props.user || BDFDB.LibraryStores.UserStore.getUser(e.instance.props.userId);
|
||||
if (!user || user.isNonUserBot()) return;
|
||||
e.returnvalue = [
|
||||
BDFDB.ReactUtils.createElement(LastMessageDateComponents, {
|
||||
isInPopout: true,
|
||||
guildId: currentPopout.props.guildId || BDFDB.DiscordConstants.ME,
|
||||
channelId: currentPopout.props.channelId,
|
||||
isGuild: !!currentPopout.props.guildId,
|
||||
user: user
|
||||
}, true),
|
||||
e.returnvalue
|
||||
];
|
||||
}
|
||||
|
||||
processUserProfile (e) {
|
||||
currentProfile = e.instance;
|
||||
}
|
||||
|
||||
processUserProfileHeader (e) {
|
||||
if (currentProfile && e.instance.props.user && this.settings.places.userProfile) {
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: ["DiscordTag", "ColoredFluxTag"]});
|
||||
if (index > -1) this.injectDate(children, index + 1, e.instance.props.user, currentProfile.props.guildId);
|
||||
}
|
||||
}
|
||||
|
||||
injectDate (children, index, user, guildId) {
|
||||
if (!guildId) guildId = BDFDB.LibraryStores.SelectedGuildStore.getGuildId();
|
||||
if (!BDFDB.ArrayUtils.is(children) || !user || user.isNonUserBot()) return;
|
||||
let isGuild = guildId && guildId != BDFDB.DiscordConstants.ME;
|
||||
guildId = isGuild ? guildId : BDFDB.LibraryStores.SelectedChannelStore.getChannelId();
|
||||
if (!guildId) return;
|
||||
|
||||
if (!loadedUsers[guildId]) loadedUsers[guildId] = {};
|
||||
if (!requestedUsers[guildId]) requestedUsers[guildId] = {};
|
||||
if (!queuedInstances[guildId]) queuedInstances[guildId] = {};
|
||||
|
||||
if (loadedUsers[guildId][user.id] === undefined && !requestedUsers[guildId][user.id]) {
|
||||
requestedUsers[guildId][user.id] = true;
|
||||
queuedInstances[guildId][user.id] = [].concat(queuedInstances[guildId][user.id]).filter(n => n);
|
||||
BDFDB.LibraryModules.APIUtils.get({
|
||||
url: isGuild ? BDFDB.DiscordConstants.Endpoints.SEARCH_GUILD(guildId) : BDFDB.DiscordConstants.Endpoints.SEARCH_CHANNEL(guildId),
|
||||
query: BDFDB.LibraryModules.APIEncodeUtils.stringify({author_id: user.id})
|
||||
}).then(result => {
|
||||
delete requestedUsers[guildId][user.id];
|
||||
if (typeof result.body.retry_after != "number") {
|
||||
if (result.body.messages && Array.isArray(result.body.messages[0])) {
|
||||
for (let message of result.body.messages[0]) if (message.hit && message.author.id == user.id) loadedUsers[guildId][user.id] = new Date(message.timestamp);
|
||||
}
|
||||
else loadedUsers[guildId][user.id] = null;
|
||||
BDFDB.ReactUtils.forceUpdate(queuedInstances[guildId][user.id]);
|
||||
delete queuedInstances[guildId][user.id];
|
||||
}
|
||||
else BDFDB.TimeUtils.timeout(_ => this.injectDate(children, index, user, guildId), result.body.retry_after + 500);
|
||||
});
|
||||
}
|
||||
children.splice(index, 0, BDFDB.ReactUtils.createElement(class extends BDFDB.ReactUtils.Component {
|
||||
render() {
|
||||
if (loadedUsers[guildId][user.id] === undefined) {
|
||||
if (queuedInstances[guildId][user.id].indexOf(this) == -1) queuedInstances[guildId][user.id].push(this);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
let timestamp = loadedUsers[guildId][user.id] ? BDFDB.LibraryComponents.DateInput.format(_this.settings.dates.lastMessageDate, loadedUsers[guildId][user.id]) : "---";
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextScroller, {
|
||||
className: BDFDB.disCNS._lastmessagedatedate + BDFDB.disCNS.userinfodate + BDFDB.disCN.textrow,
|
||||
children: _this.settings.general.displayText ? _this.labels.last_message.replace("{{time}}", timestamp) : timestamp
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
processUserProfileBody (e) {
|
||||
if (!currentProfile) return;
|
||||
let user = e.instance.props.user || BDFDB.LibraryStores.UserStore.getUser(e.instance.props.userId);
|
||||
if (!user || user.isNonUserBot()) return;
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "UserMemberSince"});
|
||||
if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(LastMessageDateComponents, {
|
||||
isInPopout: false,
|
||||
guildId: currentPopout.props.guildId || BDFDB.DiscordConstants.ME,
|
||||
channelId: currentPopout.props.channelId,
|
||||
isGuild: !!currentPopout.props.guildId,
|
||||
user: user
|
||||
}, true));
|
||||
}
|
||||
|
||||
setLabelsByLanguage () {
|
||||
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
||||
case "bg": // Bulgarian
|
||||
return {
|
||||
last_message: "Последно съобщение на {{time}}"
|
||||
last_message: "Последно изпратено съобщение"
|
||||
};
|
||||
case "cs": // Czech
|
||||
return {
|
||||
last_message: "Poslední zpráva v {{time}}"
|
||||
last_message: "Poslední odeslaná zpráva"
|
||||
};
|
||||
case "da": // Danish
|
||||
return {
|
||||
last_message: "Sidste besked den {{time}}"
|
||||
last_message: "Senest sendt besked"
|
||||
};
|
||||
case "de": // German
|
||||
return {
|
||||
last_message: "Letzte Nachricht am {{time}}"
|
||||
last_message: "Letzte gesendete Nachricht"
|
||||
};
|
||||
case "el": // Greek
|
||||
return {
|
||||
last_message: "Τελευταίο μήνυμα στις {{time}}"
|
||||
last_message: "Τελευταίο μήνυμα που εστάλη"
|
||||
};
|
||||
case "es": // Spanish
|
||||
return {
|
||||
last_message: "Último mensaje el {{time}}"
|
||||
last_message: "Último mensaje enviado"
|
||||
};
|
||||
case "fi": // Finnish
|
||||
return {
|
||||
last_message: "Viimeinen viesti {{time}}"
|
||||
last_message: "Viimeksi lähetetty viesti"
|
||||
};
|
||||
case "fr": // French
|
||||
return {
|
||||
last_message: "Dernier message le {{time}}"
|
||||
last_message: "Dernier message envoyé"
|
||||
};
|
||||
case "hi": // Hindi
|
||||
return {
|
||||
last_message: "अंतिम संदेश {{time}} को"
|
||||
last_message: "अंतिम भेजा गया संदेश"
|
||||
};
|
||||
case "hr": // Croatian
|
||||
return {
|
||||
last_message: "Posljednja poruka {{time}}"
|
||||
last_message: "Zadnja poslana poruka"
|
||||
};
|
||||
case "hu": // Hungarian
|
||||
return {
|
||||
last_message: "Utolsó üzenet: {{time}}"
|
||||
last_message: "Utoljára elküldött üzenet"
|
||||
};
|
||||
case "it": // Italian
|
||||
return {
|
||||
last_message: "Ultimo messaggio il {{time}}"
|
||||
last_message: "Ultimo messaggio inviato"
|
||||
};
|
||||
case "ja": // Japanese
|
||||
return {
|
||||
last_message: "{{time}}の最後のメッセージ"
|
||||
last_message: "最後に送信されたメッセージ"
|
||||
};
|
||||
case "ko": // Korean
|
||||
return {
|
||||
last_message: "{{time}}의 마지막 메시지"
|
||||
last_message: "마지막으로 보낸 메시지"
|
||||
};
|
||||
case "lt": // Lithuanian
|
||||
return {
|
||||
last_message: "Paskutinis pranešimas {{time}}"
|
||||
last_message: "Paskutinė išsiųsta žinutė"
|
||||
};
|
||||
case "nl": // Dutch
|
||||
return {
|
||||
last_message: "Laatste bericht op {{time}}"
|
||||
last_message: "Laatst verzonden bericht"
|
||||
};
|
||||
case "no": // Norwegian
|
||||
return {
|
||||
last_message: "Siste melding {{time}}"
|
||||
last_message: "Sist sendt melding"
|
||||
};
|
||||
case "pl": // Polish
|
||||
return {
|
||||
last_message: "Ostatnia wiadomość {{time}}"
|
||||
last_message: "Ostatnio wysłana wiadomość"
|
||||
};
|
||||
case "pt-BR": // Portuguese (Brazil)
|
||||
return {
|
||||
last_message: "Última mensagem em {{time}}"
|
||||
last_message: "Última mensagem enviada"
|
||||
};
|
||||
case "ro": // Romanian
|
||||
return {
|
||||
last_message: "Ultimul mesaj pe {{time}}"
|
||||
last_message: "Ultimul mesaj trimis"
|
||||
};
|
||||
case "ru": // Russian
|
||||
return {
|
||||
last_message: "Последнее сообщение в {{time}}"
|
||||
last_message: "Последнее отправленное сообщение"
|
||||
};
|
||||
case "sv": // Swedish
|
||||
return {
|
||||
last_message: "Senaste meddelandet {{time}}"
|
||||
last_message: "Senast skickat meddelande"
|
||||
};
|
||||
case "th": // Thai
|
||||
return {
|
||||
last_message: "ข้อความล่าสุดเมื่อ {{time}}"
|
||||
last_message: "ข้อความที่ส่งล่าสุด"
|
||||
};
|
||||
case "tr": // Turkish
|
||||
return {
|
||||
last_message: "{{time}} tarihindeki son mesaj"
|
||||
last_message: "Son Gönderilen Mesaj"
|
||||
};
|
||||
case "uk": // Ukrainian
|
||||
return {
|
||||
last_message: "Останнє повідомлення {{time}}"
|
||||
last_message: "Останнє надіслане повідомлення"
|
||||
};
|
||||
case "vi": // Vietnamese
|
||||
return {
|
||||
last_message: "Tin nhắn cuối cùng vào {{time}}"
|
||||
last_message: "Tin nhắn được gửi lần cuối"
|
||||
};
|
||||
case "zh-CN": // Chinese (China)
|
||||
return {
|
||||
last_message: "{{time}}上的最后一条消息"
|
||||
last_message: "最后发送的消息"
|
||||
};
|
||||
case "zh-TW": // Chinese (Taiwan)
|
||||
return {
|
||||
last_message: "{{time}}上的最後一條消息"
|
||||
last_message: "最後發送的消息"
|
||||
};
|
||||
default: // English
|
||||
return {
|
||||
last_message: "Last Message on {{time}}"
|
||||
last_message: "Last sent Message"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue