Compare commits

...

2 commits

Author SHA1 Message Date
V 5d1d054b7e
MessageLinkEmbeds: Use api 2023-06-24 16:55:57 +02:00
V a11d5a9111
Add ComponentUpdaterAPI 2023-06-24 16:46:09 +02:00
4 changed files with 88 additions and 5 deletions

View file

@ -0,0 +1,29 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { proxyLazy } from "@utils/lazy";
const p = proxyLazy<typeof import("plugins/_api/componentUpdater").default>(() => Vencord.Plugins.plugins.ComponentUpdaterAPI as any);
/**
* Rerender a specific message
* @param messageId The id of the message to rerender
*/
export function updateMessageComponent(messageId: string) {
p.forceUpdaters.get(messageId)?.();
}

View file

@ -18,6 +18,7 @@
import * as $Badges from "./Badges";
import * as $Commands from "./Commands";
import * as $ComponentUpdater from "./ComponentUpdater";
import * as $ContextMenu from "./ContextMenu";
import * as $DataStore from "./DataStore";
import * as $MemberListDecorators from "./MemberListDecorators";
@ -109,3 +110,8 @@ export const Notifications = $Notifications;
* An api allowing you to patch and add/remove items to/from context menus
*/
export const ContextMenu = $ContextMenu;
/**
* An api allowing you to update/rerender components
*/
export const ComponentUpdater = $ComponentUpdater;

View file

@ -0,0 +1,51 @@
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 Vendicated and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Devs } from "@utils/constants";
import { useForceUpdater } from "@utils/react";
import definePlugin from "@utils/types";
import { useEffect } from "@webpack/common";
import { Channel, Message } from "discord-types/general";
const forceUpdaters = new Map<string, () => void>();
function useUpdater(data: { channel: Channel; message: Message; }) {
const forceUpdater = useForceUpdater();
useEffect(() => {
forceUpdaters.set(data.message.id, forceUpdater);
return () => void forceUpdaters.delete(data.message.id);
}, [data.message.id]);
}
export default definePlugin({
name: "ComponentUpdaterAPI",
description: "API to update / force rerender several components, such as messages",
authors: [Devs.Ven],
patches: [{
find: ".renderContentOnly;",
replacement: {
match: /=(\i)\.renderContentOnly;/,
replace: "$&$self.useUpdater($1);"
}
}],
useUpdater,
forceUpdaters
});

View file

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { updateMessageComponent } from "@api/ComponentUpdater";
import { addAccessory } from "@api/MessageAccessories";
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
@ -28,7 +29,6 @@ import { find, findByCode, findByPropsLazy } from "@webpack";
import {
Button,
ChannelStore,
FluxDispatcher,
GuildStore,
MessageStore,
Parser,
@ -228,10 +228,7 @@ function MessageEmbedAccessory({ message }: { message: Message; }) {
delete msg.interaction;
messageFetchQueue.push(() => fetchMessage(channelID, messageID)
.then(m => m && FluxDispatcher.dispatch({
type: "MESSAGE_UPDATE",
message: msg
}))
.then(m => m && updateMessageComponent(message.id))
);
continue;
}