mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-18 05:13:29 -05:00
MessagePeek
This commit is contained in:
parent
94372e1d6e
commit
2c773ec7d1
6 changed files with 120 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -24,3 +24,5 @@ src/userplugins
|
|||
|
||||
ExtensionCache/
|
||||
settings/
|
||||
|
||||
src/equicordplugins/usrpe
|
||||
|
|
|
@ -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
|
||||
|
|
47
src/equicordplugins/messagePeek/components/MessagePeek.tsx
Normal file
47
src/equicordplugins/messagePeek/components/MessagePeek.tsx
Normal 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>
|
||||
);
|
||||
}
|
5
src/equicordplugins/messagePeek/components/styles.css
Normal file
5
src/equicordplugins/messagePeek/components/styles.css
Normal file
|
@ -0,0 +1,5 @@
|
|||
a[href^="/channels/@me"] [class^="layout"] {
|
||||
min-height: 42px;
|
||||
max-height: 50px;
|
||||
height: unset;
|
||||
}
|
53
src/equicordplugins/messagePeek/index.tsx
Normal file
53
src/equicordplugins/messagePeek/index.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
});
|
12
src/equicordplugins/messagePeek/types/index.ts
Normal file
12
src/equicordplugins/messagePeek/types/index.ts
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue