change remove duplicate msgs

This commit is contained in:
PhilReact 2024-10-24 04:27:17 +03:00
parent 5433cf8e41
commit 5476ee3269
3 changed files with 15 additions and 19 deletions

View File

@ -149,7 +149,7 @@ const defaultValues: MyContextInterface = {
message: "", message: "",
}, },
}; };
export let isMobile = true; export let isMobile = false;
const isMobileDevice = () => { const isMobileDevice = () => {
const userAgent = navigator.userAgent || navigator.vendor || window.opera; const userAgent = navigator.userAgent || navigator.vendor || window.opera;

View File

@ -255,7 +255,7 @@ export const AnnouncementDiscussion = ({
return ( return (
<div <div
style={{ style={{
height: isMobile ? '100%' : "100vh", height: isMobile ? '100%' : "100%",
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
width: "100%", width: "100%",

View File

@ -10,11 +10,15 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
const hasLoadedInitialRef = useRef(false); const hasLoadedInitialRef = useRef(false);
const isAtBottomRef = useRef(true); // const isAtBottomRef = useRef(true); //
// Update message list with unique signatures and tempMessages // Update message list with unique signatures and tempMessages
useEffect(() => { useEffect(() => {
let uniqueInitialMessagesMap = new Map(); let uniqueInitialMessagesMap = new Map();
// Only add a message if it doesn't already exist in the Map
initialMessages.forEach((message) => { initialMessages.forEach((message) => {
if (!uniqueInitialMessagesMap.has(message.signature)) {
uniqueInitialMessagesMap.set(message.signature, message); uniqueInitialMessagesMap.set(message.signature, message);
}
}); });
const uniqueInitialMessages = Array.from(uniqueInitialMessagesMap.values()).sort( const uniqueInitialMessages = Array.from(uniqueInitialMessagesMap.values()).sort(
@ -30,20 +34,11 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
const hasUnreadMessages = totalMessages.some((msg) => msg.unread && !msg?.chatReference); const hasUnreadMessages = totalMessages.some((msg) => msg.unread && !msg?.chatReference);
if (virtuosoRef.current) { if (virtuosoRef.current) {
if (virtuosoRef.current && !isAtBottomRef.current && hasUnreadMessages) { if (virtuosoRef.current && !isAtBottomRef.current && hasUnreadMessages) {
setShowScrollButton(hasUnreadMessages); setShowScrollButton(hasUnreadMessages);
} else { } else {
handleMessageSeen(); handleMessageSeen();
} }
} }
if (!hasLoadedInitialRef.current) { if (!hasLoadedInitialRef.current) {
scrollToBottom(totalMessages); scrollToBottom(totalMessages);
@ -54,6 +49,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
const handleMessageSeen = useCallback(() => { const handleMessageSeen = useCallback(() => {
setMessages((prevMessages) => setMessages((prevMessages) =>
prevMessages.map((msg) => ({ prevMessages.map((msg) => ({