fix: open last opened server channel instead of first

This commit is contained in:
Paul Makles 2022-05-27 22:32:06 +01:00
parent e2d9e41a58
commit 12b9716043

View file

@ -23,9 +23,8 @@ import MessageBox from "../../components/common/messaging/MessageBox";
import JumpToBottom from "../../components/common/messaging/bars/JumpToBottom";
import NewMessages from "../../components/common/messaging/bars/NewMessages";
import TypingIndicator from "../../components/common/messaging/bars/TypingIndicator";
import { PageHeader } from "../../components/ui/Header";
import RightSidebar from "../../components/navigation/RightSidebar";
import { PageHeader } from "../../components/ui/Header";
import ChannelHeader from "./ChannelHeader";
import { MessageArea } from "./messaging/MessageArea";
import VoiceHeader from "./voice/VoiceHeader";
@ -100,14 +99,23 @@ const PlaceholderBase = styled.div`
export const Channel = observer(
({ id, server_id }: { id: string; server_id: string }) => {
const client = useClient();
const state = useApplicationState();
if (!client.channels.exists(id)) {
if (server_id) {
const server = client.servers.get(server_id);
if (server && server.channel_ids.length > 0) {
let target_id = server.channel_ids[0];
const last_id = state.layout.getLastOpened(server_id);
if (last_id) {
if (client.channels.has(last_id)) {
target_id = last_id;
}
}
return (
<Redirect
to={`/server/${server_id}/channel/${server.channel_ids[0]}`}
to={`/server/${server_id}/channel/${target_id}`}
/>
);
}