aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-11-08 18:09:11 +0100
committerVendicated <vendicated@riseup.net>2022-11-08 18:09:11 +0100
commit460f329e4f94de1a234908e40b89b6ba4d7efe87 (patch)
tree60d98d4bc7307639aee517e6622b0bfded24bdff
parent3a3a52c4937898bcf674eb936651225d6c3df969 (diff)
downloadVencord-460f329e4f94de1a234908e40b89b6ba4d7efe87.tar.gz
Vencord-460f329e4f94de1a234908e40b89b6ba4d7efe87.tar.bz2
Vencord-460f329e4f94de1a234908e40b89b6ba4d7efe87.zip
fix double click actions using outdated content
-rw-r--r--src/api/MessageEvents.ts19
-rw-r--r--src/webpack/common.tsx1
2 files changed, 15 insertions, 5 deletions
diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts
index 8411c9a..ea2dfd6 100644
--- a/src/api/MessageEvents.ts
+++ b/src/api/MessageEvents.ts
@@ -16,9 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type { Channel,Message } from "discord-types/general";
+import type { Channel, Message } from "discord-types/general";
import Logger from "../utils/logger";
+import { MessageStore } from "../webpack/common";
const MessageEventsLogger = new Logger("MessageEvents", "#e5c890");
@@ -41,7 +42,7 @@ export interface MessageExtra {
stickerIds?: string[];
}
-export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => void | { cancel: boolean };
+export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => void | { cancel: boolean; };
export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => void;
const sendListeners = new Set<SendListener>();
@@ -54,7 +55,9 @@ export function _handlePreSend(channelId: string, messageObj: MessageObject, ext
if (result && result.cancel === true) {
return true;
}
- } catch (e) { MessageEventsLogger.error("MessageSendHandler: Listener encountered an unknown error\n", e); }
+ } catch (e) {
+ MessageEventsLogger.error("MessageSendHandler: Listener encountered an unknown error\n", e);
+ }
}
return false;
}
@@ -63,7 +66,9 @@ export function _handlePreEdit(channelId: string, messageId: string, messageObj:
for (const listener of editListeners) {
try {
listener(channelId, messageId, messageObj);
- } catch (e) { MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e); }
+ } catch (e) {
+ MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e);
+ }
}
}
@@ -95,10 +100,14 @@ type ClickListener = (message: Message, channel: Channel, event: MouseEvent) =>
const listeners = new Set<ClickListener>();
export function _handleClick(message: Message, channel: Channel, event: MouseEvent) {
+ // message object may be outdated, so (try to) fetch latest one
+ message = MessageStore.getMessage(channel.id, message.id) ?? message;
for (const listener of listeners) {
try {
listener(message, channel, event);
- } catch (e) { MessageEventsLogger.error("MessageClickHandler: Listener encountered an unknown error\n", e); }
+ } catch (e) {
+ MessageEventsLogger.error("MessageClickHandler: Listener encountered an unknown error\n", e);
+ }
}
}
diff --git a/src/webpack/common.tsx b/src/webpack/common.tsx
index 73ead1c..b5c2c2f 100644
--- a/src/webpack/common.tsx
+++ b/src/webpack/common.tsx
@@ -32,6 +32,7 @@ export const Flux = lazyWebpack(filters.byProps("connectStores"));
export let React: typeof import("react");
export const ReactDOM: typeof import("react-dom") = lazyWebpack(filters.byProps("createPortal", "render"));
+export const MessageStore = lazyWebpack(filters.byProps("getRawMessages")) as Stores.MessageStore;
export let GuildStore: Stores.GuildStore;
export let UserStore: Stores.UserStore;
export let SelectedChannelStore: Stores.SelectedChannelStore;