Skip to content

Commit d3c76d5

Browse files
committed
fix: sync voice status of thread parent message component
1 parent c91d7fd commit d3c76d5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/uikit-react-native/src/components/ThreadParentMessageRenderer/ThreadParentMessage.file.voice.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type VoiceFileMessageState = {
1616
type Props = ThreadParentMessageRendererProps<{
1717
durationMetaArrayKey?: string;
1818
onUnmount: () => void;
19+
initialCurrentTime?: number;
1920
}>;
2021

2122
const ThreadParentMessageFileVoice = (props: Props) => {
@@ -25,6 +26,7 @@ const ThreadParentMessageFileVoice = (props: Props) => {
2526
parentMessage,
2627
durationMetaArrayKey = 'KEY_VOICE_MESSAGE_DURATION',
2728
onUnmount,
29+
initialCurrentTime,
2830
} = props;
2931

3032
const fileMessage: SendbirdFileMessage = parentMessage as SendbirdFileMessage;
@@ -38,7 +40,7 @@ const ThreadParentMessageFileVoice = (props: Props) => {
3840
const initialDuration = value ? parseInt(value, 10) : 0;
3941
return {
4042
status: 'paused',
41-
currentTime: 0,
43+
currentTime: initialCurrentTime || 0,
4244
duration: initialDuration,
4345
};
4446
});

packages/uikit-react-native/src/components/ThreadParentMessageRenderer/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type ThreadParentMessageRendererProps<AdditionalProps = unknown> = {
3434
const ThreadParentMessageRenderer = (props: ThreadParentMessageRendererProps) => {
3535
const handlers = useSBUHandlers();
3636
const playerUnsubscribes = useRef<(() => void)[]>([]);
37-
const { sbOptions, currentUser, mentionManager } = useSendbirdChat();
37+
const { sbOptions, currentUser, mentionManager, voiceMessageStatusManager } = useSendbirdChat();
3838
const { palette } = useUIKitTheme();
3939
const { mediaService, playerService } = usePlatformService();
4040
const parentMessage = props.parentMessage;
@@ -68,6 +68,11 @@ const ThreadParentMessageRenderer = (props: ThreadParentMessageRendererProps) =>
6868
let seekFinished = !shouldSeekToTime;
6969

7070
const forPlayback = playerService.addPlaybackListener(({ stopped, currentTime, duration }) => {
71+
voiceMessageStatusManager.setCurrentTime(
72+
parentMessage.channelUrl,
73+
parentMessage.messageId,
74+
stopped ? 0 : currentTime,
75+
);
7176
if (seekFinished) {
7277
setState((prevState) => ({ ...prevState, currentTime: stopped ? 0 : currentTime, duration }));
7378
}
@@ -177,6 +182,10 @@ const ThreadParentMessageRenderer = (props: ThreadParentMessageRendererProps) =>
177182
return (
178183
<ThreadParentMessageFileVoice
179184
durationMetaArrayKey={VOICE_MESSAGE_META_ARRAY_DURATION_KEY}
185+
initialCurrentTime={voiceMessageStatusManager.getCurrentTime(
186+
parentMessage.channelUrl,
187+
parentMessage.messageId,
188+
)}
180189
onUnmount={() => {
181190
if (isVoiceMessage(parentMessage) && playerService.uri === parentMessage.url) {
182191
resetPlayer().catch((_) => {});

0 commit comments

Comments
 (0)