BetterDiscordAddons/Plugins/PinDMs/PinDMs.plugin.js

719 lines
31 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"PinDMs","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/PinDMs","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/PinDMs/PinDMs.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class PinDMs {
getName () {return "PinDMs";}
2019-11-21 14:56:53 +01:00
getVersion () {return "1.5.0";}
getAuthor () {return "DevilBro";}
2019-01-31 18:09:39 +01:00
getDescription () {return "Allows you to pin DMs, making them appear at the top of your DMs/Guild-list.";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-02-05 14:23:34 +01:00
this.changelog = {
2019-11-21 14:56:53 +01:00
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
2019-02-05 14:23:34 +01:00
};
2019-09-04 12:34:02 +02:00
2019-11-14 17:56:26 +01:00
this.patchedModules = {
2019-11-21 14:56:53 +01:00
before: {
PrivateChannelsList: "render",
UnreadDMs: "render",
},
2019-11-14 17:56:26 +01:00
after: {
2019-11-21 14:56:53 +01:00
PrivateChannelsList: "render",
UnreadDMs: "render",
PrivateChannel: ["render", "componentDidMount"],
DirectMessage: ["render", "componentDidMount"]
2019-11-14 17:56:26 +01:00
}
};
2019-09-04 12:34:02 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
initConstructor () {
this.css = `
2019-11-21 14:56:53 +01:00
${BDFDB.dotCNS.dmchannel + BDFDB.dotCN.namecontainerchildren} {
display: flex;
}
${BDFDB.dotCN.dmchannel}:hover ${BDFDB.dotCN._pindmsunpinbutton} {
display: block;
}
${BDFDB.dotCN._pindmsunpinbutton} {
display: none;
width: 16px;
height: 16px;
opacity: .7;
margin: 2px;
}
${BDFDB.dotCN._pindmsunpinbutton}:hover {
opacity: 1;
}
${BDFDB.dotCN._pindmsunpinicon} {
display: block;
width: 16px;
height: 16px;
}
${BDFDB.dotCNS._pindmsdmchannelplaceholder + BDFDB.dotCN.namecontainerlayout} {
box-sizing: border-box;
border: 1px dashed currentColor;
}
${BDFDB.dotCN._pindmsdragpreview} {
2019-02-28 10:44:12 +01:00
pointer-events: none !important;
position: absolute !important;
opacity: 0.5 !important;
z-index: 10000 !important;
}`;
this.defaults = {
settings: {
showPinIcon: {value:true, description:"Shows a little 'Pin' icon for pinned DMs in the server list:"}
2019-02-05 14:23:34 +01:00
}
2019-02-28 10:44:12 +01:00
};
}
2019-01-26 22:45:19 +01:00
getSettingsPanel () {
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-10-22 23:04:35 +02:00
let settings = BDFDB.DataUtils.get(this, "settings");
2019-11-21 14:56:53 +01:00
let settingsitems = [];
for (let key in settings) (!this.defaults.settings[key].inner ? settingsitems : inneritems).push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
className: BDFDB.disCN.marginbottom8,
color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Unpin all pinned DMs",
onClick: _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to unpin all pinned DMs?", () => {
BDFDB.DataUtils.remove(this, "pinnedDMs");
BDFDB.DataUtils.remove(this, "pinnedRecents");
});
},
children: BDFDB.LanguageUtils.LanguageStrings.UNPIN
}));
return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
2018-10-11 10:21:26 +02:00
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
2019-05-26 13:55:26 +02:00
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
2018-10-11 10:21:26 +02:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2018-10-11 10:21:26 +02:00
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
2019-05-26 13:55:26 +02:00
libraryScript.addEventListener("load", () => {this.initialize();});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
}
2019-01-17 23:48:29 +01:00
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2019-11-01 10:27:07 +01:00
this.startTimeout = setTimeout(() => {
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2018-10-11 10:21:26 +02:00
}
initialize () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-01-22 11:05:54 +01:00
if (this.started) return;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01:00
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
2018-10-11 10:21:26 +02:00
}
stop () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-11-21 14:56:53 +01:00
this.forceUpdateAll();
let unreadDMsInstance = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"UnreadDMs", unlimited:true});
if (unreadDMsInstance) {
delete unreadDMsInstance.props.pinnedPrivateChannelIds;
unreadDMsInstance.props.unreadPrivateChannelIds = BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds();
BDFDB.ReactUtils.forceUpdate(unreadDMsInstance);
}
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2018-10-11 10:21:26 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
onSettingsClosed (instance, wrapper, returnvalue) {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
onUserContextMenu (e) {
if (e.instance.props.user) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"UserCloseChatItem"});
2019-09-11 12:14:43 +02:00
if (index > -1) {
2019-11-21 14:56:53 +01:00
let id = BDFDB.LibraryModules.ChannelStore.getDMFromUserId(e.instance.props.user.id);
if (id) this.injectItem(e.instance, id, children, index);
}
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
onGroupDMContextMenu (e) {
if (e.instance.props.channelId) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"ChangeIcon"});
if (index > -1) this.injectItem(e.instance, e.instance.props.channelId, children, index);
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
injectItem (instance, id, children, index) {
let pinnedInChannel = this.isPinned(id, "pinnedDMs");
let pinnedInGuild = this.isPinned(id, "pinnedRecents");
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuSubItem, {
label: this.labels.context_pindm_text,
render: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
label: this.labels[pinnedInChannel ? "context_unpinchannel_text" : "context_pinchannel_text"],
danger: pinnedInChannel,
action: _ => {
BDFDB.ContextMenuUtils.close(instance);
if (!pinnedInChannel) this.addPin(id, "pinnedDMs");
else this.removePin(id, "pinnedDMs");
}
2019-11-21 14:56:53 +01:00
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
label: this.labels[pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text"],
danger: pinnedInGuild,
action: _ => {
BDFDB.ContextMenuUtils.close(instance);
if (!pinnedInGuild) this.addPin(id, "pinnedRecents");
else this.removePin(id, "pinnedRecents");
}
})
]
2019-09-11 12:14:43 +02:00
}));
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processPrivateChannelsList (e) {
let sortedDMs = this.sortAndUpdate("pinnedDMs");
if (sortedDMs.length) {
e.instance.props.channels = Object.assign({}, e.instance.props.channels);
e.instance.props.pinnedChannels = Object.assign({}, e.instance.props.pinnedChannels);
for (let pos in sortedDMs) {
let id = sortedDMs[pos];
if (e.instance.props.channels[id]) {
e.instance.props.pinnedChannels[id] = e.instance.props.channels[id];
BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
delete e.instance.props.channels[id];
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
}
if (e.returnvalue && !BDFDB.ObjectUtils.isEmpty(e.instance.props.pinnedChannels)) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ListSectionItem"});
if (index > -1) {
if (this.draggedChannel && this.releasedChannel) {
let ids = Object.keys(e.instance.props.pinnedChannels), pinnedChannels = {}, newData = {};
BDFDB.ArrayUtils.remove(ids, this.draggedChannel, true);
ids.splice(this.releasedChannel == "header" ? 0 : ids.indexOf(this.releasedChannel) + 1, 0, this.draggedChannel);
for (let pos in ids) {
let id = ids[pos];
pinnedChannels[id] = e.instance.props.pinnedChannels[id];
newData[id] = parseInt(pos);
}
e.instance.props.pinnedChannels = pinnedChannels;
BDFDB.DataUtils.save(newData, this, "pinnedDMs");
delete this.draggedChannel;
delete this.releasedChannel;
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListHeader, {
className: BDFDB.disCNS.dmchannelheader + BDFDB.disCN._pindmspinnedchannelsheadercontainer,
children: this.labels.header_pinneddms_text
}));
if (this.hoveredChannel == "header") children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, {
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder
}));
for (let id in e.instance.props.pinnedChannels) if (e.instance.props.pinnedChannels[id]) {
if (!e.instance.props.privateChannelIds.includes(id)) e.instance.props.privateChannelIds.unshift(id);
if (this.draggedChannel != id) {
let channel = e.instance.props.renderChannel(e.instance.props.pinnedChannels[id], e.instance.props.selectedChannelId == id);
channel.props.pinned = true;
children.splice(index++, 0, channel);
if (this.hoveredChannel == id) children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, {
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder
}));
}
}
2019-05-29 17:39:43 +02:00
}
}
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processUnreadDMs (e) {
e.instance.props.pinnedPrivateChannelIds = [];
let sortedRecents = this.sortAndUpdate("pinnedRecents");
if (sortedRecents.length) {
e.instance.props.unreadPrivateChannelIds = [];
for (let pos in sortedRecents) {
let id = sortedRecents[pos];
if (e.instance.props.channels[id]) {
if (!e.instance.props.pinnedPrivateChannelIds.includes(id)) e.instance.props.pinnedPrivateChannelIds.push(id);
if (!e.instance.props.unreadPrivateChannelIds.includes(id)) e.instance.props.unreadPrivateChannelIds.push(id);
}
2018-11-29 15:19:09 +01:00
}
2019-11-21 14:56:53 +01:00
e.instance.props.unreadPrivateChannelIds = e.instance.props.unreadPrivateChannelIds.concat(BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds());
if (e.returnvalue) {
if (this.draggedChannel && this.releasedChannel) {
let pinnedPrivateChannelIds = [].concat(e.instance.props.pinnedPrivateChannelIds), newData = {};
BDFDB.ArrayUtils.remove(pinnedPrivateChannelIds, this.draggedChannel, true);
pinnedPrivateChannelIds.splice(pinnedPrivateChannelIds.indexOf(this.releasedChannel) + 1, 0, this.draggedChannel);
for (let pos in pinnedPrivateChannelIds) newData[pinnedPrivateChannelIds[pos]] = parseInt(pos);
BDFDB.DataUtils.save(newData, this, "pinnedRecents");
delete this.draggedChannel;
delete this.releasedChannel;
BDFDB.ReactUtils.forceUpdate(e.instance);
}
2019-11-21 14:56:53 +01:00
if (this.draggedChannel) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {filter: child => BDFDB.ReactUtils.getValue(child, "props.channel.id") == this.draggedChannel});
children.splice(index, 1);
}
if (this.hoveredChannel) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {filter: child => BDFDB.ReactUtils.getValue(child, "props.channel.id") == this.hoveredChannel});
children.splice(index + 1, 0, BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCNS.guildouter + BDFDB.disCN._pindmsrecentplaceholder,
children: BDFDB.ReactUtils.createElement("div", {
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.GuildComponents.DragPlaceholder, {})
})
}));
}
}
2019-02-16 10:41:56 +01:00
}
2019-11-21 14:56:53 +01:00
else e.instance.props.unreadPrivateChannelIds = BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds();
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processPrivateChannel (e) {
if (e.instance.props.channel && e.instance.props.pinned) {
if (e.node) {
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned);
e.node.setAttribute("draggable", false);
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
e.node.PinDMsMouseDownListener = event => {
let mousemove = event2 => {
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
BDFDB.ListenerUtils.stopEvent(event);
this.draggedChannel = e.instance.props.channel.id;
BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList");
let dragpreview = this.createDragPreview(e.node, event2);
2019-02-05 14:23:34 +01:00
document.removeEventListener("mousemove", mousemove);
document.removeEventListener("mouseup", mouseup);
2019-11-21 14:56:53 +01:00
let dragging = event3 => {
this.updateDragPreview(dragpreview, event3);
let hoveredChannel = null;
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmspinnedchannelsheadercontainer, event3.target)) hoveredChannel = "header";
else {
let placeholder = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelplaceholder, event3.target);
hoveredChannel = (BDFDB.ReactUtils.findValue(BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsdmchannelpinned, placeholder ? placeholder.previousSibling : event3.target), "channel", {up: true}) || {}).id;
};
let update = hoveredChannel != this.hoveredChannel;
if (hoveredChannel) this.hoveredChannel = hoveredChannel;
else delete this.hoveredChannel;
if (update) BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList");
2019-02-05 14:23:34 +01:00
};
2019-11-21 14:56:53 +01:00
let releasing = event3 => {
BDFDB.DOMUtils.remove(dragpreview);
if (this.hoveredChannel) this.releasedChannel = this.hoveredChannel;
else delete this.draggedChannel;
delete this.hoveredChannel;
BDFDB.ModuleUtils.forceAllUpdates(this, "PrivateChannelsList");
2019-02-05 14:23:34 +01:00
document.removeEventListener("mousemove", dragging);
document.removeEventListener("mouseup", releasing);
};
document.addEventListener("mousemove", dragging);
document.addEventListener("mouseup", releasing);
}
};
2019-11-21 14:56:53 +01:00
let mouseup = _ => {
2019-02-05 14:23:34 +01:00
document.removeEventListener("mousemove", mousemove);
document.removeEventListener("mouseup", mouseup);
};
document.addEventListener("mousemove", mousemove);
document.addEventListener("mouseup", mouseup);
2019-11-21 14:56:53 +01:00
};
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
}
2019-11-21 14:56:53 +01:00
if (e.returnvalue) e.returnvalue.props.children = [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: BDFDB.LanguageUtils.LanguageStrings.UNPIN,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
className: BDFDB.disCN._pindmsunpinbutton,
onClick: event => {
BDFDB.ListenerUtils.stopEvent(event);
this.removePin(e.instance.props.channel.id, "pinnedDMs");
},
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN._pindmsunpinicon,
name: BDFDB.LibraryComponents.SvgIcon.Names.PIN
})
})
})
2019-11-22 14:26:12 +01:00
].concat(e.returnvalue.props.children).flat(10);
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
processDirectMessage (e) {
if (e.instance.props.channel) {
if (e.node) {
BDFDB.DOMUtils.removeClass(e.node, BDFDB.disCN._pindmsrecentpinned);
e.node.removeEventListener("contextmenu", e.node.PinDMsContextMenuListener);
e.node.PinDMsContextMenuListener = event => {
let pinnedInGuild = this.isPinned(e.instance.props.channel.id, "pinnedRecents");
BDFDB.ContextMenuUtils.open(this, event, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItemGroup, {
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
label: this.labels[pinnedInGuild ? "context_unpinguild_text" : "context_pinguild_text"],
danger: pinnedInGuild,
action: event2 => {
BDFDB.ContextMenuUtils.close(event2.target);
if (!pinnedInGuild) this.addPin(e.instance.props.channel.id, "pinnedRecents");
else this.removePin(e.instance.props.channel.id, "pinnedRecents");
}
})
]
}));
};
e.node.addEventListener("contextmenu", e.node.PinDMsContextMenuListener);
if (this.isPinned(e.instance.props.channel.id, "pinnedRecents")) {
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsrecentpinned);
for (let child of e.node.querySelectorAll("a")) child.setAttribute("draggable", false);
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
e.node.PinDMsMouseDownListener = event => {
let mousemove = event2 => {
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
BDFDB.ListenerUtils.stopEvent(event);
this.draggedChannel = e.instance.props.channel.id;
BDFDB.ModuleUtils.forceAllUpdates(this, "UnreadDMs");
let dragpreview = this.createDragPreview(e.node, event2);
document.removeEventListener("mousemove", mousemove);
document.removeEventListener("mouseup", mouseup);
let dragging = event3 => {
this.updateDragPreview(dragpreview, event3);
let placeholder = BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsrecentplaceholder, event3.target);
let hoveredChannel = (BDFDB.ReactUtils.findValue(BDFDB.DOMUtils.getParent(BDFDB.dotCN._pindmsrecentpinned, placeholder ? placeholder.previousSibling : event3.target), "channel", {up: true}) || {}).id;
let update = hoveredChannel != this.hoveredChannel;
if (hoveredChannel) this.hoveredChannel = hoveredChannel;
else delete this.hoveredChannel;
if (update) BDFDB.ModuleUtils.forceAllUpdates(this, "UnreadDMs");
};
let releasing = event3 => {
BDFDB.DOMUtils.remove(dragpreview);
if (this.hoveredChannel) this.releasedChannel = this.hoveredChannel;
else delete this.draggedChannel;
delete this.hoveredChannel;
BDFDB.ModuleUtils.forceAllUpdates(this, "UnreadDMs");
document.removeEventListener("mousemove", dragging);
document.removeEventListener("mouseup", releasing);
};
document.addEventListener("mousemove", dragging);
document.addEventListener("mouseup", releasing);
}
};
let mouseup = _ => {
document.removeEventListener("mousemove", mousemove);
document.removeEventListener("mouseup", mouseup);
};
document.addEventListener("mousemove", mousemove);
document.addEventListener("mouseup", mouseup);
};
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
}
}
if (e.returnvalue && this.isPinned(e.instance.props.channel.id, "pinnedRecents")) {
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"BlobMask"});
if (index > -1 && !children[index].props.upperBadge && BDFDB.DataUtils.get(this, "settings", "showPinIcon")) children[index].props.upperBadge = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BadgeComponents.IconBadge, {
className: BDFDB.disCN.guildbadgeiconbadge2,
name: BDFDB.LibraryComponents.SvgIcon.Names.NOVA_PIN,
style: {backgroundColor: null}
});
}
}
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
addPin (newid, type) {
if (!newid) return;
let container = this.getContainer(type);
if (!container) return;
let pinnedDMs = BDFDB.DataUtils.load(this, type);
for (let id in pinnedDMs) pinnedDMs[id] = pinnedDMs[id] + 1;
pinnedDMs[newid] = 0;
BDFDB.DataUtils.save(pinnedDMs, this, type);
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:container, unlimited:true}));
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
removePin (id, type) {
if (!id) return;
let container = this.getContainer(type);
if (!container) return;
BDFDB.DataUtils.remove(this, type, id);
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:container, unlimited:true}));
2019-02-05 14:23:34 +01:00
}
2019-11-21 14:56:53 +01:00
isPinned (id, type) {
return BDFDB.DataUtils.load(this, type, id) != undefined;
}
2019-11-21 14:56:53 +01:00
getContainer (type) {
switch (type) {
case "pinnedDMs": return "FluxContainer(PrivateChannels)";
case "pinnedRecents": return "UnreadDMs";
default: return null;
}
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
sortAndUpdate (type) {
let data = BDFDB.DataUtils.load(this, type), newData = {};
delete data[""];
delete data["null"];
let sortedDMs = [], existingDMs = [], sortDM = (id, pos) => {
if (sortedDMs[pos] === undefined) sortedDMs[pos] = id;
else sortDM(id, pos + 1);
};
for (let id in data) sortDM(id, data[id]);
sortedDMs = sortedDMs.filter(n => n);
for (let pos in sortedDMs) {
newData[sortedDMs[pos]] = parseInt(pos);
if (BDFDB.LibraryModules.ChannelStore.getChannel(sortedDMs[pos])) existingDMs.push(sortedDMs[pos]);
}
2019-11-21 14:56:53 +01:00
if (!BDFDB.equals(data, newData)) BDFDB.DataUtils.save(newData, this, type);
return existingDMs;
}
2019-01-26 22:45:19 +01:00
2019-11-21 14:56:53 +01:00
forceUpdateAll () {
BDFDB.ReactUtils.forceUpdate(BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"FluxContainer(PrivateChannels)", all:true, unlimited:true}));
BDFDB.ModuleUtils.forceAllUpdates(this);
}
2019-09-04 12:34:02 +02:00
2019-11-21 14:56:53 +01:00
createDragPreview (div, event) {
if (!Node.prototype.isPrototypeOf(div)) return;
let dragpreview = div.cloneNode(true);
BDFDB.DOMUtils.addClass(dragpreview, BDFDB.disCN._pindmsdragpreview);
BDFDB.DOMUtils.remove(dragpreview.querySelector(BDFDB.dotCNC.guildlowerbadge + BDFDB.dotCNC.guildupperbadge + BDFDB.dotCN.guildpillwrapper));
document.querySelector(BDFDB.dotCN.appmount).appendChild(dragpreview);
let rects = BDFDB.DOMUtils.getRects(dragpreview);
BDFDB.DOMUtils.hide(dragpreview);
dragpreview.style.setProperty("pointer-events", "none", "important");
dragpreview.style.setProperty("left", event.clientX - (rects.width/2) + "px", "important");
dragpreview.style.setProperty("top", event.clientY - (rects.height/2) + "px", "important");
return dragpreview;
}
2019-04-26 23:16:20 +02:00
2019-11-21 14:56:53 +01:00
updateDragPreview (dragpreview, event) {
if (!Node.prototype.isPrototypeOf(dragpreview)) return;
BDFDB.DOMUtils.show(dragpreview);
let rects = BDFDB.DOMUtils.getRects(dragpreview);
dragpreview.style.setProperty("left", event.clientX - (rects.width/2) + "px", "important");
dragpreview.style.setProperty("top", event.clientY - (rects.height/2) + "px", "important");
2019-04-26 23:16:20 +02:00
}
2018-10-11 10:21:26 +02:00
setLabelsByLanguage () {
2019-10-23 11:10:01 +02:00
switch (BDFDB.LanguageUtils.getLanguage().id) {
2018-10-11 10:21:26 +02:00
case "hr": //croatian
return {
context_pindm_text: "Prikljucite Izravnu Poruku",
context_pinchannel_text: "Priložite popisu kanala",
context_unpinchannel_text: "Ukloni s popisa kanala",
context_pinguild_text: "Priložite popisu poslužitelja",
context_unpinguild_text: "Ukloni s popisa poslužitelja",
header_pinneddms_text: "Prikvačene Izravne Poruke"
2018-10-11 10:21:26 +02:00
};
case "da": //danish
return {
context_pindm_text: "Fastgør PB",
context_pinchannel_text: "Vedhæft til kanalliste",
context_unpinchannel_text: "Fjern fra kanalliste",
context_pinguild_text: "Vedhæft til serverliste",
context_unpinguild_text: "Fjern fra serverliste",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Pinned Privat Beskeder"
};
case "de": //german
return {
context_pindm_text: "Direktnachricht anheften",
context_pinchannel_text: "An Kanalliste anheften",
context_unpinchannel_text: "Von Kanalliste loslösen",
context_pinguild_text: "An Serverliste anheften",
context_unpinguild_text: "Von Serverliste loslösen",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Gepinnte Direktnachrichten"
};
case "es": //spanish
return {
context_pindm_text: "Anclar MD",
context_pinchannel_text: "Adjuntar a la lista de canales",
context_unpinchannel_text: "Deshazte de la lista de canales",
context_pinguild_text: "Adjuntar a la lista de servidores",
context_unpinguild_text: "Deshazte de la lista de servidores",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Mensajes Directos Fijados"
};
case "fr": //french
return {
context_pindm_text: "Épingler MP",
context_pinchannel_text: "Épingler à la liste des chaînes",
context_unpinchannel_text: "Détacher de la liste des chaînes",
context_pinguild_text: "Épingler à la liste de serveurs",
context_unpinguild_text: "Détacher de la liste de serveurs",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Messages Prives Épinglés"
};
case "it": //italian
return {
context_pindm_text: "Fissa il messaggio diretto",
context_pinchannel_text: "Allega alla lista dei canali",
context_unpinchannel_text: "Rimuovi dalla lista dei canali",
context_pinguild_text: "Allega alla lista dei server",
context_unpinguild_text: "Rimuovi dalla lista dei server",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Messaggi Diretti Aggiunti"
};
case "nl": //dutch
return {
context_pindm_text: "PB pinnen",
context_pinchannel_text: "Pin naar de kanalenlijst",
context_unpinchannel_text: "Losmaken van kanalenlijst",
context_pinguild_text: "Pin naar de serverlijst",
context_unpinguild_text: "Losmaken van serverlijst",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Vastgezette Persoonluke Berichten"
};
case "no": //norwegian
return {
context_pindm_text: "Fest DM",
context_pinchannel_text: "Fest på kanalliste",
context_unpinchannel_text: "Fjern fra kanalliste",
context_pinguild_text: "Fest på serverliste",
context_unpinguild_text: "Fjern fra serverlisten",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Pinned Direktemeldinger"
};
case "pl": //polish
return {
context_pindm_text: "Przypnij PW",
context_pinchannel_text: "Dołącz do listy kanałów",
context_unpinchannel_text: "Usuń z listy kanałów",
context_pinguild_text: "Dołącz do listy serwerów",
context_unpinguild_text: "Usuń z listy serwerów",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Prywatne Wiadomości Bezpośrednie"
};
case "pt-BR": //portuguese (brazil)
return {
context_pindm_text: "Fixar MD",
context_pinchannel_text: "Anexar à lista de canais",
context_unpinchannel_text: "Remover da lista de canais",
context_pinguild_text: "Anexar à lista de servidores",
context_unpinguild_text: "Remover da lista de servidores",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Mensagens diretas fixadas"
};
case "fi": //finnish
return {
context_pindm_text: "Kiinnitä yksityisviestit",
context_pinchannel_text: "Liitä kanavaluetteloon",
context_unpinchannel_text: "Poista kanavaluettelosta",
context_pinguild_text: "Liitä palvelinluetteloon",
context_unpinguild_text: "Poista palvelinluettelosta",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Liitetyt yksityisviestit"
};
case "sv": //swedish
return {
context_pindm_text: "Fäst DM",
context_pinchannel_text: "Fäst till kanallista",
context_unpinchannel_text: "Ta bort från kanallistan",
context_pinguild_text: "Fäst till servernlista",
context_unpinguild_text: "Ta bort från servernlista",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Inlagda Direktmeddelanden"
};
case "tr": //turkish
return {
context_pindm_text: "DM'yi Sabitle",
context_pinchannel_text: "Kanal listesine ekle",
context_unpinchannel_text: "Kanal listesinden kaldır",
context_pinguild_text: "Sunucu listesine ekle",
context_unpinguild_text: "Sunucu listesinden kaldır",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Direkt Mesajlar Sabitleyin"
};
case "cs": //czech
return {
context_pindm_text: "Připnout PZ",
context_pinchannel_text: "Připojení k seznamu kanálů",
context_unpinchannel_text: "Odstranit ze seznamu kanálů",
context_pinguild_text: "Připojit ke seznamu serverů",
context_unpinguild_text: "Odstranit ze seznamu serverů",
header_pinneddms_text: "Připojené Přímá Zpráva"
2018-10-11 10:21:26 +02:00
};
case "bg": //bulgarian
return {
context_pindm_text: "Закачени ДС",
context_pinchannel_text: "Прикачете към списъка с канали",
context_unpinchannel_text: "Премахване от списъка с канали",
context_pinguild_text: "Прикачване към списъка със сървъри",
context_unpinguild_text: "Премахване от списъка със сървъри",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Свързани директни съобщения"
};
case "ru": //russian
return {
context_pindm_text: "Закрепить ЛС",
context_pinchannel_text: "Прикрепить к списку каналов",
context_unpinchannel_text: "Удалить из списка каналов",
context_pinguild_text: "Присоединить к списку серверов",
context_unpinguild_text: "Удалить из списка серверов",
header_pinneddms_text: "Прикрепленные Личные Сообщения"
2018-10-11 10:21:26 +02:00
};
case "uk": //ukrainian
return {
context_pindm_text: "Закріпити ОП",
context_pinchannel_text: "Додайте до списку каналів",
context_unpinchannel_text: "Видалити зі списку каналів",
context_pinguild_text: "Додайте до списку серверів",
context_unpinguild_text: "Видалити зі списку серверів",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Прикріплені oсобисті повідомлення"
};
case "ja": //japanese
return {
context_pindm_text: "DMピン",
context_pinchannel_text: "チャンネルリストに添付",
context_unpinchannel_text: "チャンネルリストから削除",
context_pinguild_text: "サーバーリストに添付",
context_unpinguild_text: "サーバーリストから削除",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "固定された直接メッセージ"
};
case "zh-TW": //chinese (traditional)
return {
context_pindm_text: "引腳直接留言",
context_pinchannel_text: "附加到頻道列表",
context_unpinchannel_text: "從頻道列表中刪除",
context_pinguild_text: "附加到服務器列表",
context_unpinguild_text: "從服務器列表中刪除",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "固定私人信息"
};
case "ko": //korean
return {
context_pindm_text: "비공개 메시지 고정",
context_pinchannel_text: "채널 목록에 첨부",
context_unpinchannel_text: "채널 목록에서 삭제",
context_pinguild_text: "서버 목록에 첨부",
context_unpinguild_text: "서버 목록에서 제거",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "고정 된 비공개 메시지"
};
default: //default: english
return {
context_pindm_text: "Pin DM",
context_pinchannel_text: "Pin to Channellist",
context_unpinchannel_text: "Unpin from Channellist",
context_pinguild_text: "Pin to Serverlist",
context_unpinguild_text: "Unpin from Serverlist",
2018-10-11 10:21:26 +02:00
header_pinneddms_text: "Pinned Direct Messages"
};
}
}
}