diff --git a/frontend/components/chat/MessageBubble.jsx b/frontend/components/chat/MessageBubble.jsx index 32203be..7b3f47d 100644 --- a/frontend/components/chat/MessageBubble.jsx +++ b/frontend/components/chat/MessageBubble.jsx @@ -1,7 +1,8 @@ import { Check, CheckCheck, Pin, Languages} from "lucide-react" import Avatar from "./Avatar" -import { useState } from "react" +import { useState, useEffect, useRef } from "react" import ReplyPreview from "./ReplyPreview" +import useChatStore from "../../src/store/useChatStore" const formatTime = (d) => new Date(d).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) @@ -10,9 +11,18 @@ const formatTime = (d) => export default function MessageBubble({ msg, isMine, showTime, selectedUser, isOnline, authUser, onContextMenu, onTouchStart, onTouchEnd, onReact }) { const [showTranslation, setShowTranslation] = useState(false) - const [selectedImage, setSelectedImage] = useState(null) const [isSelected, setIsSelected] = useState(false) + const activeAudioId = useChatStore((state) => state.activeAudioId) + const setActiveAudioId = useChatStore((state) => state.setActiveAudioId) + const audioRef = useRef(null) + + useEffect(() => { + if (activeAudioId && activeAudioId !== msg._id && audioRef.current) { + audioRef.current.pause() + } + }, [activeAudioId, msg._id]) + const getTranslatedText = (text) => { const translations = { hello: "hola", @@ -93,7 +103,7 @@ export default function MessageBubble({ msg, isMine, showTime, selectedUser, isO src={msg.image} alt="attachment" className="max-w-full rounded-lg mb-1 cursor-pointer hover:opacity-90 transition" - onClick={() => setSelectedImage(msg.image)} + onClick={() => window.open(msg.image, "_blank")} /> )} @@ -105,9 +115,21 @@ export default function MessageBubble({ msg, isMine, showTime, selectedUser, isO