Minor tidying.

This commit is contained in:
Warrick Corfe-Tan 2021-06-24 14:00:07 +10:00
parent d35f3f9e62
commit 856ced056a
4 changed files with 22 additions and 15 deletions

View file

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

View file

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

View file

@ -273,7 +273,11 @@ export class SessionMessagesList extends React.Component<Props, State> {
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--;
if (messages[index]) {
this.setState({
@ -284,8 +288,8 @@ export class SessionMessagesList extends React.Component<Props, State> {
if (messageProps) {
messageProps.nextMessageToPlay = this.state.nextMessageToPlay
messageProps.index = playableMessageIndex;
messageProps.changeTestList = changeTestList;
messageProps.playableMessageIndex = playableMessageIndex;
messageProps.playNextMessage = playNextMessage;
}
playableMessageIndex++;

View file

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