@@ -576,6 +576,13 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
576576 ] ) ;
577577
578578 useEffect ( ( ) => {
579+ /**
580+ * Condition to check if a message is removed from MessageList.
581+ * Eg: This would happen when giphy search is cancelled, message is deleted with visibility "never" etc.
582+ * If such a case arises, we scroll to bottom.
583+ */
584+ const isMessageRemovedFromMessageList =
585+ messageListLengthAfterUpdate < messageListLengthBeforeUpdate . current ;
579586 /**
580587 * Scroll down when
581588 * created_at timestamp of top message before update is lesser than created_at timestamp of top message after update - channel has resynced
@@ -585,18 +592,10 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
585592 return ;
586593 }
587594
588- /**
589- * Condition to check if a message is removed from MessageList.
590- * Eg: This would happen when giphy search is cancelled, etc.
591- * If such a case arises, we scroll to bottom.
592- */
593- const isMessageRemovedFromMessageList =
594- messageListLengthAfterUpdate < messageListLengthBeforeUpdate . current ;
595595 if (
596- isMessageRemovedFromMessageList ||
597- ( topMessageBeforeUpdate . current ?. created_at &&
598- topMessageAfterUpdate ?. created_at &&
599- topMessageBeforeUpdate . current . created_at < topMessageAfterUpdate . created_at )
596+ topMessageBeforeUpdate . current ?. created_at &&
597+ topMessageAfterUpdate ?. created_at &&
598+ topMessageBeforeUpdate . current . created_at < topMessageAfterUpdate . created_at
600599 ) {
601600 channelResyncScrollSet . current = false ;
602601 setScrollToBottomButtonVisible ( false ) ;
@@ -616,8 +615,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
616615 }
617616 } ;
618617
619- // TODO: Think about if this is really needed?
620- if ( threadList ) {
618+ if ( threadList || isMessageRemovedFromMessageList ) {
621619 scrollToBottomIfNeeded ( ) ;
622620 }
623621
0 commit comments