Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Handle replying with a voice recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Mar 8, 2023
1 parent a44d293 commit 33ddfee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/views/rooms/VoiceRecordComposerTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import InlineSpinner from "../elements/InlineSpinner";
import { PlaybackManager } from "../../../audio/PlaybackManager";
import { doMaybeLocalRoomAction } from "../../../utils/local-room";
import defaultDispatcher from "../../../dispatcher/dispatcher";
import { attachRelation } from "./SendMessageComposer";
import { attachMentions, attachRelation } from "./SendMessageComposer";
import { addReplyToMessageContent } from "../../../utils/Reply";
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
import RoomContext from "../../../contexts/RoomContext";
Expand Down Expand Up @@ -129,7 +129,8 @@ export default class VoiceRecordComposerTile extends React.PureComponent<IProps,
this.state.recorder.getPlayback().thumbnailWaveform.map((v) => Math.round(v * 1024)),
);

// TODO Do we need to attachMentions?
// Attach mentions, which really only applies if there's a replyToEvent.
attachMentions(MatrixClientPeg.get().getUserId()!, content, null, replyToEvent);
attachRelation(content, relation);
if (replyToEvent) {
addReplyToMessageContent(content, replyToEvent, {
Expand Down
44 changes: 43 additions & 1 deletion test/components/views/rooms/VoiceRecordComposerTile-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import React, { createRef, RefObject } from "react";
import { render } from "@testing-library/react";
import { MatrixClient, MsgType, Room } from "matrix-js-sdk/src/matrix";
import { MatrixClient, MatrixEvent, MsgType, Room } from "matrix-js-sdk/src/matrix";
import { mocked } from "jest-mock";

import VoiceRecordComposerTile from "../../../../src/components/views/rooms/VoiceRecordComposerTile";
Expand All @@ -26,6 +26,7 @@ import { IUpload, VoiceMessageRecording } from "../../../../src/audio/VoiceMessa
import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks";
import { VoiceRecordingStore } from "../../../../src/stores/VoiceRecordingStore";
import { PlaybackClock } from "../../../../src/audio/PlaybackClock";
import { mkEvent } from "../../../test-utils";

jest.mock("../../../../src/utils/local-room", () => ({
doMaybeLocalRoomAction: jest.fn(),
Expand All @@ -46,10 +47,12 @@ describe("<VoiceRecordComposerTile/>", () => {
let mockRecorder: VoiceMessageRecording;
let mockUpload: IUpload;
let mockClient: MatrixClient;
let replyToEvent: MatrixEvent | null = null;
const roomId = "!room:example.com";

beforeEach(() => {
mockClient = {
getUserId: jest.fn().mockReturnValue("@alice:example.com"),
sendMessage: jest.fn(),
} as unknown as MatrixClient;
MatrixClientPeg.get = () => mockClient;
Expand All @@ -63,6 +66,7 @@ describe("<VoiceRecordComposerTile/>", () => {
room,
ref: voiceRecordComposerTile,
permalinkCreator: new RoomPermalinkCreator(room),
replyToEvent,
};
mockUpload = {
mxc: "mxc://example.com/voice",
Expand Down Expand Up @@ -127,6 +131,44 @@ describe("<VoiceRecordComposerTile/>", () => {
"org.matrix.msc1767.text": "Voice message",
"org.matrix.msc3245.voice": {},
"url": "mxc://example.com/voice",
"org.matrix.msc3952.mentions": {},
});
});

it("reply with voice recording", async () => {
replyToEvent = mkEvent({
type: "m.room.message",
user: "@bob:test",
room: roomId,
content: {},
event: true,
});

await voiceRecordComposerTile.current!.send();
expect(mockClient.sendMessage).toHaveBeenCalledWith(roomId, {
"body": "Voice message",
"file": undefined,
"info": {
duration: 1337000,
mimetype: "audio/ogg",
size: undefined,
},
"msgtype": MsgType.Audio,
"org.matrix.msc1767.audio": {
duration: 1337000,
waveform: [1434, 2560, 3686],
},
"org.matrix.msc1767.file": {
file: undefined,
mimetype: "audio/ogg",
name: "Voice message.ogg",
size: undefined,
url: "mxc://example.com/voice",
},
"org.matrix.msc1767.text": "Voice message",
"org.matrix.msc3245.voice": {},
"url": "mxc://example.com/voice",
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
});
});
});
Expand Down

0 comments on commit 33ddfee

Please sign in to comment.