2022-03-03 20:23:10 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-03-10 20:36:58 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
2022-09-15 20:10:46 +00:00
|
|
|
import { pick } from 'underscore';
|
2021-03-10 20:36:58 +00:00
|
|
|
|
|
|
|
import { MessageAudio } from '../../components/conversation/MessageAudio';
|
2022-09-15 20:10:46 +00:00
|
|
|
import type { OwnProps as MessageAudioOwnProps } from '../../components/conversation/MessageAudio';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ComputePeaksResult } from '../../components/GlobalAudioContext';
|
2021-03-10 20:36:58 +00:00
|
|
|
|
|
|
|
import { mapDispatchToProps } from '../actions';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
2021-07-09 20:27:16 +00:00
|
|
|
import type {
|
|
|
|
DirectionType,
|
|
|
|
MessageStatusType,
|
|
|
|
} from '../../components/conversation/Message';
|
2022-09-15 20:10:46 +00:00
|
|
|
import type { ActiveAudioPlayerStateType } from '../ducks/audioPlayer';
|
2021-03-10 20:36:58 +00:00
|
|
|
|
|
|
|
export type Props = {
|
2021-06-29 19:58:29 +00:00
|
|
|
renderingContext: string;
|
2021-03-10 20:36:58 +00:00
|
|
|
i18n: LocalizerType;
|
2021-03-16 00:59:48 +00:00
|
|
|
attachment: AttachmentType;
|
2022-03-08 14:32:42 +00:00
|
|
|
collapseMetadata: boolean;
|
2021-03-10 20:36:58 +00:00
|
|
|
withContentAbove: boolean;
|
|
|
|
withContentBelow: boolean;
|
|
|
|
|
2021-07-09 20:27:16 +00:00
|
|
|
direction: DirectionType;
|
|
|
|
expirationLength?: number;
|
|
|
|
expirationTimestamp?: number;
|
|
|
|
id: string;
|
2022-09-15 20:10:46 +00:00
|
|
|
conversationId: string;
|
2021-07-27 15:42:25 +00:00
|
|
|
played: boolean;
|
2021-07-09 20:27:16 +00:00
|
|
|
showMessageDetail: (id: string) => void;
|
|
|
|
status?: MessageStatusType;
|
|
|
|
textPending?: boolean;
|
|
|
|
timestamp: number;
|
|
|
|
|
2021-04-15 21:02:24 +00:00
|
|
|
computePeaks(url: string, barCount: number): Promise<ComputePeaksResult>;
|
2021-03-16 00:59:48 +00:00
|
|
|
kickOffAttachmentDownload(): void;
|
2021-03-22 18:51:53 +00:00
|
|
|
onCorrupted(): void;
|
2021-08-12 18:15:55 +00:00
|
|
|
onFirstPlayed(): void;
|
2021-03-10 20:36:58 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 20:10:46 +00:00
|
|
|
const mapStateToProps = (
|
|
|
|
state: StateType,
|
|
|
|
props: Props
|
|
|
|
): MessageAudioOwnProps => {
|
|
|
|
const { active } = state.audioPlayer;
|
|
|
|
|
|
|
|
const messageActive: ActiveAudioPlayerStateType | undefined =
|
|
|
|
active &&
|
|
|
|
active.id === props.id &&
|
|
|
|
active.context === props.renderingContext
|
|
|
|
? pick(active, 'playing', 'playbackRate', 'currentTime', 'duration')
|
|
|
|
: undefined;
|
2021-03-10 20:36:58 +00:00
|
|
|
return {
|
|
|
|
...props,
|
2022-09-15 20:10:46 +00:00
|
|
|
active: messageActive,
|
2021-03-10 20:36:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
export const SmartMessageAudio = smart(MessageAudio);
|