Pinned Message: Fix updating after pin/unpin

This commit is contained in:
Alexander Zinchuk 2021-05-15 02:46:05 +03:00
parent 414c88f345
commit 18aeb7abe7
2 changed files with 3 additions and 8 deletions

View File

@ -134,15 +134,10 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
}
}, [chatId, loadPinnedMessages, lastSyncTime, threadId]);
// Modify pinned index after unpinning
useEffect(() => {
setPinnedMessageIndex(pinnedMessagesCount ? cycleRestrict(pinnedMessagesCount, pinnedMessageIndex) : -1);
}, [pinnedMessagesCount, pinnedMessageIndex]);
// Reset pinned index when switching chats
// Reset pinned index when switching chats and pinning/unpinning
useEffect(() => {
setPinnedMessageIndex(0);
}, [chatId]);
}, [pinnedMessageIds]);
useEnsureMessage(chatId, pinnedMessageId, pinnedMessage);

View File

@ -201,7 +201,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
const currentPinnedIds = selectPinnedIds(global, chatId) || [];
const newPinnedIds = isPinned
? [...currentPinnedIds, ...messageIds]
? [...currentPinnedIds, ...messageIds].sort((a, b) => b - a)
: currentPinnedIds.filter((id) => !messageIds.includes(id));
setGlobal(replaceThreadParam(global, chatId, MAIN_THREAD_ID, 'pinnedIds', newPinnedIds));