Compare commits
2 commits
main
...
componentU
Author | SHA1 | Date | |
---|---|---|---|
|
5d1d054b7e | ||
|
a11d5a9111 |
4 changed files with 88 additions and 5 deletions
29
src/api/ComponentUpdater.ts
Normal file
29
src/api/ComponentUpdater.ts
Normal 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)?.();
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
import * as $Badges from "./Badges";
|
import * as $Badges from "./Badges";
|
||||||
import * as $Commands from "./Commands";
|
import * as $Commands from "./Commands";
|
||||||
|
import * as $ComponentUpdater from "./ComponentUpdater";
|
||||||
import * as $ContextMenu from "./ContextMenu";
|
import * as $ContextMenu from "./ContextMenu";
|
||||||
import * as $DataStore from "./DataStore";
|
import * as $DataStore from "./DataStore";
|
||||||
import * as $MemberListDecorators from "./MemberListDecorators";
|
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
|
* An api allowing you to patch and add/remove items to/from context menus
|
||||||
*/
|
*/
|
||||||
export const ContextMenu = $ContextMenu;
|
export const ContextMenu = $ContextMenu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An api allowing you to update/rerender components
|
||||||
|
*/
|
||||||
|
export const ComponentUpdater = $ComponentUpdater;
|
||||||
|
|
51
src/plugins/_api/componentUpdater.ts
Normal file
51
src/plugins/_api/componentUpdater.ts
Normal 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
|
||||||
|
});
|
|
@ -16,6 +16,7 @@
|
||||||
* 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 { updateMessageComponent } from "@api/ComponentUpdater";
|
||||||
import { addAccessory } from "@api/MessageAccessories";
|
import { addAccessory } from "@api/MessageAccessories";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import ErrorBoundary from "@components/ErrorBoundary";
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
|
@ -28,7 +29,6 @@ import { find, findByCode, findByPropsLazy } from "@webpack";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
ChannelStore,
|
ChannelStore,
|
||||||
FluxDispatcher,
|
|
||||||
GuildStore,
|
GuildStore,
|
||||||
MessageStore,
|
MessageStore,
|
||||||
Parser,
|
Parser,
|
||||||
|
@ -228,10 +228,7 @@ function MessageEmbedAccessory({ message }: { message: Message; }) {
|
||||||
delete msg.interaction;
|
delete msg.interaction;
|
||||||
|
|
||||||
messageFetchQueue.push(() => fetchMessage(channelID, messageID)
|
messageFetchQueue.push(() => fetchMessage(channelID, messageID)
|
||||||
.then(m => m && FluxDispatcher.dispatch({
|
.then(m => m && updateMessageComponent(message.id))
|
||||||
type: "MESSAGE_UPDATE",
|
|
||||||
message: msg
|
|
||||||
}))
|
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue