Middle Header: Fix pinned message getting stuck (#2519)
This commit is contained in:
parent
0be5085d69
commit
f0574f78a5
@ -92,6 +92,7 @@ type StateProps = {
|
|||||||
isChatWithSelf?: boolean;
|
isChatWithSelf?: boolean;
|
||||||
lastSyncTime?: number;
|
lastSyncTime?: number;
|
||||||
hasButtonInHeader?: boolean;
|
hasButtonInHeader?: boolean;
|
||||||
|
hasReachedFocusedMessage?: boolean;
|
||||||
shouldSkipHistoryAnimations?: boolean;
|
shouldSkipHistoryAnimations?: boolean;
|
||||||
currentTransitionKey: number;
|
currentTransitionKey: number;
|
||||||
connectionState?: GlobalState['connectionState'];
|
connectionState?: GlobalState['connectionState'];
|
||||||
@ -121,6 +122,7 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
|
|||||||
shouldSkipHistoryAnimations,
|
shouldSkipHistoryAnimations,
|
||||||
currentTransitionKey,
|
currentTransitionKey,
|
||||||
connectionState,
|
connectionState,
|
||||||
|
hasReachedFocusedMessage,
|
||||||
isSyncing,
|
isSyncing,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
@ -129,6 +131,7 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
|
|||||||
focusMessage,
|
focusMessage,
|
||||||
openChat,
|
openChat,
|
||||||
openPreviousChat,
|
openPreviousChat,
|
||||||
|
setReachedFocusedMessage,
|
||||||
loadPinnedMessages,
|
loadPinnedMessages,
|
||||||
toggleLeftColumn,
|
toggleLeftColumn,
|
||||||
exitMessageSelectMode,
|
exitMessageSelectMode,
|
||||||
@ -136,6 +139,7 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
const isBackButtonActive = useRef(true);
|
const isBackButtonActive = useRef(true);
|
||||||
|
const [isWaitingForPinnedMessageFocus, setWaitingForPinnedMessageFocus] = useState(false);
|
||||||
const { isTablet } = useAppLayout();
|
const { isTablet } = useAppLayout();
|
||||||
|
|
||||||
const [pinnedMessageIndex, setPinnedMessageIndex] = useState(0);
|
const [pinnedMessageIndex, setPinnedMessageIndex] = useState(0);
|
||||||
@ -157,8 +161,22 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
|
|||||||
// Reset pinned index when switching chats and pinning/unpinning
|
// Reset pinned index when switching chats and pinning/unpinning
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPinnedMessageIndex(0);
|
setPinnedMessageIndex(0);
|
||||||
|
setWaitingForPinnedMessageFocus(false);
|
||||||
}, [pinnedMessageIds]);
|
}, [pinnedMessageIds]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasReachedFocusedMessage && isWaitingForPinnedMessageFocus) {
|
||||||
|
setReachedFocusedMessage({ hasReached: false });
|
||||||
|
setWaitingForPinnedMessageFocus(false);
|
||||||
|
|
||||||
|
const newIndex = cycleRestrict(pinnedMessagesCount || 1, pinnedMessageIndex + 1);
|
||||||
|
setPinnedMessageIndex(newIndex);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
hasReachedFocusedMessage, isWaitingForPinnedMessageFocus, pinnedMessageIndex, pinnedMessagesCount,
|
||||||
|
setReachedFocusedMessage,
|
||||||
|
]);
|
||||||
|
|
||||||
useEnsureMessage(chatId, pinnedMessageId, pinnedMessage);
|
useEnsureMessage(chatId, pinnedMessageId, pinnedMessage);
|
||||||
|
|
||||||
const { width: windowWidth } = useWindowSize();
|
const { width: windowWidth } = useWindowSize();
|
||||||
@ -184,10 +202,9 @@ const MiddleHeader: FC<OwnProps & StateProps> = ({
|
|||||||
chatId: pinnedMessage.chatId, threadId, messageId: pinnedMessage.id, noForumTopicPanel: true,
|
chatId: pinnedMessage.chatId, threadId, messageId: pinnedMessage.id, noForumTopicPanel: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const newIndex = cycleRestrict(pinnedMessagesCount || 1, pinnedMessageIndex + 1);
|
setWaitingForPinnedMessageFocus(true);
|
||||||
setPinnedMessageIndex(newIndex);
|
|
||||||
}
|
}
|
||||||
}, [pinnedMessage, focusMessage, threadId, pinnedMessagesCount, pinnedMessageIndex]);
|
}, [pinnedMessage, focusMessage, threadId]);
|
||||||
|
|
||||||
const handleAllPinnedClick = useCallback(() => {
|
const handleAllPinnedClick = useCallback(() => {
|
||||||
openChat({ id: chatId, threadId, type: 'pinned' });
|
openChat({ id: chatId, threadId, type: 'pinned' });
|
||||||
@ -492,6 +509,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
);
|
);
|
||||||
const shouldSendJoinRequest = Boolean(chat?.isNotJoined && chat.isJoinRequest);
|
const shouldSendJoinRequest = Boolean(chat?.isNotJoined && chat.isJoinRequest);
|
||||||
const typingStatus = selectThreadParam(global, chatId, threadId, 'typingStatus');
|
const typingStatus = selectThreadParam(global, chatId, threadId, 'typingStatus');
|
||||||
|
const focusedMessage = selectTabState(global).focusedMessage;
|
||||||
|
|
||||||
const state: StateProps = {
|
const state: StateProps = {
|
||||||
typingStatus,
|
typingStatus,
|
||||||
@ -508,6 +526,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
connectionState: global.connectionState,
|
connectionState: global.connectionState,
|
||||||
isSyncing: global.isSyncing,
|
isSyncing: global.isSyncing,
|
||||||
hasButtonInHeader: canStartBot || canRestartBot || canSubscribe || shouldSendJoinRequest,
|
hasButtonInHeader: canStartBot || canRestartBot || canSubscribe || shouldSendJoinRequest,
|
||||||
|
hasReachedFocusedMessage: !focusedMessage || focusedMessage.hasReachedMessage,
|
||||||
};
|
};
|
||||||
|
|
||||||
const messagesById = selectChatMessages(global, chatId);
|
const messagesById = selectChatMessages(global, chatId);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { getActions } from '../../../../global';
|
||||||
|
|
||||||
import type { FocusDirection } from '../../../../types';
|
import type { FocusDirection } from '../../../../types';
|
||||||
|
|
||||||
import { useLayoutEffect } from '../../../../lib/teact/teact';
|
import { useLayoutEffect } from '../../../../lib/teact/teact';
|
||||||
@ -15,10 +17,16 @@ export default function useFocusMessage(
|
|||||||
noFocusHighlight?: boolean,
|
noFocusHighlight?: boolean,
|
||||||
isResizingContainer?: boolean,
|
isResizingContainer?: boolean,
|
||||||
) {
|
) {
|
||||||
|
const { setReachedFocusedMessage } = getActions();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (isFocused && elementRef.current) {
|
if (isFocused && elementRef.current) {
|
||||||
const messagesContainer = elementRef.current.closest<HTMLDivElement>('.MessageList')!;
|
const messagesContainer = elementRef.current.closest<HTMLDivElement>('.MessageList')!;
|
||||||
|
|
||||||
|
setReachedFocusedMessage({
|
||||||
|
hasReached: true,
|
||||||
|
});
|
||||||
|
|
||||||
fastSmoothScroll(
|
fastSmoothScroll(
|
||||||
messagesContainer,
|
messagesContainer,
|
||||||
elementRef.current,
|
elementRef.current,
|
||||||
@ -31,5 +39,7 @@ export default function useFocusMessage(
|
|||||||
isResizingContainer,
|
isResizingContainer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, [elementRef, chatId, isFocused, focusDirection, noFocusHighlight, isResizingContainer]);
|
}, [
|
||||||
|
elementRef, chatId, isFocused, focusDirection, noFocusHighlight, isResizingContainer, setReachedFocusedMessage,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import {
|
|||||||
replaceThreadParam,
|
replaceThreadParam,
|
||||||
replaceTabThreadParam,
|
replaceTabThreadParam,
|
||||||
updateFocusDirection,
|
updateFocusDirection,
|
||||||
updateFocusedMessage,
|
updateFocusedMessage, updateFocusedMessageReached,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
import {
|
import {
|
||||||
selectCurrentChat,
|
selectCurrentChat,
|
||||||
@ -368,6 +368,12 @@ addActionHandler('focusNextReply', (global, actions, payload): ActionReturnType
|
|||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addActionHandler('setReachedFocusedMessage', (global, actions, payload): ActionReturnType => {
|
||||||
|
const { hasReached = false, tabId = getCurrentTabId() } = payload;
|
||||||
|
|
||||||
|
return updateFocusedMessageReached(global, hasReached, tabId);
|
||||||
|
});
|
||||||
|
|
||||||
addActionHandler('focusMessage', (global, actions, payload): ActionReturnType => {
|
addActionHandler('focusMessage', (global, actions, payload): ActionReturnType => {
|
||||||
const {
|
const {
|
||||||
chatId, threadId = MAIN_THREAD_ID, messageListType = 'thread', noHighlight, groupedId, groupedChatId,
|
chatId, threadId = MAIN_THREAD_ID, messageListType = 'thread', noHighlight, groupedId, groupedChatId,
|
||||||
|
|||||||
@ -512,6 +512,22 @@ export function updateFocusedMessage<T extends GlobalState>(
|
|||||||
}, tabId);
|
}, tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateFocusedMessageReached<T extends GlobalState>(
|
||||||
|
global: T, hasReachedMessage: boolean,
|
||||||
|
...[tabId = getCurrentTabId()]: TabArgs<T>
|
||||||
|
): T {
|
||||||
|
const focusedMessage = selectTabState(global, tabId).focusedMessage;
|
||||||
|
|
||||||
|
if (!focusedMessage) return global;
|
||||||
|
|
||||||
|
return updateTabState(global, {
|
||||||
|
focusedMessage: {
|
||||||
|
...focusedMessage,
|
||||||
|
hasReachedMessage,
|
||||||
|
},
|
||||||
|
}, tabId);
|
||||||
|
}
|
||||||
|
|
||||||
export function updateSponsoredMessage<T extends GlobalState>(
|
export function updateSponsoredMessage<T extends GlobalState>(
|
||||||
global: T, chatId: string, message: ApiSponsoredMessage,
|
global: T, chatId: string, message: ApiSponsoredMessage,
|
||||||
): T {
|
): T {
|
||||||
|
|||||||
@ -214,6 +214,7 @@ export type TabState = {
|
|||||||
direction?: FocusDirection;
|
direction?: FocusDirection;
|
||||||
noHighlight?: boolean;
|
noHighlight?: boolean;
|
||||||
isResizingContainer?: boolean;
|
isResizingContainer?: boolean;
|
||||||
|
hasReachedMessage?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
selectedMessages?: {
|
selectedMessages?: {
|
||||||
@ -1445,6 +1446,9 @@ export interface ActionPayloads {
|
|||||||
showDialog: {
|
showDialog: {
|
||||||
data: TabState['dialogs'][number];
|
data: TabState['dialogs'][number];
|
||||||
} & WithTabId;
|
} & WithTabId;
|
||||||
|
setReachedFocusedMessage: {
|
||||||
|
hasReached?: boolean;
|
||||||
|
} & WithTabId;
|
||||||
focusMessage: {
|
focusMessage: {
|
||||||
chatId: string;
|
chatId: string;
|
||||||
threadId?: number;
|
threadId?: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user