MessageUtilities now works with the newest PerrsonalPins and GoogleTranslateOption

This commit is contained in:
Mirco Wittrien 2019-01-03 00:35:05 +01:00
parent 4eeb426f51
commit 1a7c65e50f
2 changed files with 73 additions and 90 deletions

View File

@ -651,7 +651,6 @@ class GoogleTranslateOption {
} }
translateMessage (message, target, channel) { translateMessage (message, target, channel) {
console.log(message, target, channel);
if (!message || !target) return; if (!message || !target) return;
let {messagediv, pos} = this.getMessageAndPos(target); let {messagediv, pos} = this.getMessageAndPos(target);
if (!messagediv || pos == -1) return; if (!messagediv || pos == -1) return;

View File

@ -43,15 +43,15 @@ class MessageUtilities {
getDescription () {return "Offers a number of useful message options. Remap the keybindings in the settings.";} getDescription () {return "Offers a number of useful message options. Remap the keybindings in the settings.";}
getVersion () {return "1.4.2";} getVersion () {return "1.4.3";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
getSettingsPanel () { getSettingsPanel () {
if (!this.started || typeof BDFDB !== "object") return; if (!this.started || typeof BDFDB !== "object") return;
var settings = BDFDB.getAllData(this, "settings"); let settings = BDFDB.getAllData(this, "settings");
var bindings = BDFDB.getAllData(this, "bindings"); let bindings = BDFDB.getAllData(this, "bindings");
var settingshtml = `<div class="${this.getName()}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.getName()}</div><div class="DevilBro-settings-inner">`; let settingshtml = `<div class="${this.getName()}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.getName()}</div><div class="DevilBro-settings-inner">`;
for (let key in settings) { for (let key in settings) {
if (this.defaults.settings[key].description) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner}"${settings[key] ? " checked" : ""}></div></div>`; if (this.defaults.settings[key].description) settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner}"${settings[key] ? " checked" : ""}></div></div>`;
} }
@ -68,7 +68,7 @@ class MessageUtilities {
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom20}" style="flex: 0 0 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Reset all key bindings.</h3><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorred + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} reset-button" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}">Reset</div></button></div>`; settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom20}" style="flex: 0 0 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Reset all key bindings.</h3><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorred + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} reset-button" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}">Reset</div></button></div>`;
settingshtml += `</div></div>`; settingshtml += `</div></div>`;
var settingspanel = $(settingshtml)[0]; let settingspanel = $(settingshtml)[0];
BDFDB.initElements(settingspanel); BDFDB.initElements(settingspanel);
@ -91,7 +91,7 @@ class MessageUtilities {
load () {} load () {}
start () { start () {
var libraryScript = null; let libraryScript = null;
if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) {
libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (libraryScript) libraryScript.remove(); if (libraryScript) libraryScript.remove();
@ -109,7 +109,7 @@ class MessageUtilities {
if (typeof BDFDB === "object") { if (typeof BDFDB === "object") {
BDFDB.loadMessage(this); BDFDB.loadMessage(this);
this.ChannelStore = BDFDB.WebModules.findByProperties("getChannel", "getChannels"); this.ChannelUtils = BDFDB.WebModules.findByProperties("getChannels","getChannel");
this.MessageActions = BDFDB.WebModules.findByProperties("startEditMessage", "endEditMessage"); this.MessageActions = BDFDB.WebModules.findByProperties("startEditMessage", "endEditMessage");
this.PinActions = BDFDB.WebModules.findByProperties("pinMessage", "unpinMessage"); this.PinActions = BDFDB.WebModules.findByProperties("pinMessage", "unpinMessage");
this.CurrentUserPerms = BDFDB.WebModules.findByProperties("getChannelPermissions", "can"); this.CurrentUserPerms = BDFDB.WebModules.findByProperties("getChannelPermissions", "can");
@ -133,10 +133,6 @@ class MessageUtilities {
stop () { stop () {
if (typeof BDFDB === "object") { if (typeof BDFDB === "object") {
$(document).off("click." + this.getName(), BDFDB.dotCNC.message + BDFDB.dotCN.messagesystem);
$(document).off("dblclick." + this.getName(), BDFDB.dotCNC.message + BDFDB.dotCN.messagesystem);
$(document).off("keydown." + this.getName(), BDFDB.dotCN.textareawrapchat);
BDFDB.unloadMessage(this); BDFDB.unloadMessage(this);
} }
} }
@ -145,8 +141,8 @@ class MessageUtilities {
//begin of own functions //begin of own functions
updateSettings (settingspanel) { updateSettings (settingspanel) {
var settings = {}; let settings = {};
for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) { for (let input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
settings[input.value] = input.checked; settings[input.value] = input.checked;
} }
BDFDB.saveAllData(settings, this, "settings"); BDFDB.saveAllData(settings, this, "settings");
@ -155,40 +151,40 @@ class MessageUtilities {
resetAll (settingspanel) { resetAll (settingspanel) {
if (confirm("Are you sure you want to delete all key bindings?")) { if (confirm("Are you sure you want to delete all key bindings?")) {
BDFDB.removeAllData(this, "bindings"); BDFDB.removeAllData(this, "bindings");
var bindings = BDFDB.getAllData(this, "bindings"); let bindings = BDFDB.getAllData(this, "bindings");
settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach((wrap) => { settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach((wrap) => {
var action = wrap.getAttribute("type"); let action = wrap.getAttribute("type");
var option = wrap.getAttribute("option"); let option = wrap.getAttribute("option");
wrap.setAttribute("value", bindings[action][option]); wrap.setAttribute("value", bindings[action][option]);
wrap.querySelector(BDFDB.dotCN.title).innerText = this.clickMap[bindings[action][option]]; wrap.querySelector(BDFDB.dotCN.title).innerText = this.clickMap[bindings[action][option]];
}); });
settingspanel.querySelectorAll(BDFDB.dotCN.hotkeycontainer).forEach((wrap) => { settingspanel.querySelectorAll(BDFDB.dotCN.hotkeycontainer).forEach((wrap) => {
var action = wrap.getAttribute("type"); let action = wrap.getAttribute("type");
var option = wrap.getAttribute("option"); let option = wrap.getAttribute("option");
wrap.setAttribute("value", bindings[action][option]); wrap.setAttribute("value", bindings[action][option]);
wrap.querySelector("input").setAttribute("value", this.keyboardMap[bindings[action][option]]); wrap.querySelector("input").setAttribute("value", this.keyboardMap[bindings[action][option]]);
});; });
} }
} }
openDropdownMenu (settingspanel, e) { openDropdownMenu (settingspanel, e) {
var selectControl = e.currentTarget; let selectControl = e.currentTarget;
var selectWrap = e.currentTarget.parentElement; let selectWrap = e.currentTarget.parentElement;
if (selectWrap.classList.contains(BDFDB.disCN.selectisopen)) return; if (selectWrap.classList.contains(BDFDB.disCN.selectisopen)) return;
selectWrap.classList.add(BDFDB.disCN.selectisopen); selectWrap.classList.add(BDFDB.disCN.selectisopen);
var action = selectWrap.getAttribute("type"); let action = selectWrap.getAttribute("type");
var option = selectWrap.getAttribute("option"); let option = selectWrap.getAttribute("option");
var value = selectWrap.getAttribute("value"); let value = selectWrap.getAttribute("value");
var selectMenu = this.createDropdownMenu(action, value); let selectMenu = this.createDropdownMenu(action, value);
selectWrap.appendChild(selectMenu); selectWrap.appendChild(selectMenu);
$(selectMenu).on("mousedown." + this.getName(), BDFDB.dotCN.selectoption, (e2) => { $(selectMenu).on("mousedown." + this.getName(), BDFDB.dotCN.selectoption, (e2) => {
var binding = BDFDB.getData(action, this, "bindings"); let binding = BDFDB.getData(action, this, "bindings");
var selection = e2.currentTarget.getAttribute("value"); let selection = e2.currentTarget.getAttribute("value");
selectWrap.setAttribute("value", selection); selectWrap.setAttribute("value", selection);
selectControl.querySelector(BDFDB.dotCN.title).innerText = e2.currentTarget.textContent; selectControl.querySelector(BDFDB.dotCN.title).innerText = e2.currentTarget.textContent;
binding[option] = parseInt(selection); binding[option] = parseInt(selection);
@ -203,9 +199,9 @@ class MessageUtilities {
} }
createDropdownMenu (action, value) { createDropdownMenu (action, value) {
var menuhtml = `<div class="${BDFDB.disCN.selectmenuouter}"><div class="${BDFDB.disCN.selectmenu}">`; let menuhtml = `<div class="${BDFDB.disCN.selectmenuouter}"><div class="${BDFDB.disCN.selectmenu}">`;
for (var i in this.clickMap) { for (let i in this.clickMap) {
var isSelected = i == value ? ` ${BDFDB.disCN.selectselected}` : ``; let isSelected = i == value ? ` ${BDFDB.disCN.selectselected}` : ``;
menuhtml += `<div value="${i}" class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignbaseline + BDFDB.disCNS.nowrap + BDFDB.disCN.selectoption + isSelected}" style="flex: 1 1 auto;"><div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.size16 + BDFDB.disCNS.height20 + BDFDB.disCNS.primary + BDFDB.disCN.weightnormal}">${this.clickMap[i]}</div></div>` menuhtml += `<div value="${i}" class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignbaseline + BDFDB.disCNS.nowrap + BDFDB.disCN.selectoption + isSelected}" style="flex: 1 1 auto;"><div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.size16 + BDFDB.disCNS.height20 + BDFDB.disCNS.primary + BDFDB.disCN.weightnormal}">${this.clickMap[i]}</div></div>`
} }
menuhtml += `</div></div>`; menuhtml += `</div></div>`;
@ -213,14 +209,14 @@ class MessageUtilities {
} }
startRecording (settingspanel, e) { startRecording (settingspanel, e) {
var recorderWrap = e.currentTarget; let recorderWrap = e.currentTarget;
if (recorderWrap.classList.contains(BDFDB.disCN.hotkeyrecording)) return; if (recorderWrap.classList.contains(BDFDB.disCN.hotkeyrecording)) return;
var recorderInput = recorderWrap.querySelector("input"); let recorderInput = recorderWrap.querySelector("input");
var recorderText = recorderWrap.querySelector(BDFDB.dotCN.hotkeytext); let recorderText = recorderWrap.querySelector(BDFDB.dotCN.hotkeytext);
var action = recorderWrap.getAttribute("type"); let action = recorderWrap.getAttribute("type");
var option = recorderWrap.getAttribute("option"); let option = recorderWrap.getAttribute("option");
recorderWrap.classList.add(BDFDB.disCN.hotkeyrecording); recorderWrap.classList.add(BDFDB.disCN.hotkeyrecording);
recorderWrap.classList.remove(BDFDB.disCN.hotkeyhasvalue); recorderWrap.classList.remove(BDFDB.disCN.hotkeyhasvalue);
@ -234,7 +230,7 @@ class MessageUtilities {
$(document).on("mousedown.recorder" + this.getName(), () => { $(document).on("mousedown.recorder" + this.getName(), () => {
$(document).off("mousedown.recorder" + this.getName()); $(document).off("mousedown.recorder" + this.getName());
$(document).off("keydown.recorder" + this.getName()); $(document).off("keydown.recorder" + this.getName());
var binding = BDFDB.getData(action, this, "bindings"); let binding = BDFDB.getData(action, this, "bindings");
binding[option] = parseInt(recorderWrap.getAttribute("value")); binding[option] = parseInt(recorderWrap.getAttribute("value"));
BDFDB.saveData(action, binding, this, "bindings"); BDFDB.saveData(action, binding, this, "bindings");
setTimeout(() => { setTimeout(() => {
@ -246,14 +242,14 @@ class MessageUtilities {
} }
resetRecorder (settingspanel, e) { resetRecorder (settingspanel, e) {
var resetButton = e.currentTarget; let resetButton = e.currentTarget;
var recorderWrap = e.currentTarget.parentElement.parentElement.querySelector(BDFDB.dotCN.hotkeycontainer); let recorderWrap = e.currentTarget.parentElement.parentElement.querySelector(BDFDB.dotCN.hotkeycontainer);
var recorderInput = recorderWrap.querySelector("input"); let recorderInput = recorderWrap.querySelector("input");
var action = recorderWrap.getAttribute("type"); let action = recorderWrap.getAttribute("type");
var option = recorderWrap.getAttribute("option"); let option = recorderWrap.getAttribute("option");
recorderWrap.setAttribute("value", 0); recorderWrap.setAttribute("value", 0);
recorderInput.setAttribute("value", this.keyboardMap[0]); recorderInput.setAttribute("value", this.keyboardMap[0]);
var binding = BDFDB.getData(action, this, "bindings"); let binding = BDFDB.getData(action, this, "bindings");
binding[option] = parseInt(recorderWrap.getAttribute("value")); binding[option] = parseInt(recorderWrap.getAttribute("value"));
BDFDB.saveData(action, binding, this, "bindings"); BDFDB.saveData(action, binding, this, "bindings");
} }
@ -261,12 +257,12 @@ class MessageUtilities {
onClick (div, click, name) { onClick (div, click, name) {
if (!this.isEventFired(name)) { if (!this.isEventFired(name)) {
this.fireEvent(name); this.fireEvent(name);
var settings = BDFDB.getAllData(this, "settings"); let settings = BDFDB.getAllData(this, "settings");
var bindings = BDFDB.getAllData(this, "bindings") let bindings = BDFDB.getAllData(this, "bindings");
for (let action in bindings) { for (let action in bindings) {
if (settings[action] && this.checkIfBindingIsValid(bindings[action], click)) { if (settings[action] && this.checkIfBindingIsValid(bindings[action], click)) {
var message = this.getMessageData(div); let {messagediv, pos, message} = this.getMessageData(div);
if (message) this.defaults.bindings[action].func.bind(this)(message); if (messagediv && pos > -1 && message) this.defaults.bindings[action].func.bind(this)({messagediv, pos, message});
break; break;
} }
} }
@ -275,7 +271,7 @@ class MessageUtilities {
} }
checkIfBindingIsValid (binding, doneclick) { checkIfBindingIsValid (binding, doneclick) {
var valid = true; let valid = true;
for (let click of this.clicks) { for (let click of this.clicks) {
if (binding[click] != doneclick) valid = false; if (binding[click] != doneclick) valid = false;
} }
@ -285,58 +281,59 @@ class MessageUtilities {
return valid; return valid;
} }
doDelete (message) { doDelete ({messagediv, pos, message}) {
var channel = this.ChannelStore.getChannel(message.channel_id); let channel = this.ChannelUtils.getChannel(message.channel_id);
if ((channel && this.CurrentUserPerms.can(this.Permissions.MANAGE_MESSAGES, channel)) || message.author.id == BDFDB.myData.id) { if ((channel && this.CurrentUserPerms.can(this.Permissions.MANAGE_MESSAGES, channel)) || message.author.id == BDFDB.myData.id) {
this.MessageActions.deleteMessage(message.channel_id, message.id); this.MessageActions.deleteMessage(message.channel_id, message.id);
} }
} }
doEdit (message) { doEdit ({messagediv, pos, message}) {
if (message.author.id == BDFDB.myData.id && !message.div.querySelector("textarea")) { if (message.author.id == BDFDB.myData.id && !messagediv.querySelector("textarea")) {
this.MessageActions.startEditMessage(message.channel_id, message.id, message.content); this.MessageActions.startEditMessage(message.channel_id, message.id, message.content);
} }
} }
doOpenReact (message) { doOpenReact ({messagediv, pos, message}) {
var reactButton = message.div.querySelector(BDFDB.dotCN.emojipickerbutton); let reactButton = messagediv.querySelector(BDFDB.dotCN.emojipickerbutton);
if (reactButton) reactButton.click(); if (reactButton) reactButton.click();
} }
doPinUnPin (message) { doPinUnPin ({messagediv, pos, message}) {
var channel = this.ChannelStore.getChannel(message.channel_id); let channel = this.ChannelUtils.getChannel(message.channel_id);
if (channel && this.CurrentUserPerms.can(this.Permissions.MANAGE_MESSAGES, channel)) { if (channel && this.CurrentUserPerms.can(this.Permissions.MANAGE_MESSAGES, channel)) {
if (message.pinned) this.PinActions.unpinMessage(channel, message.id); if (message.pinned) this.PinActions.unpinMessage(channel, message.id);
else this.PinActions.pinMessage(channel, message.id); else this.PinActions.pinMessage(channel, message.id);
} }
} }
doNote (message) { doNote ({messagediv, pos, message}) {
if (BDFDB.isPluginEnabled("PersonalPins") == true) { if (BDFDB.isPluginEnabled("PersonalPins") == true) {
var PersonalPins = window.bdplugins["PersonalPins"].plugin; let channel = this.ChannelUtils.getChannel(message.channel_id);
PersonalPins.getMessageData(message.div); if (channel) {
PersonalPins.addMessageToNotes(); if (bdplugins.PersonalPins.plugin.getNoteData(message, channel, pos)) bdplugins.PersonalPins.plugin.removeNoteData(message, channel, pos);
else bdplugins.PersonalPins.plugin.addMessageToNotes(message, messagediv, channel);
}
} }
} }
doTranslate (message) { doTranslate ({messagediv, pos, message}) {
if (BDFDB.isPluginEnabled("GoogleTranslateOption") == true) { if (BDFDB.isPluginEnabled("GoogleTranslateOption") == true) {
var GoogleTranslateOption = window.bdplugins["GoogleTranslateOption"].plugin; let channel = this.ChannelUtils.getChannel(message.channel_id);
GoogleTranslateOption.getMessageData(message.div); if (channel) bdplugins.GoogleTranslateOption.plugin.translateMessage(message, messagediv, channel);
GoogleTranslateOption.translateMessage();
} }
} }
doQuote (message) { doQuote ({messagediv, pos, message}) {
if (BDFDB.isPluginEnabled("Quoter") == true) { if (BDFDB.isPluginEnabled("Quoter") == true) {
var quoteButton = message.div.querySelector(".btn-quote"); let quoteButton = messagediv.querySelector(".btn-quote");
if (quoteButton) quoteButton.click(); if (quoteButton) quoteButton.click();
} }
} }
doCitate (message) { doCitate ({messagediv, pos, message}) {
if (BDFDB.isPluginEnabled("Citador") == true) { if (BDFDB.isPluginEnabled("Citador") == true) {
var citarButton = message.div.parentElement.querySelector(".citar-btn"); let citarButton = messagediv.parentElement.querySelector(".citar-btn");
if (citarButton) citarButton.click(); if (citarButton) citarButton.click();
} }
} }
@ -345,7 +342,7 @@ class MessageUtilities {
if (!this.isEventFired(name)) { if (!this.isEventFired(name)) {
this.fireEvent(name); this.fireEvent(name);
if (key == 27 && BDFDB.getData("clearOnEscape", this, "settings")) { if (key == 27 && BDFDB.getData("clearOnEscape", this, "settings")) {
var instance = BDFDB.getOwnerInstance({"node":div, "name":"ChannelTextAreaForm", "up":true}); let instance = BDFDB.getOwnerInstance({"node":div, "name":"ChannelTextAreaForm", "up":true});
if (instance) { if (instance) {
instance.setState({textValue:""}); instance.setState({textValue:""});
} }
@ -366,25 +363,12 @@ class MessageUtilities {
return str ? str.slice(0,-1) : null; return str ? str.slice(0,-1) : null;
} }
getMessageGroup (message) { getMessageData (target) {
var messagegroup = null; let messagediv = BDFDB.getParentEle(BDFDB.dotCN.message, target);
while (messagegroup == null || message.parentElement) { let pos = messagediv ? Array.from(messagediv.parentElement.querySelectorAll(BDFDB.dotCN.message)).indexOf(messagediv) : -1;
message = message.parentElement; let instance = BDFDB.getReactInstance(messagediv);
if (message.classList && message.classList.contains(BDFDB.disCN.messagegroup)) messagegroup = message; let message = instance && instance.return && instance.return.memoizedProps && instance.return.memoizedProps.message ? instance.return.memoizedProps.message : null;
} return {messagediv, pos, message};
return messagegroup;
}
getMessageData (div) {
if (div) {
var messagegroup = this.getMessageGroup(div);
var pos = Array.from(messagegroup.querySelectorAll(BDFDB.dotCNC.message + BDFDB.dotCN.messagesystem)).indexOf(div);
var instance = BDFDB.getReactInstance(messagegroup);
if (!instance) return;
var info = instance.return.stateNode.props.messages;
if (info && pos > -1) return Object.assign({},info[pos],{"div":div, "group":messagegroup, "pos":pos});
}
return null;
} }
fireEvent (name) { fireEvent (name) {