From c311155d7cba0658eaba6ba8b081e465cc18bceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jade=20=E3=83=BB=3A*=E3=83=BB=E3=80=82*=E3=83=BB?= Date: Sat, 6 Apr 2024 06:29:08 +1100 Subject: [PATCH] PinDMs: Fix unexpected behaviours when using last message sort (#2324) --- src/plugins/pinDms/data.ts | 9 +++++++-- src/plugins/pinDms/index.tsx | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/plugins/pinDms/data.ts b/src/plugins/pinDms/data.ts index afb6f9795..a4e40dde0 100644 --- a/src/plugins/pinDms/data.ts +++ b/src/plugins/pinDms/data.ts @@ -9,7 +9,7 @@ import { Settings } from "@api/Settings"; import { UserStore } from "@webpack/common"; import { DEFAULT_COLOR } from "./constants"; -import { forceUpdate } from "./index"; +import { forceUpdate, PinOrder, PrivateChannelSortStore, settings } from "./index"; export interface Category { id: string; @@ -106,7 +106,12 @@ export function categoryLen() { } export function getAllUncollapsedChannels() { - return categories.filter(c => !c.collapsed).map(c => c.channels).flat(); + if (settings.store.pinOrder === PinOrder.LastMessage) { + const sortedChannels = PrivateChannelSortStore.getPrivateChannelIds(); + return categories.filter(c => !c.collapsed).flatMap(c => sortedChannels.filter(channel => c.channels.includes(channel))); + } + + return categories.filter(c => !c.collapsed).flatMap(c => c.channels); } export function getSections() { diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index 353fc482a..010b5506c 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -29,7 +29,7 @@ interface ChannelComponentProps { const headerClasses = findByPropsLazy("privateChannelsHeaderContainer"); -const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; +export const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; export let instance: any; export const forceUpdate = () => instance?.props?._forceUpdate?.(); @@ -236,7 +236,7 @@ export default definePlugin({ const category = categories[categoryIndex - 1]; if (!category) return false; - return category.collapsed && this.instance.props.selectedChannelId !== category.channels[channelIndex]; + return category.collapsed && this.instance.props.selectedChannelId !== this.getCategoryChannels(category)[channelIndex]; }, getScrollOffset(channelId: string, rowHeight: number, padding: number, preRenderedChildren: number, originalOffset: number) {