VoiceMessages: Support replies (#1565)

Co-authored-by: TheKodeToad <TheKodeToad@proton.me>
Co-authored-by: Justice Almanzar <superdash993@gmail.com>
Co-authored-by: V <vendicated@riseup.net>
Signed-off-by: V <vendicated@riseup.net>
This commit is contained in:
Nickyux 2023-08-01 04:29:10 +01:00 committed by V
parent ea64b33e24
commit cc07518a34
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -26,8 +26,8 @@ import { ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModa
import { useAwaiter } from "@utils/react"; import { useAwaiter } from "@utils/react";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { chooseFile } from "@utils/web"; import { chooseFile } from "@utils/web";
import { findLazy } from "@webpack"; import { findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
import { Button, Forms, Menu, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common"; import { Button, FluxDispatcher, Forms, Menu, PermissionsBits, PermissionStore, RestAPI, SelectedChannelStore, showToast, SnowflakeUtils, Toasts, useEffect, useState } from "@webpack/common";
import { ComponentType } from "react"; import { ComponentType } from "react";
import { VoiceRecorderDesktop } from "./DesktopRecorder"; import { VoiceRecorderDesktop } from "./DesktopRecorder";
@ -37,6 +37,8 @@ import { VoicePreview } from "./VoicePreview";
import { VoiceRecorderWeb } from "./WebRecorder"; import { VoiceRecorderWeb } from "./WebRecorder";
const CloudUpload = findLazy(m => m.prototype?.uploadFileToCloud); const CloudUpload = findLazy(m => m.prototype?.uploadFileToCloud);
const MessageCreator = findByPropsLazy("getSendMessageOptionsForReply", "sendMessage");
const PendingReplyStore = findStoreLazy("PendingReplyStore");
export type VoiceRecorder = ComponentType<{ export type VoiceRecorder = ComponentType<{
setAudioBlob(blob: Blob): void; setAudioBlob(blob: Blob): void;
@ -48,7 +50,7 @@ const VoiceRecorder = IS_DISCORD_DESKTOP ? VoiceRecorderDesktop : VoiceRecorderW
export default definePlugin({ export default definePlugin({
name: "VoiceMessages", 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", 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, settings,
start() { start() {
@ -71,6 +73,8 @@ const EMPTY_META: AudioMetadata = {
function sendAudio(blob: Blob, meta: AudioMetadata) { function sendAudio(blob: Blob, meta: AudioMetadata) {
const channelId = SelectedChannelStore.getChannelId(); const channelId = SelectedChannelStore.getChannelId();
const reply = PendingReplyStore.getPendingReply(channelId);
if (reply) FluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId });
const upload = new CloudUpload({ const upload = new CloudUpload({
file: new File([blob], "voice-message.ogg", { type: "audio/ogg; codecs=opus" }), 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, uploaded_filename: upload.uploadedFilename,
waveform: meta.waveform, waveform: meta.waveform,
duration_secs: meta.duration, duration_secs: meta.duration,
}] }],
message_reference: reply ? MessageCreator.getSendMessageOptionsForReply(reply)?.messageReference : null,
} }
}); });
}); });
@ -232,4 +237,3 @@ const ctxMenuPatch: NavContextMenuPatchCallback = (children, props) => () => {
/> />
); );
}; };