Profile: Fix gift error (#6060)
This commit is contained in:
parent
3131a5878b
commit
3fee5f06bd
@ -96,6 +96,7 @@ export interface ApiSavedStarGift {
|
||||
isPinned?: boolean;
|
||||
isConverted?: boolean; // Local field, used for Action Message
|
||||
upgradeMsgId?: number; // Local field, used for Action Message
|
||||
localTag?: number; // Local field, used for key in list
|
||||
}
|
||||
|
||||
export type StarGiftAttributeIdModel = {
|
||||
|
||||
@ -41,6 +41,7 @@ import {
|
||||
isUserBot,
|
||||
isUserRightBanned,
|
||||
} from '../../global/helpers';
|
||||
import { getSavedGiftKey } from '../../global/helpers/stars';
|
||||
import {
|
||||
selectActiveDownloads,
|
||||
selectChat,
|
||||
@ -360,10 +361,7 @@ const Profile: FC<OwnProps & StateProps> = ({
|
||||
const [renderingGifts, setRenderingGifts] = useState(gifts);
|
||||
const { startViewTransition, shouldApplyVtn } = useViewTransition();
|
||||
|
||||
const getGiftId = useLastCallback((gift: ApiSavedStarGift) => (
|
||||
`${gift.date}-${gift.fromId}-${gift.gift.id}`
|
||||
));
|
||||
const giftIds = useMemo(() => renderingGifts?.map(getGiftId), [renderingGifts]);
|
||||
const giftIds = useMemo(() => renderingGifts?.map((gift) => getSavedGiftKey(gift)), [renderingGifts]);
|
||||
|
||||
const renderingActiveTab = activeTab > tabs.length - 1 ? tabs.length - 1 : activeTab;
|
||||
const tabType = tabs[renderingActiveTab].type;
|
||||
@ -389,8 +387,8 @@ const Profile: FC<OwnProps & StateProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const prevGiftIds = prevGifts.map(getGiftId);
|
||||
const newGiftIds = gifts.map(getGiftId);
|
||||
const prevGiftIds = prevGifts.map((gift) => getSavedGiftKey(gift));
|
||||
const newGiftIds = gifts.map((gift) => getSavedGiftKey(gift));
|
||||
const hasOrderChanged = prevGiftIds.some((id, index) => id !== newGiftIds[index]);
|
||||
|
||||
if (hasOrderChanged) {
|
||||
@ -847,8 +845,8 @@ const Profile: FC<OwnProps & StateProps> = ({
|
||||
return (
|
||||
<SavedGift
|
||||
peerId={chatId}
|
||||
key={getGiftId(gift)}
|
||||
style={shouldApplyVtn ? `view-transition-name: vt${getGiftId(gift)}` : undefined}
|
||||
key={getSavedGiftKey(gift)}
|
||||
style={shouldApplyVtn ? `view-transition-name: vt${getSavedGiftKey(gift)}` : undefined}
|
||||
gift={gift}
|
||||
observeIntersection={observeIntersectionForMedia}
|
||||
/>
|
||||
|
||||
11
src/global/helpers/stars.ts
Normal file
11
src/global/helpers/stars.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import type { ApiSavedStarGift } from '../../api/types';
|
||||
|
||||
export function getSavedGiftKey(gift: ApiSavedStarGift, withoutTag?: boolean) {
|
||||
return [
|
||||
gift.date,
|
||||
gift.fromId,
|
||||
gift.gift.id,
|
||||
gift.gift.type === 'starGiftUnique' ? gift.gift.number : undefined,
|
||||
!withoutTag ? gift.localTag : undefined,
|
||||
].filter(Boolean).join('-');
|
||||
}
|
||||
@ -13,6 +13,7 @@ import { areDeepEqual } from '../../util/areDeepEqual';
|
||||
import { getCurrentTabId } from '../../util/establishMultitabRole';
|
||||
import { omit, omitUndefined, unique } from '../../util/iteratees';
|
||||
import { MEMO_EMPTY_ARRAY } from '../../util/memo';
|
||||
import { getSavedGiftKey } from '../helpers/stars';
|
||||
import { selectTabState } from '../selectors';
|
||||
import { updateTabState } from './tabs';
|
||||
|
||||
@ -332,6 +333,17 @@ export function replacePeerSavedGifts<T extends GlobalState>(
|
||||
): T {
|
||||
const tabState = selectTabState(global, tabId);
|
||||
|
||||
// Some non-unique gifts can be entirely identical and break `key`
|
||||
const keyCounts = new Map<string, number>();
|
||||
gifts.forEach((gift) => {
|
||||
const id = getSavedGiftKey(gift, true);
|
||||
const count = keyCounts.get(id) || 0;
|
||||
if (count > 0) {
|
||||
gift.localTag = count;
|
||||
}
|
||||
keyCounts.set(id, count + 1);
|
||||
});
|
||||
|
||||
return updateTabState(global, {
|
||||
savedGifts: {
|
||||
...tabState.savedGifts,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user