Skip to content

Commit 5db8ebf

Browse files
committed
Merge pull request #745 from redjex/fix-gift-converted-text
Gifts: a gift converted to Stars says so under it, as in Telegram Desktop
2 parents 054e84d + 8c6b4eb commit 5db8ebf

5 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎src/components/chat/bubbles/starGift.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ export function StarGiftBubble(props: {
7676
return <I18nTsx key="StarGiftDefaultMessageUpgrade" />
7777
}
7878

79+
if(props.gift.isConverted && props.gift.isIncoming) {
80+
return (
81+
<I18nTsx
82+
key="StarGiftGotStars"
83+
args={`${props.gift.raw.convert_stars}`}
84+
/>
85+
);
86+
}
87+
7988
if(props.gift.raw.convert_stars !== undefined && !props.gift.isUpgraded) {
8089
return props.gift.isIncoming ? (
8190
<I18nTsx

‎src/components/popups/starGiftInfo.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ export default function showStarGiftInfoPopup(options: {
876876
try {
877877
await managers.appGiftsManager.convertGift(input);
878878
context.hide();
879+
toastNew({langPackKey: 'StarGiftGotStars', langPackArguments: [+saved.convert_stars]});
879880
} catch(err) {
880881
toastNew({langPackKey: 'Error.AnError'});
881882
}

‎src/lang.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,6 +4019,10 @@ const lang = {
40194019
'one_value': 'Add this gift to your profile or convert it to %d Star.',
40204020
'other_value': 'Add this gift to your profile or convert it to %d Stars.'
40214021
},
4022+
'StarGiftGotStars': {
4023+
'one_value': 'You got **%d Star** for this gift.',
4024+
'other_value': 'You got **%d Stars** for this gift.'
4025+
},
40224026
'StarGiftDefaultMessageConvertableOut': {
40234027
'one_value': '%2$s can add this gift on their profile or convert it to %1$d Star.',
40244028
'other_value': '%2$s can add this gift on their profile or convert it to %1$d Stars.'

‎src/lib/appManagers/appGiftsManager.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@ export default class AppGiftsManager extends AppManager {
419419
await this.apiManager.invokeApiSingle('payments.convertStarGift', {
420420
stargift: gift
421421
});
422+
423+
// * the server does not edit the gift's message, so it is marked here for its bubble to say so
424+
if(gift._ !== 'inputSavedStarGiftUser') return;
425+
const mid = this.appMessagesIdsManager.generateMessageId(gift.msg_id);
426+
const message = this.appMessagesManager.getMessageById(mid) as Message.messageService;
427+
if(message?._ !== 'messageService' || message.action._ !== 'messageActionStarGift') return;
428+
429+
const storage = this.appMessagesManager.getHistoryMessagesStorage(message.peerId);
430+
this.appMessagesManager.modifyMessage(message, (message) => {
431+
(message.action as MessageAction.messageActionStarGift).pFlags.converted = true;
432+
}, storage);
433+
434+
this.rootScope.dispatchEvent('message_edit', {
435+
storageKey: storage.key,
436+
peerId: message.peerId,
437+
mid: message.mid,
438+
message
439+
});
422440
}
423441

424442
public async getPremiumGiftOptions(): Promise<MyPremiumGiftOption[]> {

‎src/scripts/out/langPack.strings‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,8 @@
35243524
"StarGiftDefaultMessageOut" = "%s can display this gift on their profile.";
35253525
"StarGiftDefaultMessageConvertable_one" = "Add this gift to your profile or convert it to %d Star.";
35263526
"StarGiftDefaultMessageConvertable_other" = "Add this gift to your profile or convert it to %d Stars.";
3527+
"StarGiftGotStars_one" = "You got **%d Star** for this gift.";
3528+
"StarGiftGotStars_other" = "You got **%d Stars** for this gift.";
35273529
"StarGiftDefaultMessageConvertableOut_one" = "%2$s can add this gift on their profile or convert it to %1$d Star.";
35283530
"StarGiftDefaultMessageConvertableOut_other" = "%2$s can add this gift on their profile or convert it to %1$d Stars.";
35293531
"StarGiftDefaultMessageUpgrade" = "Upgrade this gift to a unique collectible.";

0 commit comments

Comments
 (0)