Minor tidying.

pull/1718/head
Warrick Corfe-Tan 4 years ago
parent d35f3f9e62
commit 856ced056a

@ -11,9 +11,8 @@ export const AudioPlayerWithEncryptedFile = (props: {
src: string; src: string;
contentType: string; contentType: string;
playbackSpeed: number; playbackSpeed: number;
changeTestList?: any; playNextMessage?: (index: number) => void;
shouldPlay?: boolean playableMessageIndex?: number
index?: number
nextMessageToPlay?: number nextMessageToPlay?: number
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@ -29,14 +28,20 @@ export const AudioPlayerWithEncryptedFile = (props: {
}, [playbackSpeed]); }, [playbackSpeed]);
useEffect(() => { useEffect(() => {
if (props.index == props.nextMessageToPlay) { if (props.playableMessageIndex == props.nextMessageToPlay) {
player.current?.audio.current?.play(); player.current?.audio.current?.play();
} }
}) })
const onEnded = () => { const onEnded = () => {
if (window.inboxStore?.getState().userConfig.audioAutoplay === true) { // if audio autoplay is enabled, call method to start playing
props.changeTestList(props.index); // the next playable message
if (
window.inboxStore?.getState().userConfig.audioAutoplay === true &&
props.playNextMessage &&
props.playableMessageIndex
) {
props.playNextMessage(props.playableMessageIndex);
} }
} }

@ -202,9 +202,8 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
playbackSpeed={this.state.playbackSpeed} playbackSpeed={this.state.playbackSpeed}
src={firstAttachment.url} src={firstAttachment.url}
contentType={firstAttachment.contentType} contentType={firstAttachment.contentType}
changeTestList={this.props.changeTestList} playNextMessage={this.props.playNextMessage}
shouldPlay={this.props.shouldPlay} playableMessageIndex={this.props.playableMessageIndex}
index={this.props.index}
nextMessageToPlay={this.props.nextMessageToPlay} nextMessageToPlay={this.props.nextMessageToPlay}
/> />
</div> </div>

@ -273,7 +273,11 @@ export class SessionMessagesList extends React.Component<Props, State> {
return; return;
} }
const changeTestList = (index: any) => { /**
* Sets the targeted index for the next
* @param index index of message that just completed
*/
const playNextMessage = (index: any) => {
index--; index--;
if (messages[index]) { if (messages[index]) {
this.setState({ this.setState({
@ -284,8 +288,8 @@ export class SessionMessagesList extends React.Component<Props, State> {
if (messageProps) { if (messageProps) {
messageProps.nextMessageToPlay = this.state.nextMessageToPlay messageProps.nextMessageToPlay = this.state.nextMessageToPlay
messageProps.index = playableMessageIndex; messageProps.playableMessageIndex = playableMessageIndex;
messageProps.changeTestList = changeTestList; messageProps.playNextMessage = playNextMessage;
} }
playableMessageIndex++; playableMessageIndex++;

@ -253,8 +253,7 @@ export interface MessageRegularProps {
markRead: (readAt: number) => Promise<void>; markRead: (readAt: number) => Promise<void>;
theme: DefaultTheme; theme: DefaultTheme;
shouldPlay?: boolean; playableMessageIndex?: number;
index?: number;
nextMessageToPlay?: number; nextMessageToPlay?: number;
changeTestList: (value: any) => any; playNextMessage?: (value: number) => any;
} }

Loading…
Cancel
Save