diff --git a/.gitignore b/.gitignore index f056feac..1055b510 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ src/userplugins ExtensionCache/ settings/ + +src/equicordplugins/usrpe diff --git a/README.md b/README.md index 21f08fe1..d7df733a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/equicordplugins/messagePeek/components/MessagePeek.tsx b/src/equicordplugins/messagePeek/components/MessagePeek.tsx new file mode 100644 index 00000000..9dbe01b1 --- /dev/null +++ b/src/equicordplugins/messagePeek/components/MessagePeek.tsx @@ -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 ( +
+ 256 ? Parser.parse(content.slice(0, 256).trim()) : Parser.parse(content)}> +
+ {`${(lastMessage.author as any).globalName || lastMessage.author.username}: `} + {Parser.parseInlineReply(content)} +
+
+
+ ); +} diff --git a/src/equicordplugins/messagePeek/components/styles.css b/src/equicordplugins/messagePeek/components/styles.css new file mode 100644 index 00000000..694ff06a --- /dev/null +++ b/src/equicordplugins/messagePeek/components/styles.css @@ -0,0 +1,5 @@ +a[href^="/channels/@me"] [class^="layout"] { + min-height: 42px; + max-height: 50px; + height: unset; +} diff --git a/src/equicordplugins/messagePeek/index.tsx b/src/equicordplugins/messagePeek/index.tsx new file mode 100644 index 00000000..8e4e2bc5 --- /dev/null +++ b/src/equicordplugins/messagePeek/index.tsx @@ -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 ( + + + + ); + } +}); diff --git a/src/equicordplugins/messagePeek/types/index.ts b/src/equicordplugins/messagePeek/types/index.ts new file mode 100644 index 00000000..89ced8a4 --- /dev/null +++ b/src/equicordplugins/messagePeek/types/index.ts @@ -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; +}