Unique Gifts: Follow-up (#5468)
This commit is contained in:
parent
d1304c621d
commit
aabf78a8fa
@ -468,7 +468,6 @@ export function saveStarGift({
|
|||||||
messageId,
|
messageId,
|
||||||
shouldUnsave,
|
shouldUnsave,
|
||||||
}: {
|
}: {
|
||||||
user: ApiUser;
|
|
||||||
messageId: number;
|
messageId: number;
|
||||||
shouldUnsave?: boolean;
|
shouldUnsave?: boolean;
|
||||||
}) {
|
}) {
|
||||||
@ -481,7 +480,6 @@ export function saveStarGift({
|
|||||||
export function convertStarGift({
|
export function convertStarGift({
|
||||||
messageId,
|
messageId,
|
||||||
}: {
|
}: {
|
||||||
user: ApiUser;
|
|
||||||
messageId: number;
|
messageId: number;
|
||||||
}) {
|
}) {
|
||||||
return invokeRequest(new GramJs.payments.ConvertStarGift({
|
return invokeRequest(new GramJs.payments.ConvertStarGift({
|
||||||
|
|||||||
@ -133,7 +133,7 @@ const RadialPatternBackground = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const radialGradient = ctx.createRadialGradient(width / 2, height / 2, 0, width / 2, height / 2, width / 2);
|
const radialGradient = ctx.createRadialGradient(width / 2, height / 2, 0, width / 2, height / 2, width / 2);
|
||||||
radialGradient.addColorStop(0, '#FFFFFF00');
|
radialGradient.addColorStop(0, '#FFFFFF77');
|
||||||
radialGradient.addColorStop(1, '#FFFFFF');
|
radialGradient.addColorStop(1, '#FFFFFF');
|
||||||
|
|
||||||
// Alpha mask
|
// Alpha mask
|
||||||
|
|||||||
@ -341,17 +341,24 @@
|
|||||||
|
|
||||||
.action-message-unique-properties {
|
.action-message-unique-properties {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: min-content 1fr;
|
||||||
|
justify-content: center;
|
||||||
gap: 0.375rem;
|
gap: 0.375rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
margin-top: 0.5rem;
|
margin-top: 0.5rem;
|
||||||
|
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.action-message-unique-value {
|
.action-message-unique-value {
|
||||||
color: white;
|
color: white;
|
||||||
justify-self: flex-start;
|
justify-self: flex-start;
|
||||||
|
width: 100%; // Grid ellipsis hack
|
||||||
|
text-align: initial;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.action-message-unique-property {
|
.action-message-unique-property {
|
||||||
|
|||||||
@ -81,8 +81,7 @@ const GiftInfoModal = ({
|
|||||||
const giftSticker = gift && getStickerFromGift(gift);
|
const giftSticker = gift && getStickerFromGift(gift);
|
||||||
|
|
||||||
const canFocusUpgrade = Boolean(userGift?.upgradeMsgId);
|
const canFocusUpgrade = Boolean(userGift?.upgradeMsgId);
|
||||||
const canUpdate = gift?.type === 'starGiftUnique'
|
const canUpdate = Boolean(userGift?.messageId) && !isSender && !canFocusUpgrade;
|
||||||
? gift.ownerId === currentUserId : Boolean(userGift?.messageId) && !isSender && !canFocusUpgrade;
|
|
||||||
|
|
||||||
const handleClose = useLastCallback(() => {
|
const handleClose = useLastCallback(() => {
|
||||||
closeGiftInfoModal();
|
closeGiftInfoModal();
|
||||||
@ -96,14 +95,14 @@ const GiftInfoModal = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleTriggerVisibility = useLastCallback(() => {
|
const handleTriggerVisibility = useLastCallback(() => {
|
||||||
const { fromId, messageId, isUnsaved } = userGift!;
|
const { messageId, isUnsaved } = userGift!;
|
||||||
changeGiftVisibility({ userId: fromId!, messageId: messageId!, shouldUnsave: !isUnsaved });
|
changeGiftVisibility({ messageId: messageId!, shouldUnsave: !isUnsaved });
|
||||||
handleClose();
|
handleClose();
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleConvertToStars = useLastCallback(() => {
|
const handleConvertToStars = useLastCallback(() => {
|
||||||
const { fromId, messageId } = userGift!;
|
const { messageId } = userGift!;
|
||||||
convertGiftToStars({ userId: fromId!, messageId: messageId! });
|
convertGiftToStars({ messageId: messageId! });
|
||||||
closeConvertConfirm();
|
closeConvertConfirm();
|
||||||
handleClose();
|
handleClose();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import type { ApiUserStarGift } from '../../../api/types';
|
||||||
import type { StarGiftCategory } from '../../../types';
|
import type { StarGiftCategory } from '../../../types';
|
||||||
|
|
||||||
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
||||||
@ -7,6 +8,7 @@ import { addActionHandler, getGlobal, setGlobal } from '../../index';
|
|||||||
import {
|
import {
|
||||||
appendStarsSubscriptions,
|
appendStarsSubscriptions,
|
||||||
appendStarsTransactions,
|
appendStarsTransactions,
|
||||||
|
replaceUserGifts,
|
||||||
updateStarsBalance,
|
updateStarsBalance,
|
||||||
updateStarsSubscriptionLoading,
|
updateStarsSubscriptionLoading,
|
||||||
} from '../../reducers';
|
} from '../../reducers';
|
||||||
@ -152,19 +154,7 @@ addActionHandler('loadUserGifts', async (global, actions, payload): Promise<void
|
|||||||
|
|
||||||
const newGifts = currentGifts && !shouldRefresh ? currentGifts.gifts.concat(result.gifts) : result.gifts;
|
const newGifts = currentGifts && !shouldRefresh ? currentGifts.gifts.concat(result.gifts) : result.gifts;
|
||||||
|
|
||||||
global = {
|
global = replaceUserGifts(global, userId, newGifts, result.nextOffset);
|
||||||
...global,
|
|
||||||
users: {
|
|
||||||
...global.users,
|
|
||||||
giftsById: {
|
|
||||||
...global.users.giftsById,
|
|
||||||
[userId]: {
|
|
||||||
gifts: newGifts,
|
|
||||||
nextOffset: result.nextOffset,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
setGlobal(global);
|
setGlobal(global);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -223,32 +213,43 @@ addActionHandler('fulfillStarsSubscription', async (global, actions, payload): P
|
|||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('changeGiftVisibility', async (global, actions, payload): Promise<void> => {
|
addActionHandler('changeGiftVisibility', async (global, actions, payload): Promise<void> => {
|
||||||
const { userId, messageId, shouldUnsave } = payload;
|
const { messageId, shouldUnsave } = payload;
|
||||||
|
|
||||||
const user = selectUser(global, userId);
|
const currentUserId = global.currentUserId!;
|
||||||
if (!user) return;
|
|
||||||
|
const oldGifts = global.users.giftsById[currentUserId];
|
||||||
|
const newGifts = oldGifts.gifts.map((gift) => {
|
||||||
|
if (gift.messageId === messageId) {
|
||||||
|
return {
|
||||||
|
...gift,
|
||||||
|
isUnsaved: shouldUnsave,
|
||||||
|
} satisfies ApiUserStarGift;
|
||||||
|
}
|
||||||
|
return gift;
|
||||||
|
});
|
||||||
|
global = replaceUserGifts(global, currentUserId, newGifts, oldGifts.nextOffset);
|
||||||
|
setGlobal(global);
|
||||||
|
|
||||||
const result = await callApi('saveStarGift', {
|
const result = await callApi('saveStarGift', {
|
||||||
user,
|
|
||||||
messageId,
|
messageId,
|
||||||
shouldUnsave,
|
shouldUnsave,
|
||||||
});
|
});
|
||||||
|
global = getGlobal();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
global = replaceUserGifts(global, currentUserId, oldGifts.gifts, oldGifts.nextOffset);
|
||||||
|
setGlobal(global);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.loadUserGifts({ userId: global.currentUserId!, shouldRefresh: true });
|
// Reload gift list to avoid issues with pagination
|
||||||
|
actions.loadUserGifts({ userId: currentUserId, shouldRefresh: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('convertGiftToStars', async (global, actions, payload): Promise<void> => {
|
addActionHandler('convertGiftToStars', async (global, actions, payload): Promise<void> => {
|
||||||
const { userId, messageId, tabId = getCurrentTabId() } = payload;
|
const { messageId, tabId = getCurrentTabId() } = payload;
|
||||||
|
|
||||||
const user = selectUser(global, userId);
|
|
||||||
if (!user) return;
|
|
||||||
|
|
||||||
const result = await callApi('convertStarGift', {
|
const result = await callApi('convertStarGift', {
|
||||||
user,
|
|
||||||
messageId,
|
messageId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import type {
|
|||||||
ApiUser,
|
ApiUser,
|
||||||
ApiUserCommonChats,
|
ApiUserCommonChats,
|
||||||
ApiUserFullInfo,
|
ApiUserFullInfo,
|
||||||
|
ApiUserStarGift,
|
||||||
ApiUserStatus,
|
ApiUserStatus,
|
||||||
} from '../../api/types';
|
} from '../../api/types';
|
||||||
import type { BotAppPermissions } from '../../types';
|
import type { BotAppPermissions } from '../../types';
|
||||||
@ -322,3 +323,26 @@ export function updateBotAppPermissions<T extends GlobalState>(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function replaceUserGifts<T extends GlobalState>(
|
||||||
|
global: T,
|
||||||
|
userId: string,
|
||||||
|
gifts: ApiUserStarGift[],
|
||||||
|
nextOffset?: string,
|
||||||
|
): T {
|
||||||
|
global = {
|
||||||
|
...global,
|
||||||
|
users: {
|
||||||
|
...global.users,
|
||||||
|
giftsById: {
|
||||||
|
...global.users.giftsById,
|
||||||
|
[userId]: {
|
||||||
|
gifts,
|
||||||
|
nextOffset,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return global;
|
||||||
|
}
|
||||||
|
|||||||
@ -2303,12 +2303,10 @@ export interface ActionPayloads {
|
|||||||
shouldRefresh?: boolean;
|
shouldRefresh?: boolean;
|
||||||
};
|
};
|
||||||
changeGiftVisibility: {
|
changeGiftVisibility: {
|
||||||
userId: string;
|
|
||||||
messageId: number;
|
messageId: number;
|
||||||
shouldUnsave?: boolean;
|
shouldUnsave?: boolean;
|
||||||
};
|
};
|
||||||
convertGiftToStars: {
|
convertGiftToStars: {
|
||||||
userId: string;
|
|
||||||
messageId: number;
|
messageId: number;
|
||||||
} & WithTabId;
|
} & WithTabId;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user