This commit is contained in:
PhilReact 2024-11-10 17:26:48 +02:00
parent 7a6a07c6e5
commit 622fa1f98e
4 changed files with 21 additions and 14 deletions

View File

@ -11,7 +11,7 @@ let messageQueue = []; // Global message queue
export const MessageQueueProvider = ({ children }) => { export const MessageQueueProvider = ({ children }) => {
const [queueChats, setQueueChats] = useState({}); // Stores chats and status for display const [queueChats, setQueueChats] = useState({}); // Stores chats and status for display
const isProcessingRef = useRef(false); // To track if the queue is being processed const isProcessingRef = useRef(false); // To track if the queue is being processed
const maxRetries = 4; const maxRetries = 2;
const clearStatesMessageQueueProvider = useCallback(() => { const clearStatesMessageQueueProvider = useCallback(() => {
setQueueChats({}); setQueueChats({});
messageQueue = []; messageQueue = [];
@ -43,7 +43,7 @@ export const MessageQueueProvider = ({ children }) => {
]; ];
// Start processing the queue if not already processing // Start processing the queue if not already processing
processQueue(); processQueue([], groupDirectId);
}, []); }, []);
// Method to process with new messages and groupDirectId // Method to process with new messages and groupDirectId
@ -68,6 +68,11 @@ export const MessageQueueProvider = ({ children }) => {
return !newMessages.some(newMsg => newMsg?.specialId === chat?.message?.specialId); return !newMessages.some(newMsg => newMsg?.specialId === chat?.message?.specialId);
}); });
updatedChats[groupDirectId] = updatedChats[groupDirectId].filter((chat) => {
console.log('chatstasu', chat)
return chat?.status !== 'failed-permanent'
});
// If no more chats for this group, delete the groupDirectId entry // If no more chats for this group, delete the groupDirectId entry
if (updatedChats[groupDirectId].length === 0) { if (updatedChats[groupDirectId].length === 0) {
delete updatedChats[groupDirectId]; delete updatedChats[groupDirectId];
@ -102,7 +107,6 @@ export const MessageQueueProvider = ({ children }) => {
try { try {
// Execute the function stored in the messageQueue // Execute the function stored in the messageQueue
await currentMessage.func(); await currentMessage.func();
// Remove the message from the messageQueue after successful sending // Remove the message from the messageQueue after successful sending
messageQueue = messageQueue.slice(1); // Slice here remains for successful messages messageQueue = messageQueue.slice(1); // Slice here remains for successful messages
@ -136,10 +140,10 @@ export const MessageQueueProvider = ({ children }) => {
// Remove the message from the messageQueue after max retries // Remove the message from the messageQueue after max retries
messageQueue = messageQueue.slice(1); // Slice for failed messages after max retries messageQueue = messageQueue.slice(1); // Slice for failed messages after max retries
// Remove the message from queueChats after failure // // Remove the message from queueChats after failure
updatedChats[groupDirectId] = updatedChats[groupDirectId].filter( // updatedChats[groupDirectId] = updatedChats[groupDirectId].filter(
(item) => item.identifier !== identifier // (item) => item.identifier !== identifier
); // );
} }
} }
return updatedChats; return updatedChats;

View File

@ -33,7 +33,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
const uniqueInitialMessages = Array.from(uniqueInitialMessagesMap.values()).sort( const uniqueInitialMessages = Array.from(uniqueInitialMessagesMap.values()).sort(
(a, b) => a.timestamp - b.timestamp (a, b) => a.timestamp - b.timestamp
); );
const totalMessages = [...uniqueInitialMessages, ...(tempMessages || [])]; const totalMessages = [...uniqueInitialMessages, ...(tempMessages || [])]
if (totalMessages.length === 0) return; if (totalMessages.length === 0) return;
@ -151,6 +151,7 @@ export const ChatList = ({ initialMessages, myAddress, tempMessages, chatId, onR
...(message?.message || {}), ...(message?.message || {}),
isTemp: true, isTemp: true,
unread: false, unread: false,
status: message?.status
}; };
} }

View File

@ -37,6 +37,8 @@ export const MessageItem = ({
triggerOnce: false, // Only trigger once when it becomes visible triggerOnce: false, // Only trigger once when it becomes visible
}); });
useEffect(() => { useEffect(() => {
if (inView && isLast && onSeen) { if (inView && isLast && onSeen) {
onSeen(message.id); onSeen(message.id);
@ -262,21 +264,21 @@ export const MessageItem = ({
<Typography <Typography
sx={{ sx={{
fontSize: "14px", fontSize: "14px",
color: "gray", color: "gray",
fontFamily: "Inter", fontFamily: "Inter",
}} }}
> >
Updating... {message?.status === 'failed-permanent' ? 'Failed to update' : 'Updating...'}
</Typography> </Typography>
) : isTemp ? ( ) : isTemp ? (
<Typography <Typography
sx={{ sx={{
fontSize: "14px", fontSize: "14px",
color: "gray", color: "gray",
fontFamily: "Inter", fontFamily: "Inter",
}} }}
> >
Sending... {message?.status === 'failed-permanent' ? 'Failed to send' : 'Sending...'}
</Typography> </Typography>
) : ( ) : (
<Typography <Typography

View File

@ -323,10 +323,10 @@ export default ({
attributes: { attributes: {
class: "tiptap-prosemirror", class: "tiptap-prosemirror",
style: style:
isMobile && isMobile ?
`overflow: auto; min-height: ${ `overflow: auto; min-height: ${
customEditorHeight ? "200px" : "0px" customEditorHeight ? "200px" : "0px"
}; max-height:calc(100svh - ${customEditorHeight || "140px"})`, }; max-height:calc(100svh - ${customEditorHeight || "140px"})`: `overflow: auto; max-height: 250px`,
}, },
handleKeyDown(view, event) { handleKeyDown(view, event) {
if (!disableEnter && event.key === "Enter") { if (!disableEnter && event.key === "Enter") {