Skip to content

Commit 9dee3eb

Browse files
authored
Merge pull request matrix-org#6728 from matrix-org/travis/voice-messages/interrupt-text
Stop automatic playback of voice messages if a non-voice message is encountered
2 parents 60e2d61 + b2cb944 commit 9dee3eb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/audio/PlaybackQueue.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { arrayFastClone } from "../utils/arrays";
2222
import { PlaybackManager } from "./PlaybackManager";
2323
import { isVoiceMessage } from "../utils/EventUtils";
2424
import RoomViewStore from "../stores/RoomViewStore";
25+
import { EventType } from "matrix-js-sdk/src/@types/event";
2526

2627
/**
2728
* Audio playback queue management for a given room. This keeps track of where the user
@@ -137,13 +138,17 @@ export class PlaybackQueue {
137138
}
138139
if (!scanForVoiceMessage) continue;
139140

140-
// Dev note: This is where we'd break to cause text/non-voice messages to
141-
// interrupt automatic playback.
141+
if (!isVoiceMessage(event)) {
142+
const evType = event.getType();
143+
if (evType !== EventType.RoomMessage && evType !== EventType.Sticker) {
144+
continue; // Event can be skipped for automatic playback consideration
145+
}
146+
break; // Stop automatic playback: next useful event is not a voice message
147+
}
142148

143-
const isRightType = isVoiceMessage(event);
144149
const havePlayback = this.playbacks.has(event.getId());
145150
const isRecentlyCompleted = this.recentFullPlays.has(event.getId());
146-
if (isRightType && havePlayback && !isRecentlyCompleted) {
151+
if (havePlayback && !isRecentlyCompleted) {
147152
nextEv = event;
148153
break;
149154
}

0 commit comments

Comments
 (0)