Avoid repeated scollToMessage actions

This commit is contained in:
trevor-signal 2024-03-18 12:22:06 -04:00 committed by GitHub
parent 11ea595457
commit d2d2a230b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,7 +45,7 @@ export const SmartChatsTab = memo(function SmartChatsTab() {
const hasPendingUpdate = useSelector(getHasPendingUpdate);
const otherTabsUnreadStats = useSelector(getOtherTabsUnreadStats);
const selectedConversationId = useSelector(getSelectedConversationId);
const targetedMessage = useSelector(getTargetedMessage);
const targetedMessageId = useSelector(getTargetedMessage)?.id;
const targetedMessageSource = useSelector(getTargetedMessageSource);
const {
@ -64,16 +64,16 @@ export const SmartChatsTab = memo(function SmartChatsTab() {
if (selectedConversationId !== lastOpenedConversationId.current) {
lastOpenedConversationId.current = selectedConversationId;
if (selectedConversationId) {
onConversationOpened(selectedConversationId, targetedMessage?.id);
onConversationOpened(selectedConversationId, targetedMessageId);
}
} else if (
selectedConversationId &&
targetedMessage &&
targetedMessageId &&
targetedMessageSource !== TargetedMessageSource.Focus
) {
scrollToMessage(selectedConversationId, targetedMessage?.id);
scrollToMessage(selectedConversationId, targetedMessageId);
}
}, [onConversationOpened, selectedConversationId, scrollToMessage, targetedMessage, targetedMessageSource]);
}, [onConversationOpened, selectedConversationId, scrollToMessage, targetedMessageId, targetedMessageSource]);
const prevConversationId = usePrevious(
selectedConversationId,