Plugin
KeepCurrentChannel
Attempt to navigate to the channel you were in before switching accounts or loading Discord.
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import * as DataStore from "@api/DataStore";8
import { Devs } from "@utils/constants";9
import definePlugin from "@utils/types";10
import { ChannelRouter, ChannelStore, NavigationRouter, SelectedChannelStore, SelectedGuildStore } from "@webpack/common";11
12
export interface LogoutEvent {13
type: "LOGOUT";14
isSwitchingAccount: boolean;15
}16
17
interface ChannelSelectEvent {18
type: "CHANNEL_SELECT";19
channelId: string | null;20
guildId: string | null;21
}22
23
interface PreviousChannel {24
guildId: string | null;25
channelId: string | null;26
}27
28
let isSwitchingAccount = false;29
let previousCache: PreviousChannel | undefined;30
31
export default definePlugin({32
name: "KeepCurrentChannel",33
description: "Attempt to navigate to the channel you were in before switching accounts or loading Discord.",34
tags: ["Utility", "Organisation"],35
authors: [Devs.Nuckyz],36
37
patches: [38
{39
find: 039;"Switching accounts"039;,40
replacement: {41
match: /goHomeAfterSwitching:\i/,42
replace: "goHomeAfterSwitching:!1"43
}44
}45
],46
47
flux: {48
LOGOUT(e: LogoutEvent) {49
({ isSwitchingAccount } = e);50
},51
52
CONNECTION_OPEN() {53
if (!isSwitchingAccount) return;54
isSwitchingAccount = false;55
56
if (previousCache?.channelId) {57
if (ChannelStore.hasChannel(previousCache.channelId)) {58
ChannelRouter.transitionToChannel(previousCache.channelId);59
} else {60
NavigationRouter.transitionToGuild("@me");61
}62
}63
},64
65
async CHANNEL_SELECT({ guildId, channelId }: ChannelSelectEvent) {66
if (isSwitchingAccount) return;67
68
previousCache = {69
guildId,70
channelId71
};72
await DataStore.set("KeepCurrentChannel_previousData", previousCache);73
}74
},75
76
async start() {77
previousCache = await DataStore.get<PreviousChannel>("KeepCurrentChannel_previousData");78
if (!previousCache) {79
previousCache = {80
guildId: SelectedGuildStore.getGuildId(),81
channelId: SelectedChannelStore.getChannelId() ?? null82
};83
84
await DataStore.set("KeepCurrentChannel_previousData", previousCache);85
} else if (previousCache.channelId) {86
ChannelRouter.transitionToChannel(previousCache.channelId);87
}88
}89
});90