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

Commit 33ddfee

Browse files
committed
Handle replying with a voice recording.
1 parent a44d293 commit 33ddfee

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Diff for: src/components/views/rooms/VoiceRecordComposerTile.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import InlineSpinner from "../elements/InlineSpinner";
3939
import { PlaybackManager } from "../../../audio/PlaybackManager";
4040
import { doMaybeLocalRoomAction } from "../../../utils/local-room";
4141
import defaultDispatcher from "../../../dispatcher/dispatcher";
42-
import { attachRelation } from "./SendMessageComposer";
42+
import { attachMentions, attachRelation } from "./SendMessageComposer";
4343
import { addReplyToMessageContent } from "../../../utils/Reply";
4444
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
4545
import RoomContext from "../../../contexts/RoomContext";
@@ -129,7 +129,8 @@ export default class VoiceRecordComposerTile extends React.PureComponent<IProps,
129129
this.state.recorder.getPlayback().thumbnailWaveform.map((v) => Math.round(v * 1024)),
130130
);
131131

132-
// TODO Do we need to attachMentions?
132+
// Attach mentions, which really only applies if there's a replyToEvent.
133+
attachMentions(MatrixClientPeg.get().getUserId()!, content, null, replyToEvent);
133134
attachRelation(content, relation);
134135
if (replyToEvent) {
135136
addReplyToMessageContent(content, replyToEvent, {

Diff for: test/components/views/rooms/VoiceRecordComposerTile-test.tsx

+43-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

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

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

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

5153
beforeEach(() => {
5254
mockClient = {
55+
getUserId: jest.fn().mockReturnValue("@alice:example.com"),
5356
sendMessage: jest.fn(),
5457
} as unknown as MatrixClient;
5558
MatrixClientPeg.get = () => mockClient;
@@ -63,6 +66,7 @@ describe("<VoiceRecordComposerTile/>", () => {
6366
room,
6467
ref: voiceRecordComposerTile,
6568
permalinkCreator: new RoomPermalinkCreator(room),
69+
replyToEvent,
6670
};
6771
mockUpload = {
6872
mxc: "mxc://example.com/voice",
@@ -127,6 +131,44 @@ describe("<VoiceRecordComposerTile/>", () => {
127131
"org.matrix.msc1767.text": "Voice message",
128132
"org.matrix.msc3245.voice": {},
129133
"url": "mxc://example.com/voice",
134+
"org.matrix.msc3952.mentions": {},
135+
});
136+
});
137+
138+
it("reply with voice recording", async () => {
139+
replyToEvent = mkEvent({
140+
type: "m.room.message",
141+
user: "@bob:test",
142+
room: roomId,
143+
content: {},
144+
event: true,
145+
});
146+
147+
await voiceRecordComposerTile.current!.send();
148+
expect(mockClient.sendMessage).toHaveBeenCalledWith(roomId, {
149+
"body": "Voice message",
150+
"file": undefined,
151+
"info": {
152+
duration: 1337000,
153+
mimetype: "audio/ogg",
154+
size: undefined,
155+
},
156+
"msgtype": MsgType.Audio,
157+
"org.matrix.msc1767.audio": {
158+
duration: 1337000,
159+
waveform: [1434, 2560, 3686],
160+
},
161+
"org.matrix.msc1767.file": {
162+
file: undefined,
163+
mimetype: "audio/ogg",
164+
name: "Voice message.ogg",
165+
size: undefined,
166+
url: "mxc://example.com/voice",
167+
},
168+
"org.matrix.msc1767.text": "Voice message",
169+
"org.matrix.msc3245.voice": {},
170+
"url": "mxc://example.com/voice",
171+
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
130172
});
131173
});
132174
});

0 commit comments

Comments
 (0)