Comment Threads: Various fixes
This commit is contained in:
parent
d5db8639eb
commit
954ee5c508
@ -732,6 +732,7 @@ export async function requestThreadInfoUpdate({
|
||||
'@type': 'updateChat',
|
||||
id: newChat.id,
|
||||
chat: newChat,
|
||||
noTopChatsRequest: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -61,6 +61,7 @@ export type ApiUpdateChat = {
|
||||
id: number;
|
||||
chat: Partial<ApiChat>;
|
||||
newProfilePhoto?: ApiPhoto;
|
||||
noTopChatsRequest?: boolean;
|
||||
};
|
||||
|
||||
export type ApiUpdateChatJoin = {
|
||||
|
||||
@ -149,8 +149,7 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
const anchorIdRef = useRef<string>();
|
||||
const anchorTopRef = useRef<number>();
|
||||
const listItemElementsRef = useRef<HTMLDivElement[]>();
|
||||
// Updated when opening chat (to preserve divider even after messages are read)
|
||||
const memoUnreadDividerBeforeIdRef = useRef<number | undefined>(firstUnreadId);
|
||||
const memoUnreadDividerBeforeIdRef = useRef<number | undefined>();
|
||||
// Updated every time (to be used from intersection callback closure)
|
||||
const memoFirstUnreadIdRef = useRef<number>();
|
||||
const memoFocusingIdRef = useRef<number>();
|
||||
@ -172,6 +171,11 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
|
||||
useOnChange(() => {
|
||||
memoFirstUnreadIdRef.current = firstUnreadId;
|
||||
|
||||
// Updated only once (to preserve divider even after messages are read)
|
||||
if (!memoUnreadDividerBeforeIdRef.current) {
|
||||
memoUnreadDividerBeforeIdRef.current = firstUnreadId;
|
||||
}
|
||||
}, [firstUnreadId]);
|
||||
|
||||
const {
|
||||
|
||||
@ -330,7 +330,11 @@ export default memo(withGlobal(
|
||||
canPost: !isPinnedMessageList && (!chat || canPost) && (!isBotNotStarted || IS_MOBILE_SCREEN),
|
||||
isPinnedMessageList,
|
||||
messageSendingRestrictionReason: chat && getMessageSendingRestrictionReason(chat),
|
||||
hasPinnedOrAudioMessage: Boolean(pinnedIds && pinnedIds.length) || Boolean(audioChatId && audioMessageId),
|
||||
hasPinnedOrAudioMessage: (
|
||||
threadId !== MAIN_THREAD_ID
|
||||
|| Boolean(pinnedIds && pinnedIds.length)
|
||||
|| Boolean(audioChatId && audioMessageId)
|
||||
),
|
||||
customBackground,
|
||||
patternColor,
|
||||
isCustomBackgroundColor,
|
||||
|
||||
@ -50,11 +50,13 @@ import {
|
||||
selectScheduledMessage,
|
||||
selectNoWebPage,
|
||||
} from '../../selectors';
|
||||
import { rafPromise } from '../../../util/schedulers';
|
||||
import { rafPromise, throttle } from '../../../util/schedulers';
|
||||
import { copyTextToClipboard } from '../../../util/clipboard';
|
||||
|
||||
const uploadProgressCallbacks = new Map<number, ApiOnProgress>();
|
||||
|
||||
const runThrottledForMarkRead = throttle((cb) => cb(), 1000, true);
|
||||
|
||||
addReducer('loadViewportMessages', (global, actions, payload) => {
|
||||
const {
|
||||
direction = LoadMoreDirection.Around,
|
||||
@ -409,7 +411,9 @@ addReducer('markMessageListRead', (global, actions, payload) => {
|
||||
|
||||
const { maxId } = payload!;
|
||||
|
||||
void callApi('markMessageListRead', { chat, threadId, maxId });
|
||||
runThrottledForMarkRead(() => {
|
||||
void callApi('markMessageListRead', { chat, threadId, maxId });
|
||||
});
|
||||
});
|
||||
|
||||
addReducer('markMessagesRead', (global, actions, payload) => {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { addReducer, getGlobal, setGlobal } from '../../../lib/teact/teactn';
|
||||
|
||||
import { ApiUpdate } from '../../../api/types';
|
||||
import { ApiUpdate, MAIN_THREAD_ID } from '../../../api/types';
|
||||
|
||||
import { ARCHIVED_FOLDER_ID, MAX_ACTIVE_PINNED_CHATS } from '../../../config';
|
||||
import { pick } from '../../../util/iteratees';
|
||||
@ -27,7 +27,7 @@ const CURRENT_CHAT_UNREAD_DELAY = 1000;
|
||||
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
switch (update['@type']) {
|
||||
case 'updateChat': {
|
||||
if (!selectIsChatListed(global, update.id)) {
|
||||
if (!update.noTopChatsRequest && !selectIsChatListed(global, update.id)) {
|
||||
// Chat can appear in dialogs list.
|
||||
actions.loadTopChats();
|
||||
}
|
||||
@ -95,7 +95,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
|
||||
case 'newMessage': {
|
||||
const { message } = update;
|
||||
const { chatId: currentChatId } = selectCurrentMessageList(global) || {};
|
||||
const { chatId: currentChatId, threadId, type: messageListType } = selectCurrentMessageList(global) || {};
|
||||
|
||||
if (message.senderId === global.currentUserId && !message.isFromScheduled) {
|
||||
return;
|
||||
@ -106,7 +106,11 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const isActiveChat = update.chatId === currentChatId;
|
||||
const isActiveChat = (
|
||||
messageListType === 'thread'
|
||||
&& threadId === MAIN_THREAD_ID
|
||||
&& update.chatId === currentChatId
|
||||
);
|
||||
|
||||
if (isActiveChat) {
|
||||
setTimeout(() => {
|
||||
|
||||
@ -494,9 +494,7 @@ export function selectRealLastReadId(global: GlobalState, chatId: number, thread
|
||||
}
|
||||
|
||||
// Some previously read messages may be deleted
|
||||
return threadInfo.lastMessageId
|
||||
? Math.min(threadInfo.lastReadInboxMessageId, threadInfo.lastMessageId)
|
||||
: threadInfo.lastReadInboxMessageId;
|
||||
return Math.min(threadInfo.lastReadInboxMessageId, threadInfo.lastMessageId || Infinity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user