Skip to content

Fix scrolling in chat view#838

Merged
nickvergessen merged 3 commits into
masterfrom
fix-scrolling-in-chat-view
May 2, 2018
Merged

Fix scrolling in chat view#838
nickvergessen merged 3 commits into
masterfrom
fix-scrolling-in-chat-view

Conversation

@danxuliu

@danxuliu danxuliu commented May 2, 2018

Copy link
Copy Markdown
Member

Follow-up to #564.

This pull request fixes the chat view not scrolling to the new message if the last message was grouped and partially visible. More important, it also fixes the scroll position not being kept when the chat view is switched between the main view and the sidebar.

How to test (chat view not scrolling to new message):

  • Open a conversation and write enough messages to show the scroll bar.
  • Write two messages quickly, so the second one is grouped with the previous one.
  • Scroll so the last message (the grouped one) is slightly visible.
  • Write another message.

Expected result:

  • The chat view automatically scrolls to the new message.

Actual result:

  • The chat view does not scroll.

How to test (scroll position kept when switching the chat view):

  • Open a conversation and write enough messages to show the scroll bar.
  • Scroll back so both the first and last messages are hidden.
  • Join a call.
  • Leave the call.

Expected result:

  • The last message that was partially visible is now the last message fully visible.

Actual result:

  • The chat view is scrolled to the top.

danxuliu added 3 commits May 2, 2018 16:15
When an element has a negative top margin jQuery returns its top
position as the position in where the element would be if it had no
margin. In a similar way, when there is a negative margin the returned
height is not the actual height of the element, but its height without
that margin.

The message list is expected to scroll to the newest message if the last
one is partially visible, but due to the jQuery behaviour the message
list did not scroll when the last message was grouped and less than 20px
(the negative top margin) of the content of that message was visible.
Now the negative margin is taken into account and the message list
always scrolls to the newest message if the last one is partially
visible.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
The scroll area covers the top and bottom padding of an element, but not
its top and bottom margins, so the margins should not be taken into
account in the scroll calculations.

Currently this does not cause any difference in the behaviour, as the
message lists does not have any margin, but it is fixed just in case it
is added in the future.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
When an element is detached and then attached again its scroll position
is reset to the top. Now the chat view provides the "saveScrollPosition"
and "restoreScrollPosition" methods to save the scroll position before
detaching its element and then restoring it when attached again.

Note that the position can not be exactly restored, as the size of the
chat view may have changed due to switching it from the main view to the
sidebar, and thus the visible messages can not be the same in both
cases. Due to this, restoring the scroll position just ensures that the
last message that was partially visible when it was saved will be fully
visible when it is restored.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
@danxuliu danxuliu added this to the 4.0 (Nextcloud 14) milestone May 2, 2018
@danxuliu danxuliu requested review from Ivansss and nickvergessen May 2, 2018 14:27
@nickvergessen

Copy link
Copy Markdown
Member

If I scroll to the top and then join a call, it will scroll almost to the top (first message and second author are missing for me). Seems like some math is not right there

Ah, after reading the code I see, you go by the last comment, not the first

@danxuliu

danxuliu commented May 2, 2018

Copy link
Copy Markdown
Member Author

The acceptance test failure is a false positive. I will fix it in another pull request (as it is not related to this one; it is just a timing issue).

@nickvergessen nickvergessen merged commit c431752 into master May 2, 2018
@nickvergessen nickvergessen deleted the fix-scrolling-in-chat-view branch May 2, 2018 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug feature: chat 💬 Chat and system messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants