PinDMs: Add option to sort by most recent message
This commit is contained in:
parent
d35654b887
commit
1caaa78490
|
@ -19,10 +19,11 @@
|
||||||
import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
import { addContextMenuPatch, findGroupChildrenByChildId, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
||||||
import { Menu } from "@webpack/common";
|
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) {
|
function PinMenuItem(channelId: string) {
|
||||||
const pinned = isPinned(channelId);
|
const pinned = isPinned(channelId);
|
||||||
|
const canMove = pinned && settings.store.pinOrder === PinOrder.Custom;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -31,14 +32,14 @@ function PinMenuItem(channelId: string) {
|
||||||
label={pinned ? "Unpin DM" : "Pin DM"}
|
label={pinned ? "Unpin DM" : "Pin DM"}
|
||||||
action={() => togglePin(channelId)}
|
action={() => togglePin(channelId)}
|
||||||
/>
|
/>
|
||||||
{pinned && snapshotArray[0] !== channelId && (
|
{canMove && snapshotArray[0] !== channelId && (
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="move-pin-up"
|
id="move-pin-up"
|
||||||
label="Move Pin Up"
|
label="Move Pin Up"
|
||||||
action={() => movePin(channelId, -1)}
|
action={() => movePin(channelId, -1)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{pinned && snapshotArray[snapshotArray.length - 1] !== channelId && (
|
{canMove && snapshotArray[snapshotArray.length - 1] !== channelId && (
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="move-pin-down"
|
id="move-pin-down"
|
||||||
label="Move Pin Down"
|
label="Move Pin Down"
|
||||||
|
|
|
@ -21,7 +21,7 @@ import definePlugin from "@utils/types";
|
||||||
import { Channel } from "discord-types/general";
|
import { Channel } from "discord-types/general";
|
||||||
|
|
||||||
import { addContextMenus, removeContextMenus } from "./contextMenus";
|
import { addContextMenus, removeContextMenus } from "./contextMenus";
|
||||||
import { getPinAt, isPinned, snapshotArray, usePinnedDms } from "./settings";
|
import { getPinAt, isPinned, settings, snapshotArray, usePinnedDms } from "./settings";
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "PinDMs",
|
name: "PinDMs",
|
||||||
|
@ -30,6 +30,8 @@ export default definePlugin({
|
||||||
|
|
||||||
dependencies: ["ContextMenuAPI"],
|
dependencies: ["ContextMenuAPI"],
|
||||||
|
|
||||||
|
settings,
|
||||||
|
|
||||||
start: addContextMenus,
|
start: addContextMenus,
|
||||||
stop: removeContextMenus,
|
stop: removeContextMenus,
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,27 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* 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[];
|
export let snapshotArray: string[];
|
||||||
let snapshot: Set<string> | undefined;
|
let snapshot: Set<string> | undefined;
|
||||||
|
@ -51,9 +71,16 @@ export function togglePin(id: string) {
|
||||||
save([...snapshot]);
|
save([...snapshot]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPinAt(idx: number) {
|
function sortedSnapshot() {
|
||||||
requireSnapshot();
|
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) {
|
export function movePin(id: string, direction: -1 | 1) {
|
||||||
|
|
2
src/webpack/common/types/utils.d.ts
vendored
2
src/webpack/common/types/utils.d.ts
vendored
|
@ -68,7 +68,7 @@ export interface SnowflakeUtils {
|
||||||
extractTimestamp(snowflake: string): number;
|
extractTimestamp(snowflake: string): number;
|
||||||
age(snowflake: string): number;
|
age(snowflake: string): number;
|
||||||
atPreviousMillisecond(snowflake: string): string;
|
atPreviousMillisecond(snowflake: string): string;
|
||||||
compare(snowflake1: string, snowflake2: string): number;
|
compare(snowflake1?: string, snowflake2?: string): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RestRequestData {
|
interface RestRequestData {
|
||||||
|
|
Loading…
Reference in a new issue