Update MessageUtilities.plugin.js
This commit is contained in:
parent
bb2b40ee5f
commit
1f5566fe99
|
@ -7,7 +7,7 @@ var MessageUtilities = (_ => {
|
||||||
return class MessageUtilities {
|
return class MessageUtilities {
|
||||||
getName () {return "MessageUtilities";}
|
getName () {return "MessageUtilities";}
|
||||||
|
|
||||||
getVersion () {return "1.7.2";}
|
getVersion () {return "1.7.3";}
|
||||||
|
|
||||||
getAuthor () {return "DevilBro";}
|
getAuthor () {return "DevilBro";}
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ var MessageUtilities = (_ => {
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.changelog = {
|
this.changelog = {
|
||||||
"fixed":[["Open React Menu","Works again"]]
|
"fixed":[["Context Menu Update","Fixes for the context menu update, yaaaaaay"]]
|
||||||
};
|
};
|
||||||
|
|
||||||
this.patchedModules = {
|
this.patchedModules = {
|
||||||
after: {
|
before: {
|
||||||
ContextMenuItem: "default"
|
Menu: "default"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -192,34 +192,40 @@ var MessageUtilities = (_ => {
|
||||||
|
|
||||||
//begin of own functions
|
//begin of own functions
|
||||||
|
|
||||||
processContextMenuItem (e) {
|
processMenu (e) {
|
||||||
if (e.instance.props.label && !e.instance.props.hint && BDFDB.DataUtils.get(this, "settings", "addHints")) {
|
let contextMenu = BDFDB.ReactUtils.findChild(e.instance, {props: "navId"});
|
||||||
let hint, action;
|
if (contextMenu && BDFDB.ArrayUtils.is(contextMenu.props.children)) for (let group of contextMenu.props.children) {
|
||||||
if (e.instance.props.label == BDFDB.LanguageUtils.LanguageStrings.MARK_UNREAD) hint = `${clickMap[0]}+${BDFDB.LibraryModules.KeyCodeUtils.getString(18)}`;
|
if (group && group.type == BDFDB.LibraryComponents.MenuItems.MenuGroup && BDFDB.ArrayUtils.is(group.props.children)) for (let item of group.props.children) {
|
||||||
else {
|
if (item && item.props && item.props.id && !item.props.hint) {
|
||||||
switch (e.instance.props.label) {
|
let hint, action;
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.COPY_MESSAGE_LINK:
|
if (item.props.id == "mark-unread") hint = `${clickMap[0]}+${BDFDB.LibraryModules.KeyCodeUtils.getString(18)}`;
|
||||||
action = "Copy_Link";
|
else {
|
||||||
break;
|
switch (item.props.id) {
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.EDIT_MESSAGE:
|
case "copy-link":
|
||||||
action = "Edit_Message";
|
action = "Copy_Link";
|
||||||
break;
|
break;
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.PIN_MESSAGE:
|
case "edit":
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.UNPIN_MESSAGE:
|
action = "Edit_Message";
|
||||||
action = "Pin/Unpin_Message";
|
break;
|
||||||
break;
|
case "pin":
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.DELETE_MESSAGE:
|
case "unpin":
|
||||||
action = "Delete_Message";
|
action = "Pin/Unpin_Message";
|
||||||
break;
|
break;
|
||||||
case BDFDB.LanguageUtils.LanguageStrings.QUOTE:
|
case "delete":
|
||||||
action = "Quote_Message";
|
action = "Delete_Message";
|
||||||
break;
|
break;
|
||||||
|
case "quote":
|
||||||
|
action = "Quote_Message";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (action) hint = this.getActiveShortcutString(action);
|
||||||
|
}
|
||||||
|
if (hint) item.props.hint = _ => {
|
||||||
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuHint, {
|
||||||
|
hint: hint
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (action) hint = this.getActiveShortcutString(action);
|
|
||||||
}
|
|
||||||
if (hint) {
|
|
||||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {props: [["className", BDFDB.disCN.contextmenuhint]]});
|
|
||||||
if (index > -1) children[index] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Hint, {hint});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,23 +234,23 @@ var MessageUtilities = (_ => {
|
||||||
if (!firedEvents.includes(name)) {
|
if (!firedEvents.includes(name)) {
|
||||||
firedEvents.push(name);
|
firedEvents.push(name);
|
||||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||||
let bindings = BDFDB.ObjectUtils.filter(BDFDB.DataUtils.get(this, "bindings"), action => {return settings[action]}, true);
|
let bindings = BDFDB.ObjectUtils.filter(BDFDB.DataUtils.get(this, "bindings"), action => settings[action], true);
|
||||||
let priorityaction = null;
|
let priorityAction = null;
|
||||||
for (let action in bindings) {
|
for (let action in bindings) {
|
||||||
let binding = bindings[action];
|
let binding = bindings[action];
|
||||||
let prioritybinding = bindings[priorityaction];
|
let priorityBinding = bindings[priorityAction];
|
||||||
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityaction] || binding.click > prioritybinding.click || binding.keycombo.length > prioritybinding.keycombo.length)) priorityaction = action;
|
if (this.checkIfBindingIsValid(binding, click) && (!bindings[priorityAction] || binding.click > priorityBinding.click || binding.keycombo.length > priorityBinding.keycombo.length)) priorityAction = action;
|
||||||
}
|
}
|
||||||
if (priorityaction) {
|
if (priorityAction) {
|
||||||
let {messagediv, message} = this.getMessageData(e.currentTarget);
|
let {messageDiv, message} = this.getMessageData(e.currentTarget);
|
||||||
if (messagediv && message) {
|
if (messageDiv && message) {
|
||||||
BDFDB.ListenerUtils.stopEvent(e);
|
BDFDB.ListenerUtils.stopEvent(e);
|
||||||
BDFDB.TimeUtils.clear(this.clickTimeout);
|
BDFDB.TimeUtils.clear(this.clickTimeout);
|
||||||
if (!this.hasDoubleClickOverwrite(bindings, bindings[priorityaction])) {
|
if (!this.hasDoubleClickOverwrite(bindings, bindings[priorityAction])) {
|
||||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, message}, priorityaction]);
|
this.defaults.bindings[priorityAction].func.apply(this, [{messageDiv, message}, priorityAction]);
|
||||||
}
|
}
|
||||||
else this.clickTimeout = BDFDB.TimeUtils.timeout(_ => {
|
else this.clickTimeout = BDFDB.TimeUtils.timeout(_ => {
|
||||||
this.defaults.bindings[priorityaction].func.apply(this, [{messagediv, message}, priorityaction]);
|
this.defaults.bindings[priorityAction].func.apply(this, [{messageDiv, message}, priorityAction]);
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,8 +276,8 @@ var MessageUtilities = (_ => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
doDelete ({messagediv, message}, action) {
|
doDelete ({messageDiv, message}, action) {
|
||||||
let deletelink = messagediv.parentElement.querySelector(BDFDB.dotCNS.messagelocalbotoperations + BDFDB.dotCN.anchor);
|
let deletelink = messageDiv.parentElement.querySelector(BDFDB.dotCNS.messagelocalbotoperations + BDFDB.dotCN.anchor);
|
||||||
if (deletelink) deletelink.click();
|
if (deletelink) deletelink.click();
|
||||||
else {
|
else {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
|
@ -282,22 +288,22 @@ var MessageUtilities = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doEdit ({messagediv, message}, action) {
|
doEdit ({messageDiv, message}, action) {
|
||||||
if (message.author.id == BDFDB.UserUtils.me.id && !messagediv.querySelector("textarea")) {
|
if (message.author.id == BDFDB.UserUtils.me.id && !messageDiv.querySelector("textarea")) {
|
||||||
BDFDB.LibraryModules.MessageUtils.startEditMessage(message.channel_id, message.id, message.content);
|
BDFDB.LibraryModules.MessageUtils.startEditMessage(message.channel_id, message.id, message.content);
|
||||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Started editing.", {type:"success"});
|
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Started editing.", {type:"success"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doOpenReact ({messagediv, message}, action) {
|
doOpenReact ({messageDiv, message}, action) {
|
||||||
let reactButton = messagediv.querySelector(`${BDFDB.dotCN.messagetoolbarbutton}[aria-label="${BDFDB.LanguageUtils.LanguageStrings.ADD_REACTION}"]`);
|
let reactButton = messageDiv.querySelector(`${BDFDB.dotCN.messagetoolbarbutton}[aria-label="${BDFDB.LanguageUtils.LanguageStrings.ADD_REACTION}"]`);
|
||||||
if (reactButton) {
|
if (reactButton) {
|
||||||
reactButton.click();
|
reactButton.click();
|
||||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Reaction popout has been opened.", {type:"success"});
|
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Reaction popout has been opened.", {type:"success"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doPinUnPin ({messagediv, message}, action) {
|
doPinUnPin ({messageDiv, message}, action) {
|
||||||
if (message.state == "SENT") {
|
if (message.state == "SENT") {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
if (channel && (channel.type == 1 || channel.type == 3 || BDFDB.UserUtils.can("MANAGE_MESSAGES")) && message.type == 0) {
|
if (channel && (channel.type == 1 || channel.type == 3 || BDFDB.UserUtils.can("MANAGE_MESSAGES")) && message.type == 0) {
|
||||||
|
@ -313,14 +319,14 @@ var MessageUtilities = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCopyRaw ({messagediv, message}, action) {
|
doCopyRaw ({messageDiv, message}, action) {
|
||||||
if (message.content) {
|
if (message.content) {
|
||||||
BDFDB.LibraryRequires.electron.clipboard.write({text:message.content});
|
BDFDB.LibraryRequires.electron.clipboard.write({text:message.content});
|
||||||
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Raw message content has been copied.", {type:"success"});
|
if (BDFDB.DataUtils.get(this, "toasts", action)) BDFDB.NotificationUtils.toast("Raw message content has been copied.", {type:"success"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doCopyLink ({messagediv, message}, action) {
|
doCopyLink ({messageDiv, message}, action) {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
if (channel) {
|
if (channel) {
|
||||||
BDFDB.LibraryRequires.electron.clipboard.write({text:`https://discordapp.com/channels/${channel.guild_id || BDFDB.DiscordConstants.ME}/${channel.id}/${message.id}`});
|
BDFDB.LibraryRequires.electron.clipboard.write({text:`https://discordapp.com/channels/${channel.guild_id || BDFDB.DiscordConstants.ME}/${channel.id}/${message.id}`});
|
||||||
|
@ -328,7 +334,7 @@ var MessageUtilities = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doQuote ({messagediv, message}, action) {
|
doQuote ({messageDiv, message}, action) {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
if (channel && BDFDB.LibraryModules.QuoteUtils.canQuote(message, channel)) {
|
if (channel && BDFDB.LibraryModules.QuoteUtils.canQuote(message, channel)) {
|
||||||
BDFDB.LibraryModules.DispatchUtils.ComponentDispatch.dispatch(BDFDB.DiscordConstants.ComponentActions.INSERT_QUOTE_TEXT, {
|
BDFDB.LibraryModules.DispatchUtils.ComponentDispatch.dispatch(BDFDB.DiscordConstants.ComponentActions.INSERT_QUOTE_TEXT, {
|
||||||
|
@ -338,23 +344,23 @@ var MessageUtilities = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doNote ({messagediv, message}, action) {
|
doNote ({messageDiv, message}, action) {
|
||||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Note_Message.plugin)) {
|
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Note_Message.plugin)) {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Note_Message.plugin).addMessageToNotes(message, channel);
|
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Note_Message.plugin).addMessageToNotes(message, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doTranslate ({messagediv, message}, action) {
|
doTranslate ({messageDiv, message}, action) {
|
||||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Translate_Message.plugin)) {
|
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Translate_Message.plugin)) {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Translate_Message.plugin).translateMessage(message, channel);
|
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Translate_Message.plugin).translateMessage(message, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doReveal ({messagediv, message}, action) {
|
doReveal ({messageDiv, message}, action) {
|
||||||
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Reveal_Spoilers.plugin)) {
|
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Reveal_Spoilers.plugin)) {
|
||||||
BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Reveal_Spoilers.plugin).revealAllSpoilers(messagediv);
|
BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Reveal_Spoilers.plugin).revealAllSpoilers(messageDiv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,11 +392,11 @@ var MessageUtilities = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessageData (target) {
|
getMessageData (target) {
|
||||||
let messagediv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.message, target);
|
let messageDiv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.message, target);
|
||||||
if (messagediv && messagediv.querySelector(BDFDB.dotCN.textarea)) return {messagediv: null, message: null};
|
if (messageDiv && messageDiv.querySelector(BDFDB.dotCN.textarea)) return {messageDiv: null, message: null};
|
||||||
let instance = BDFDB.ReactUtils.getInstance(messagediv);
|
let instance = BDFDB.ReactUtils.getInstance(messageDiv);
|
||||||
let message = instance && BDFDB.ReactUtils.findValue(instance, "message");
|
let message = instance && BDFDB.ReactUtils.findValue(instance, "message");
|
||||||
return {messagediv, message};
|
return {messageDiv, message};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue