AutoJump -> JumpTo & Remove Automatic Jump

This commit is contained in:
thororen1234 2025-09-15 09:53:48 -04:00
parent 54dc1550f8
commit 7189b34dad
No known key found for this signature in database
3 changed files with 59 additions and 121 deletions

View file

@ -1,80 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import { Menu, ChannelStore, NavigationRouter, FluxDispatcher, MessageActions, MessageStore } from "@webpack/common";
interface ChannelSelectEvent {
type: "CHANNEL_SELECT";
channelId: string | null;
guildId: string | null;
}
let lastChan = "0";
function jumpToPresent(channelId, { limit }: { limit?: number } = {}) {
MessageActions.trackJump(channelId, null, "Present");
const jump = { present: true };
if (MessageStore.hasPresent(channelId)) {
FluxDispatcher.dispatch({
type: "LOAD_MESSAGES_SUCCESS_CACHED",
jump,
channelId,
limit
});
} else {
MessageActions.fetchMessages({
channelId,
limit,
jump
});
}
}
function autoJump(channel: any) {
const guildId = channel.guild_id ?? "@me";
const channelId = channel.id;
if (channelId === lastChan) return;
NavigationRouter.transitionTo(`/channels/${guildId}/${channelId}`);
lastChan = channelId;
jumpToPresent(channelId, { limit: 100 });
}
const MenuPatch: NavContextMenuPatchCallback = (children, { channel }) => {
children.push(
<Menu.MenuItem
id="auto-jump"
label="Jump to Last Message"
action={() => autoJump(channel)}
/>
);
};
export default definePlugin({
name: "AutoJump",
description: "Automatically jumps to the last message in selected channel & adds a context-menu option to jump to the last message.",
authors: [EquicordDevs.omaw],
contextMenus: {
"channel-context": MenuPatch,
"user-context": MenuPatch,
"thread-context": MenuPatch
},
flux: {
async CHANNEL_SELECT({ guildId, channelId }: ChannelSelectEvent) {
if (!guildId || !channelId) return;
const channel = ChannelStore.getChannel(channelId);
if (!channel || lastChan === channel.id) return;
autoJump(channel);
}
}
});

View file

@ -0,0 +1,59 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { migratePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { Menu, NavigationRouter, RestAPI } from "@webpack/common";
function jumpToFirstMessage(props) {
const guildid = props.guild_id !== null ? props.guild_id : "@me";
const channelid = props.id;
const url = `/channels/${guildid}/${channelid}/0`;
NavigationRouter.transitionTo(url);
}
async function jumpToBottom(props) {
const guildid = props.guild_id ?? "@me";
const channelid = props.id;
const res = await RestAPI.get({
url: `/channels/${channelid}/messages?limit=1`
});
const lastMessageId = res.body?.[0]?.id;
if (!lastMessageId) return;
const url = `/channels/${guildid}/${channelid}/${lastMessageId}`;
NavigationRouter.transitionTo(url);
}
const MenuPatch: NavContextMenuPatchCallback = (children, { channel }) => {
children.push(
<Menu.MenuItem
id="vc-jump-to-first"
label="Jump To First Message"
action={() => jumpToFirstMessage(channel)}
/>,
<Menu.MenuItem
id="vc-jump-to-bottom"
label="Jump To Bottom"
action={() => jumpToBottom(channel)}
/>
);
};
migratePluginSettings("JumpTo", "JumpToStart", "AutoJump");
export default definePlugin({
name: "JumpTo",
description: "Adds context menu options to jump to the start or bottom of a channel/DM",
authors: [Devs.Samwich, Devs.thororen],
contextMenus: {
"channel-context": MenuPatch,
"user-context": MenuPatch,
"thread-context": MenuPatch
}
});

View file

@ -1,41 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { Menu, NavigationRouter } from "@webpack/common";
function jumpToFirstMessage(props) {
const guildid = props.guild_id !== null ? props.guild_id : "@me";
const channelid = props.id;
const url = `/channels/${guildid}/${channelid}/0`;
NavigationRouter.transitionTo(url);
}
const MenuPatch: NavContextMenuPatchCallback = (children, { channel }) => {
children.push(
<Menu.MenuItem
id="vc-jump-to-first"
label="Jump To First Message"
action={() => {
jumpToFirstMessage(channel);
}}
/>
);
};
export default definePlugin({
name: "JumpToStart",
description: "Adds a context menu option to jump to the start of a channel/DM",
authors: [Devs.Samwich],
contextMenus:
{
"channel-context": MenuPatch,
"user-context": MenuPatch,
"thread-context": MenuPatch
}
});