diff options
author | Vendicated <vendicated@riseup.net> | 2023-04-17 01:06:54 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2023-04-17 01:06:54 +0200 |
commit | 1caaa78490854bdd043775fe1b8ea087b0cdad8c (patch) | |
tree | c7344fa8fc0d578273806a0157db0b263cf9887f /src/plugins/pinDms/settings.ts | |
parent | d35654b887d9a736e0d01a91b70d9e2feb19a398 (diff) | |
download | Vencord-1caaa78490854bdd043775fe1b8ea087b0cdad8c.tar.gz Vencord-1caaa78490854bdd043775fe1b8ea087b0cdad8c.tar.bz2 Vencord-1caaa78490854bdd043775fe1b8ea087b0cdad8c.zip |
PinDMs: Add option to sort by most recent message
Diffstat (limited to 'src/plugins/pinDms/settings.ts')
-rw-r--r-- | src/plugins/pinDms/settings.ts | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/plugins/pinDms/settings.ts b/src/plugins/pinDms/settings.ts index 2526c69..092a0db 100644 --- a/src/plugins/pinDms/settings.ts +++ b/src/plugins/pinDms/settings.ts @@ -16,7 +16,27 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -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<string> | 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) { |