Message List: Follow-up fixes for unread messages

This commit is contained in:
Alexander Zinchuk 2021-08-16 21:22:14 +03:00
parent ec590b5118
commit 01984328d7
3 changed files with 11 additions and 5 deletions

View File

@ -140,10 +140,8 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
const anchorIdRef = useRef<string>();
const anchorTopRef = useRef<number>();
const listItemElementsRef = useRef<HTMLDivElement[]>();
// Not updated (as we want the unread divider to keep its position)
const memoUnreadDividerBeforeIdRef = useRef<number | undefined>(firstUnreadId);
// Updated every time (to be used from intersection callback closure)
const memoFirstUnreadIdRef = useRef<number>();
const memoUnreadDividerBeforeIdRef = useRef<number | undefined>();
const memoFocusingIdRef = useRef<number>();
const isScrollTopJustUpdatedRef = useRef(false);
const shouldAnimateAppearanceRef = useRef(Boolean(lastMessage));
@ -161,10 +159,18 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
}
}, [areMessagesLoaded]);
// Updated every time (to be used from intersection callback closure)
useOnChange(() => {
memoFirstUnreadIdRef.current = firstUnreadId;
}, [firstUnreadId]);
// Updated only once when messages are loaded (as we want the unread divider to keep its position)
useOnChange(() => {
if (areMessagesLoaded) {
memoUnreadDividerBeforeIdRef.current = memoFirstUnreadIdRef.current;
}
}, [areMessagesLoaded]);
useOnChange(() => {
memoFocusingIdRef.current = focusingId;
}, [focusingId]);

View File

@ -57,7 +57,7 @@ import { IS_IOS } from '../../../util/environment';
const uploadProgressCallbacks = new Map<number, ApiOnProgress>();
const runDebouncedForMarkRead = debounce((cb) => cb(), 1000, false);
const runDebouncedForMarkRead = debounce((cb) => cb(), 500, false);
addReducer('loadViewportMessages', (global, actions, payload) => {
const {

View File

@ -26,7 +26,7 @@ import { throttle } from '../../../util/schedulers';
const TYPING_STATUS_CLEAR_DELAY = 6000; // 6 seconds
// Enough to animate and mark as read in Message List
const CURRENT_CHAT_UNREAD_DELAY = 1000;
const CURRENT_CHAT_UNREAD_DELAY = 1500;
const runThrottledForUpdateAppBadge = throttle((cb) => cb(), CURRENT_CHAT_UNREAD_DELAY, true);
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {