From 1caaa78490854bdd043775fe1b8ea087b0cdad8c Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 17 Apr 2023 01:06:54 +0200 Subject: PinDMs: Add option to sort by most recent message --- src/plugins/pinDms/contextMenus.tsx | 7 ++++--- src/plugins/pinDms/index.tsx | 4 +++- src/plugins/pinDms/settings.ts | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src/plugins/pinDms') diff --git a/src/plugins/pinDms/contextMenus.tsx b/src/plugins/pinDms/contextMenus.tsx index d75c9f9..7d89ec1 100644 --- a/src/plugins/pinDms/contextMenus.tsx +++ b/src/plugins/pinDms/contextMenus.tsx @@ -19,10 +19,11 @@ import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu"; import { Menu } from "@webpack/common"; -import { isPinned, movePin, snapshotArray, togglePin } from "./settings"; +import { isPinned, movePin, PinOrder, settings, snapshotArray, togglePin } from "./settings"; function PinMenuItem(channelId: string) { const pinned = isPinned(channelId); + const canMove = pinned && settings.store.pinOrder === PinOrder.Custom; return ( <> @@ -31,14 +32,14 @@ function PinMenuItem(channelId: string) { label={pinned ? "Unpin DM" : "Pin DM"} action={() => togglePin(channelId)} /> - {pinned && snapshotArray[0] !== channelId && ( + {canMove && snapshotArray[0] !== channelId && ( movePin(channelId, -1)} /> )} - {pinned && snapshotArray[snapshotArray.length - 1] !== channelId && ( + {canMove && snapshotArray[snapshotArray.length - 1] !== channelId && ( . */ -import { Settings, useSettings } from "@api/settings"; +import { definePluginSettings, Settings, useSettings } from "@api/settings"; +import { OptionType } from "@utils/types"; +import { findStoreLazy } from "@webpack"; + +export const enum PinOrder { + LastMessage, + Custom +} + +export const settings = definePluginSettings({ + pinOrder: { + type: OptionType.SELECT, + description: "Which order should pinned DMs be displayed in?", + options: [ + { label: "Most recent message", value: PinOrder.LastMessage, default: true }, + { label: "Custom (right click channels to reorder)", value: PinOrder.Custom } + ] + } +}); + +const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore"); export let snapshotArray: string[]; let snapshot: Set | undefined; @@ -51,9 +71,16 @@ export function togglePin(id: string) { save([...snapshot]); } -export function getPinAt(idx: number) { +function sortedSnapshot() { requireSnapshot(); - return snapshotArray[idx]; + if (settings.store.pinOrder === PinOrder.LastMessage) + return PrivateChannelSortStore.getPrivateChannelIds().filter(isPinned); + + return snapshotArray; +} + +export function getPinAt(idx: number) { + return sortedSnapshot()[idx]; } export function movePin(id: string, direction: -1 | 1) { -- cgit