From cc07518a34e62844fed57a408a6af1702e628200 Mon Sep 17 00:00:00 2001 From: Nickyux <30734036+nmsturcke@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:29:10 +0100 Subject: [PATCH] VoiceMessages: Support replies (#1565) Co-authored-by: TheKodeToad Co-authored-by: Justice Almanzar Co-authored-by: V Signed-off-by: V --- src/plugins/voiceMessages/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/voiceMessages/index.tsx b/src/plugins/voiceMessages/index.tsx index be5a3f38..b5b9c730 100644 --- a/src/plugins/voiceMessages/index.tsx +++ b/src/plugins/voiceMessages/index.tsx @@ -26,8 +26,8 @@ import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModa import { useAwaiter } from "@utils/react"; import definePlugin from "@utils/types"; import { chooseFile } from "@utils/web"; -import { findLazy } from "@webpack"; -import { Button, Forms, Menu, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common"; +import { findByPropsLazy, findLazy, findStoreLazy } from "@webpack"; +import { Button, FluxDispatcher, Forms, Menu, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common"; import { ComponentType } from "react"; import { VoiceRecorderDesktop } from "./DesktopRecorder"; @@ -37,6 +37,8 @@ import { VoicePreview } from "./VoicePreview"; import { VoiceRecorderWeb } from "./WebRecorder"; const CloudUpload = findLazy(m => m.prototype?.uploadFileToCloud); +const MessageCreator = findByPropsLazy("getSendMessageOptionsForReply", "sendMessage"); +const PendingReplyStore = findStoreLazy("PendingReplyStore"); export type VoiceRecorder = ComponentType<{ setAudioBlob(blob: Blob): void; @@ -48,7 +50,7 @@ const VoiceRecorder = IS_DISCORD_DESKTOP ? VoiceRecorderDesktop : VoiceRecorderW export default definePlugin({ name: "VoiceMessages", description: "Allows you to send voice messages like on mobile. To do so, right click the upload button and click Send Voice Message", - authors: [Devs.Ven, Devs.Vap], + authors: [Devs.Ven, Devs.Vap, Devs.Nickyux], settings, start() { @@ -71,6 +73,8 @@ const EMPTY_META: AudioMetadata = { function sendAudio(blob: Blob, meta: AudioMetadata) { const channelId = SelectedChannelStore.getChannelId(); + const reply = PendingReplyStore.getPendingReply(channelId); + if (reply) FluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId }); const upload = new CloudUpload({ file: new File([blob], "voice-message.ogg", { type: "audio/ogg; codecs=opus" }), @@ -95,7 +99,8 @@ function sendAudio(blob: Blob, meta: AudioMetadata) { uploaded_filename: upload.uploadedFilename, waveform: meta.waveform, duration_secs: meta.duration, - }] + }], + message_reference: reply ? MessageCreator.getSendMessageOptionsForReply(reply)?.messageReference : null, } }); }); @@ -232,4 +237,3 @@ const ctxMenuPatch: NavContextMenuPatchCallback = (children, props) => () => { /> ); }; -