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

Commit fce02cc

Browse files
committed
Handle replying with a voice recording.
1 parent 7568433 commit fce02cc

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
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

+57
Original file line numberDiff line numberDiff line change
@@ -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(),
@@ -50,6 +51,7 @@ describe("<VoiceRecordComposerTile/>", () => {
5051

5152
beforeEach(() => {
5253
mockClient = {
54+
getUserId: jest.fn().mockReturnValue("@alice:example.com"),
5355
sendMessage: jest.fn(),
5456
} as unknown as MatrixClient;
5557
MatrixClientPeg.get = () => mockClient;
@@ -127,6 +129,61 @@ describe("<VoiceRecordComposerTile/>", () => {
127129
"org.matrix.msc1767.text": "Voice message",
128130
"org.matrix.msc3245.voice": {},
129131
"url": "mxc://example.com/voice",
132+
"org.matrix.msc3952.mentions": {},
133+
});
134+
});
135+
136+
it("reply with voice recording", async () => {
137+
const room = {
138+
roomId,
139+
} as unknown as Room;
140+
141+
const replyToEvent = mkEvent({
142+
type: "m.room.message",
143+
user: "@bob:test",
144+
room: roomId,
145+
content: {},
146+
event: true,
147+
});
148+
149+
const props = {
150+
room,
151+
ref: voiceRecordComposerTile,
152+
permalinkCreator: new RoomPermalinkCreator(room),
153+
replyToEvent,
154+
};
155+
render(<VoiceRecordComposerTile {...props} />);
156+
157+
await voiceRecordComposerTile.current!.send();
158+
expect(mockClient.sendMessage).toHaveBeenCalledWith(roomId, {
159+
"body": "Voice message",
160+
"file": undefined,
161+
"info": {
162+
duration: 1337000,
163+
mimetype: "audio/ogg",
164+
size: undefined,
165+
},
166+
"msgtype": MsgType.Audio,
167+
"org.matrix.msc1767.audio": {
168+
duration: 1337000,
169+
waveform: [1434, 2560, 3686],
170+
},
171+
"org.matrix.msc1767.file": {
172+
file: undefined,
173+
mimetype: "audio/ogg",
174+
name: "Voice message.ogg",
175+
size: undefined,
176+
url: "mxc://example.com/voice",
177+
},
178+
"org.matrix.msc1767.text": "Voice message",
179+
"org.matrix.msc3245.voice": {},
180+
"url": "mxc://example.com/voice",
181+
"m.relates_to": {
182+
"m.in_reply_to": {
183+
event_id: replyToEvent.getId(),
184+
},
185+
},
186+
"org.matrix.msc3952.mentions": { user_ids: ["@bob:test"] },
130187
});
131188
});
132189
});

0 commit comments

Comments
 (0)