I implemented auto-scrolling without the need for an additional thread or listener. Since we only really care about scrolling back down if we're receiving messages, we only want to scroll down to the bottom after 10 seconds while receiving messages. So when we check if we should maybeScrollDown and decide we're not at the bottom, we start the timeout. Then, every time we do that same check:
If we're at the bottom, reset the "timer"
If we're still not at the bottom, check the timer. If difference >= 10s, reset and scroll to bottom
If timer doesn't exist, initialize it to current time
There are drawbacks to this, because it required people to be chatting (or some other calls to maybeScrollToBottom), but this is a case that will not appear often and also matter. If no one is chatting, there's no need to scroll down anyway. The benefits of not adding another thread or listener outweigh these drawbacks.
I implemented auto-scrolling without the need for an additional thread or listener. Since we only really care about scrolling back down if we're receiving messages, we only want to scroll down to the bottom after 10 seconds while receiving messages. So when we check if we should
maybeScrollDown
and decide we're not at the bottom, we start the timeout. Then, every time we do that same check:There are drawbacks to this, because it required people to be chatting (or some other calls to
maybeScrollToBottom
), but this is a case that will not appear often and also matter. If no one is chatting, there's no need to scroll down anyway. The benefits of not adding another thread or listener outweigh these drawbacks.