stuff
This commit is contained in:
parent
24066bf15b
commit
4d838f997e
|
@ -1653,7 +1653,7 @@
|
|||
function check (instance) {
|
||||
if (!instance) return false;
|
||||
let props = instance.stateNode ? instance.stateNode.props : instance.props;
|
||||
return instance.type && config.name && config.name.some(name => ((instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name || instance.type) === name)) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => propCheck(props, prop[0], checkvalue)) : propCheck(props, prop[0], prop[1])) : props[prop] !== undefined) || config.filter && config.filter(instance);
|
||||
return instance.type && config.name && config.name.some(name => (instance.type.render && instance.type.render.displayName === name || instance.type.displayName === name || instance.type.name === name || instance.type === name)) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => propCheck(props, prop[0], checkvalue)) : propCheck(props, prop[0], prop[1])) : props[prop] !== undefined) || config.filter && config.filter(instance);
|
||||
}
|
||||
function propCheck (props, key, value) {
|
||||
return key != null && props[key] != null && value != null && (key == "className" ? (" " + props[key] + " ").indexOf(" " + value + " ") > -1 : BDFDB.equals(props[key], value));
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
class PinDMs {
|
||||
getName () {return "PinDMs";}
|
||||
|
||||
getVersion () {return "1.5.2";}
|
||||
getVersion () {return "1.5.3";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
|
@ -11,6 +11,7 @@ class PinDMs {
|
|||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"added":[["Sort Order","You can now enable the option in the plugin settings to sort pinned DMs in the most recent message order within category"]],
|
||||
"improved":[["Categories","Instead of pinning all your channels into the same category in the private channel list, you can now create your own collapsable categories, old pinned channel data was ported to the new category format"],["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
|
@ -280,10 +281,12 @@ class PinDMs {
|
|||
if (categories.length) {
|
||||
e.instance.props.channels = Object.assign({}, e.instance.props.channels);
|
||||
e.instance.props.pinnedChannels = Object.assign({}, e.instance.props.pinnedChannels);
|
||||
for (let category of categories) for (let id of category.dms) if (e.instance.props.channels[id]) {
|
||||
e.instance.props.privateChannelIds = [].concat(e.instance.props.privateChannelIds).filter(n => n);
|
||||
for (let category of categories) for (let id of this.sortDMsByTime(category.dms)) if (e.instance.props.channels[id]) {
|
||||
e.instance.props.pinnedChannels[id] = e.instance.props.channels[id];
|
||||
delete e.instance.props.channels[id];
|
||||
BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
|
||||
e.instance.props.privateChannelIds.unshift(id);
|
||||
}
|
||||
if (e.returnvalue) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ListSectionItem"});
|
||||
|
@ -356,14 +359,14 @@ class PinDMs {
|
|||
if (this.hoveredChannel == "header_" + category.id) children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, {
|
||||
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder
|
||||
}));
|
||||
for (let id of category.dms) if (e.instance.props.pinnedChannels[id]) {
|
||||
if (!e.instance.props.privateChannelIds.includes(id)) e.instance.props.privateChannelIds.unshift(id);
|
||||
if (this.draggedChannel != id && (!category.collapsed || e.instance.props.selectedChannelId == id)) {
|
||||
for (let id of this.sortDMsByTime(category.dms)) {
|
||||
if (e.instance.props.pinnedChannels[id] && this.draggedChannel != id && (!category.collapsed || e.instance.props.selectedChannelId == id)) {
|
||||
children.splice(index++, 0, e.instance.props.renderChannel(e.instance.props.pinnedChannels[id], e.instance.props.selectedChannelId == id));
|
||||
if (this.hoveredChannel == id) children.splice(index++, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ListItem, {
|
||||
className: BDFDB.disCNS.dmchannel + BDFDB.disCNS._pindmsdmchannelpinned + BDFDB.disCN._pindmsdmchannelplaceholder
|
||||
}));
|
||||
}
|
||||
else BDFDB.ArrayUtils.remove(e.instance.props.privateChannelIds, id, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -419,8 +422,9 @@ class PinDMs {
|
|||
if (category) {
|
||||
if (e.node) {
|
||||
BDFDB.DOMUtils.addClass(e.node, BDFDB.disCN._pindmsdmchannelpinned);
|
||||
e.node.setAttribute("draggable", false);
|
||||
e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
|
||||
if (!BDFDB.DataUtils.get(this, "settings", "sortInRecentOrder")) {
|
||||
e.node.setAttribute("draggable", false);
|
||||
e.node.PinDMsMouseDownListener = event => {
|
||||
if (!BDFDB.BdUtils.isPluginEnabled("PinDMs")) e.node.removeEventListener("mousedown", e.node.PinDMsMouseDownListener);
|
||||
else {
|
||||
|
@ -473,7 +477,9 @@ class PinDMs {
|
|||
};
|
||||
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
|
||||
}
|
||||
if (e.returnvalue) e.returnvalue.props.children = [
|
||||
}
|
||||
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, {
|
||||
|
@ -492,6 +498,7 @@ class PinDMs {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processDirectMessage (e) {
|
||||
if (e.instance.props.channel) {
|
||||
|
@ -502,8 +509,9 @@ class PinDMs {
|
|||
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);
|
||||
if (!BDFDB.DataUtils.get(this, "settings", "sortInRecentOrder")) {
|
||||
for (let child of e.node.querySelectorAll("a")) child.setAttribute("draggable", false);
|
||||
e.node.PinDMsMouseDownListener = event => {
|
||||
let mousemove = event2 => {
|
||||
if (Math.sqrt((event.pageX - event2.pageX)**2) > 20 || Math.sqrt((event.pageY - event2.pageY)**2) > 20) {
|
||||
|
@ -545,6 +553,7 @@ class PinDMs {
|
|||
e.node.addEventListener("mousedown", e.node.PinDMsMouseDownListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.isPinned(e.instance.props.channel.id, "pinnedRecents") && BDFDB.DataUtils.get(this, "settings", "showPinIcon")) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:"BlobMask"});
|
||||
if (index > -1) children[index].props.upperLeftBadge = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BadgeComponents.IconBadge, {
|
||||
|
@ -603,6 +612,14 @@ class PinDMs {
|
|||
return reverse ? sorted.reverse() : sorted;
|
||||
}
|
||||
|
||||
sortDMsByTime (dms) {
|
||||
if (dms.length > 1 && BDFDB.DataUtils.get(this, "settings", "sortInRecentOrder")) {
|
||||
let timestamps = BDFDB.LibraryModules.DirectMessageStore.getPrivateChannelTimestamps();
|
||||
return [].concat(dms).sort(function (x, y) {return timestamps[x] > timestamps[y] ? -1 : timestamps[x] < timestamps[y] ? 1 : 0;});
|
||||
}
|
||||
else return dms;
|
||||
}
|
||||
|
||||
openCategorySettingsModal (data, type, isNew) {
|
||||
if (BDFDB.ObjectUtils.is(data) && type) BDFDB.ModalUtils.open(this, {
|
||||
size: "SMALL",
|
||||
|
@ -679,7 +696,7 @@ class PinDMs {
|
|||
if (BDFDB.LibraryModules.ChannelStore.getChannel(sortedDMs[pos])) existingDMs.push(sortedDMs[pos]);
|
||||
}
|
||||
if (!BDFDB.equals(data, newData)) BDFDB.DataUtils.save(newData, this, type);
|
||||
return existingDMs;
|
||||
return this.sortDMsByTime(existingDMs);
|
||||
}
|
||||
|
||||
forceUpdateAll () {
|
||||
|
|
|
@ -127,16 +127,30 @@ class ReadAllNotificationsButton {
|
|||
|
||||
onUserContextMenu (e) {
|
||||
if (e.instance.props.channelId && e.instance.props.type == BDFDB.DiscordConstants.ContextMenuTypes.USER_PRIVATE_CHANNELS) {
|
||||
e.returnvalue.props.children.props.children.props.children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
onGroupDMContextMenu (e) {
|
||||
if (e.instance.props.channelId) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: BDFDB.LibraryComponents.ContextMenuItems.Group});
|
||||
if (index > -1) this.injectItem(children, e.instance.props.channelId);
|
||||
}
|
||||
}
|
||||
|
||||
injectItem (children, channelId) {
|
||||
children.unshift(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Group, {
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItems.Item, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.MARK_AS_READ,
|
||||
disabled: !BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds().includes(e.instance.props.channelId),
|
||||
disabled: !BDFDB.LibraryModules.DirectMessageUnreadStore.getUnreadPrivateChannelIds().includes(channelId),
|
||||
action: event => {
|
||||
BDFDB.ContextMenuUtils.close(event.target);
|
||||
BDFDB.DMUtils.markAsRead(e.instance.props.channelId);
|
||||
BDFDB.DMUtils.markAsRead(channelId);
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
processGuilds (e) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "ConnectedUnreadDMs"});
|
||||
|
|
Loading…
Reference in New Issue