fix message hover buttons

This commit is contained in:
Vendicated 2024-08-03 11:02:26 +02:00
parent e437498c8f
commit 8274b67597
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
2 changed files with 15 additions and 9 deletions

View file

@ -16,9 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import ErrorBoundary from "@components/ErrorBoundary";
import { Logger } from "@utils/Logger"; import { Logger } from "@utils/Logger";
import { Channel, Message } from "discord-types/general"; import { Channel, Message } from "discord-types/general";
import type { ComponentType, MouseEventHandler, ReactElement } from "react"; import type { ComponentType, MouseEventHandler } from "react";
const logger = new Logger("MessagePopover"); const logger = new Logger("MessagePopover");
@ -48,22 +49,26 @@ export function removeButton(identifier: string) {
} }
export function _buildPopoverElements( export function _buildPopoverElements(
msg: Message, Component: React.ComponentType<ButtonItem>,
PopoverButton: ComponentType<ButtonItem>, props: { message: Message; }
) { ) {
const items = [] as ReactElement[]; const items: React.ReactNode[] = [];
for (const [identifier, getItem] of buttons.entries()) { for (const [identifier, getItem] of buttons.entries()) {
try { try {
const item = getItem(msg); const item = getItem(props.message);
if (item) { if (item) {
item.key ??= identifier; item.key ??= identifier;
items.push(<PopoverButton {...item} />); items.push(
<ErrorBoundary noop>
<Component {...item} {...props} />
</ErrorBoundary>
);
} }
} catch (err) { } catch (err) {
logger.error(`[${identifier}]`, err); logger.error(`[${identifier}]`, err);
} }
} }
return items; return <>{items}</>;
} }

View file

@ -26,8 +26,9 @@ export default definePlugin({
patches: [{ patches: [{
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
replacement: { replacement: {
match: /"reply-self".+?Fragment,{children:\[(?=.+?\((\i\.\i),{label:)(?<=message:(\i).+?)/, // foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other))
replace: (m, PopoverButton, msg) => `${m}...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${PopoverButton}),` match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?\(0,\i\.jsx\)\((\i\.\i).{0,200}\.\.\.(\i)\},"reply-other"/,
replace: "Vencord.Api.MessagePopover._buildPopoverElements($1,$2),$&"
} }
}], }],
}); });