mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-20 10:05:56 +00:00
fix new message send stay bottom
This commit is contained in:
parent
1da9fb161e
commit
dc7e0db0d8
@ -92,21 +92,6 @@ export const MessageQueueProvider = ({ children }) => {
|
||||
|
||||
// Remove the message from the queue after successful sending
|
||||
messageQueueRef.current.shift();
|
||||
// Remove the message from queueChats
|
||||
setQueueChats((prev) => {
|
||||
const updatedChats = { ...prev };
|
||||
if (updatedChats[groupDirectId]) {
|
||||
updatedChats[groupDirectId] = updatedChats[groupDirectId].filter(
|
||||
(item) => item.identifier !== identifier
|
||||
);
|
||||
|
||||
// If no more chats for this group, delete the groupDirectId entry
|
||||
if (updatedChats[groupDirectId].length === 0) {
|
||||
delete updatedChats[groupDirectId];
|
||||
}
|
||||
}
|
||||
return updatedChats;
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Message sending failed', error);
|
||||
@ -142,15 +127,25 @@ export const MessageQueueProvider = ({ children }) => {
|
||||
|
||||
// Method to process with new messages and groupDirectId
|
||||
const processWithNewMessages = (newMessages, groupDirectId) => {
|
||||
let updatedNewMessages = newMessages
|
||||
if (newMessages.length > 0) {
|
||||
messageQueueRef.current = messageQueueRef.current.filter((msg) => {
|
||||
return !newMessages.some(newMsg => newMsg?.specialId === msg?.specialId);
|
||||
});
|
||||
|
||||
// Remove corresponding entries in queueChats for the provided groupDirectId
|
||||
setQueueChats((prev) => {
|
||||
const updatedChats = { ...prev };
|
||||
if (updatedChats[groupDirectId]) {
|
||||
|
||||
updatedNewMessages = newMessages?.map((msg)=> {
|
||||
const findTempMsg = updatedChats[groupDirectId]?.find((msg2)=> msg2?.message?.specialId === msg?.specialId)
|
||||
if(findTempMsg){
|
||||
return {
|
||||
...msg,
|
||||
tempSignature: findTempMsg?.signature
|
||||
}
|
||||
}
|
||||
return msg
|
||||
})
|
||||
|
||||
|
||||
updatedChats[groupDirectId] = updatedChats[groupDirectId].filter((chat) => {
|
||||
return !newMessages.some(newMsg => newMsg?.specialId === chat?.message?.specialId);
|
||||
});
|
||||
@ -167,8 +162,23 @@ export const MessageQueueProvider = ({ children }) => {
|
||||
}
|
||||
return updatedChats;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if(!messageQueueRef.current.find((msg) => msg?.groupDirectId === groupDirectId)){
|
||||
setQueueChats((prev) => {
|
||||
const updatedChats = { ...prev };
|
||||
if (updatedChats[groupDirectId]) {
|
||||
delete updatedChats[groupDirectId]
|
||||
}
|
||||
|
||||
return updatedChats
|
||||
}
|
||||
)
|
||||
}
|
||||
}, 300);
|
||||
|
||||
return updatedNewMessages
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -118,9 +118,9 @@ export const ChatDirect = ({ myAddress, isNewChat, selectedDirect, setSelectedDi
|
||||
data: encryptedMessages,
|
||||
involvingAddress: selectedDirect?.address,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
processWithNewMessages(response, selectedDirect?.address);
|
||||
.then((decryptResponse) => {
|
||||
if (!decryptResponse?.error) {
|
||||
const response = processWithNewMessages(decryptResponse, selectedDirect?.address);
|
||||
res(response);
|
||||
|
||||
if (isInitiated) {
|
||||
|
@ -193,9 +193,9 @@ const [messageSize, setMessageSize] = useState(0)
|
||||
const filterUIMessages = encryptedMessages.filter((item) => !isExtMsg(item.data));
|
||||
const decodedUIMessages = decodeBase64ForUIChatMessages(filterUIMessages);
|
||||
|
||||
const combineUIAndExtensionMsgs = [...decodedUIMessages, ...response];
|
||||
processWithNewMessages(
|
||||
combineUIAndExtensionMsgs.map((item) => ({
|
||||
const combineUIAndExtensionMsgsBefore = [...decodedUIMessages, ...response];
|
||||
const combineUIAndExtensionMsgs = processWithNewMessages(
|
||||
combineUIAndExtensionMsgsBefore.map((item) => ({
|
||||
...item,
|
||||
...(item?.decryptedData || {}),
|
||||
})),
|
||||
|
@ -39,11 +39,10 @@ export const ChatList = ({
|
||||
const scrollingIntervalRef = useRef(null);
|
||||
const lastSeenUnreadMessageTimestamp = useRef(null);
|
||||
|
||||
|
||||
// Initialize the virtualizer
|
||||
const rowVirtualizer = useVirtualizer({
|
||||
count: messages.length,
|
||||
getItemKey: (index) => messages[index].signature,
|
||||
getItemKey: (index) => messages[index]?.tempSignature || messages[index].signature,
|
||||
getScrollElement: () => parentRef?.current,
|
||||
estimateSize: useCallback(() => 80, []), // Provide an estimated height of items, adjust this as needed
|
||||
overscan: 10, // Number of items to render outside the visible area to improve smoothness
|
||||
|
Loading…
x
Reference in New Issue
Block a user