MessagePeek

This commit is contained in:
thororen1234 2024-10-26 16:59:38 -04:00
parent 94372e1d6e
commit 2c773ec7d1
6 changed files with 120 additions and 0 deletions

2
.gitignore vendored
View file

@ -24,3 +24,5 @@ src/userplugins
ExtensionCache/
settings/
src/equicordplugins/usrpe

View file

@ -84,6 +84,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
- MessageColors by Hen
- MessageLinkTooltip by Kyuuhachi
- MessageLoggerEnhanced by Aria
- MessagePeek by HypedDomi
- MessageTranslate by Samwich
- ModalFade by Kyuuhachi
- MoreStickers by Leko & Arjix

View file

@ -0,0 +1,47 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./styles.css";
import { findByPropsLazy } from "@webpack";
import { MessageStore, Parser, TooltipContainer, useStateFromStores } from "@webpack/common";
import { Message } from "discord-types/general";
import { MessagePeekProps } from "../types";
const ChannelWrapperStyles = findByPropsLazy("muted", "subText");
const ChannelStyles = findByPropsLazy("closeButton", "subtext");
export default function MessagePeek(props: MessagePeekProps) {
const { channel, channel_url } = props;
if (!channel && !channel_url) return null;
const channelId = channel ? channel.id : channel_url.split("/").pop() as string;
const lastMessage: Message = useStateFromStores([MessageStore], () => MessageStore.getMessages(channelId)?.last());
if (!lastMessage) return null;
const attachmentCount = lastMessage.attachments.length;
const content =
lastMessage.content ||
lastMessage.embeds?.[0]?.rawDescription ||
lastMessage.stickerItems.length && "Sticker" ||
attachmentCount && `${attachmentCount} attachment${attachmentCount > 1 ? "s" : ""}`;
if (!content) return null;
return (
<div
className={ChannelWrapperStyles.subText}
style={{ marginBottom: "2px" }}
>
<TooltipContainer text={content.length > 256 ? Parser.parse(content.slice(0, 256).trim()) : Parser.parse(content)}>
<div className={ChannelStyles.subtext}>
{`${(lastMessage.author as any).globalName || lastMessage.author.username}: `}
{Parser.parseInlineReply(content)}
</div>
</TooltipContainer>
</div>
);
}

View file

@ -0,0 +1,5 @@
a[href^="/channels/@me"] [class^="layout"] {
min-height: 42px;
max-height: 50px;
height: unset;
}

View file

@ -0,0 +1,53 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import ErrorBoundary from "@components/ErrorBoundary";
import { EquicordDevs } from "@utils/constants";
import definePlugin from "@utils/types";
import MessagePeek from "./components/MessagePeek";
import { MessagePeekProps } from "./types";
export default definePlugin({
name: "MessagePeek",
description: "See the last message in a Channel like on mobile",
authors: [EquicordDevs.HypedDomi],
patches: [
{
// DMs
find: /let{className:[^],focusProps:[^],...[^]}=[^];return\(/,
replacement: {
match: /(?<=\.\.\.([^])[^]*)}=[^];/,
replace: `$&
if ($1.children?.props?.children?.[0]?.props?.children?.props)
$1.children.props.children[0].props.children.props.subText = [
$1.children.props.children[0].props.children.props?.subText,
$self.renderMessagePeek({ channel_url: $1.children.props.children[0].props.to })
];
`.replace(/\s+/g, "")
}
},
{
// Guild channels
find: /{href:[^],children:[^],onClick:[^],onKeyPress:[^],focusProps:[^],/,
replacement: {
match: /(?<=children:([^])[^]*)}\);/,
replace: `$&
$1[0].props.children[1].props.children=[
$1[0].props.children[1].props.children,
$self.renderMessagePeek({ channel: $1[0].props.children[0].props.channel })
];`.replace(/\s+/g, "")
}
}
],
renderMessagePeek: (props: MessagePeekProps) => {
return (
<ErrorBoundary noop>
<MessagePeek {...props} />
</ErrorBoundary>
);
}
});

View file

@ -0,0 +1,12 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Channel } from "discord-types/general";
export interface MessagePeekProps {
channel: Channel;
channel_url: string;
}