Skip to content

Commit de8b09d

Browse files
committed
Use correct phrases for outgoing giftcodes.
1 parent fddbce5 commit de8b09d

File tree

5 files changed

+68
-26
lines changed

5 files changed

+68
-26
lines changed

Telegram/SourceFiles/boxes/gift_premium_box.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void AddTable(
720720
controller,
721721
current.from);
722722
}
723-
if (current.to) {
723+
if (current.from && current.to) {
724724
AddTableRow(
725725
table,
726726
tr::lng_gift_link_label_to(),
@@ -739,7 +739,7 @@ void AddTable(
739739
lt_duration,
740740
GiftDurationValue(current.months) | Ui::Text::ToWithEntities(),
741741
Ui::Text::WithEntities));
742-
if (!skipReason) {
742+
if (!skipReason && current.from) {
743743
const auto reason = AddTableRow(
744744
table,
745745
tr::lng_gift_link_label_reason(),
@@ -1178,13 +1178,19 @@ void ResolveGiftCode(
11781178
PeerId fromId,
11791179
PeerId toId) {
11801180
const auto done = [=](Api::GiftCode code) {
1181+
const auto session = &controller->session();
1182+
const auto selfId = session->userPeerId();
11811183
if (!code) {
11821184
controller->showToast(tr::lng_gift_link_expired(tr::now));
1185+
} else if (!code.from && fromId == selfId) {
1186+
code.from = fromId;
1187+
code.to = toId;
1188+
const auto self = (fromId == selfId);
1189+
const auto peer = session->data().peer(self ? toId : fromId);
1190+
const auto months = code.months;
1191+
const auto parent = controller->parentController();
1192+
Settings::ShowGiftPremium(parent, peer, months, self);
11831193
} else {
1184-
if (!code.from) {
1185-
code.from = fromId;
1186-
code.to = toId;
1187-
}
11881194
controller->uiShow()->showBox(Box(GiftCodeBox, controller, slug));
11891195
}
11901196
};

Telegram/SourceFiles/history/history_item.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4530,19 +4530,35 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
45304530
auto prepareGiftCode = [&](const MTPDmessageActionGiftCode &action) {
45314531
auto result = PreparedServiceText();
45324532
_history->session().giftBoxStickersPacks().load();
4533-
result.text = {
4534-
(action.is_unclaimed()
4535-
? tr::lng_prize_unclaimed_about
4536-
: action.is_via_giveaway()
4537-
? tr::lng_prize_about
4538-
: tr::lng_prize_gift_about)(
4533+
if (const auto boosted = action.vboost_peer()) {
4534+
result.text = {
4535+
(action.is_unclaimed()
4536+
? tr::lng_prize_unclaimed_about
4537+
: action.is_via_giveaway()
4538+
? tr::lng_prize_about
4539+
: tr::lng_prize_gift_about)(
4540+
tr::now,
4541+
lt_channel,
4542+
_from->owner().peer(
4543+
peerFromMTP(*action.vboost_peer()))->name()),
4544+
};
4545+
} else {
4546+
const auto isSelf = (_from->id == _from->session().userPeerId());
4547+
const auto peer = isSelf ? _history->peer : _from;
4548+
result.links.push_back(peer->createOpenLink());
4549+
result.text = (isSelf
4550+
? tr::lng_action_gift_received_me
4551+
: tr::lng_action_gift_received)(
45394552
tr::now,
4540-
lt_channel,
4541-
(action.vboost_peer()
4542-
? _from->owner().peer(
4543-
peerFromMTP(*action.vboost_peer()))->name()
4544-
: "a channel")),
4545-
};
4553+
lt_user,
4554+
Ui::Text::Link(peer->name(), 1), // Link 1.
4555+
lt_cost,
4556+
{ Ui::FillAmountAndCurrency(
4557+
action.vamount().value_or_empty(),
4558+
qs(action.vcurrency().value_or_empty())) },
4559+
Ui::Text::WithEntities);
4560+
4561+
}
45464562
return result;
45474563
};
45484564

@@ -4697,7 +4713,7 @@ void HistoryItem::applyAction(const MTPMessageAction &action) {
46974713
_from,
46984714
Data::GiftCode{
46994715
.slug = qs(data.vslug()),
4700-
.channel = (peerIsChannel(boostedId)
4716+
.channel = (boostedId
47014717
? history()->owner().channel(boostedId).get()
47024718
: nullptr),
47034719
.months = data.vmonths().v,

Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ QSize PremiumGift::size() {
4343
}
4444

4545
QString PremiumGift::title() {
46-
return _data.slug.isEmpty()
46+
return gift()
4747
? tr::lng_premium_summary_title(tr::now)
4848
: _data.unclaimed
4949
? tr::lng_prize_unclaimed_title(tr::now)
5050
: tr::lng_prize_title(tr::now);
5151
}
5252

5353
TextWithEntities PremiumGift::subtitle() {
54-
if (_data.slug.isEmpty()) {
54+
if (gift()) {
5555
return { GiftDuration(_data.months) };
5656
}
5757
const auto name = _data.channel ? _data.channel->name() : "channel";
@@ -78,7 +78,7 @@ TextWithEntities PremiumGift::subtitle() {
7878
}
7979

8080
rpl::producer<QString> PremiumGift::button() {
81-
return _data.slug.isEmpty()
81+
return (gift() && (outgoingGift() || !_data.unclaimed))
8282
? tr::lng_sticker_premium_view()
8383
: tr::lng_prize_open();
8484
}
@@ -121,7 +121,7 @@ void PremiumGift::draw(
121121
}
122122

123123
bool PremiumGift::hideServiceText() {
124-
return !_data.slug.isEmpty();
124+
return !gift();
125125
}
126126

127127
void PremiumGift::stickerClearLoopPlayed() {
@@ -148,6 +148,18 @@ void PremiumGift::unloadHeavyPart() {
148148
}
149149
}
150150

151+
bool PremiumGift::incomingGift() const {
152+
return gift() && !_parent->data()->out();
153+
}
154+
155+
bool PremiumGift::outgoingGift() const {
156+
return gift() && _parent->data()->out();
157+
}
158+
159+
bool PremiumGift::gift() const {
160+
return _data.slug.isEmpty() || !_data.channel;
161+
}
162+
151163
void PremiumGift::ensureStickerCreated() const {
152164
if (_sticker) {
153165
return;

Telegram/SourceFiles/history/view/media/history_view_premium_gift.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class PremiumGift final : public ServiceBoxContent {
4646
void unloadHeavyPart() override;
4747

4848
private:
49+
[[nodiscard]] bool incomingGift() const;
50+
[[nodiscard]] bool outgoingGift() const;
51+
[[nodiscard]] bool gift() const;
4952
void ensureStickerCreated() const;
5053

5154
const not_null<Element*> _parent;

Telegram/SourceFiles/settings/settings_premium.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ void Premium::setStepDataReference(std::any &data) {
871871
void Premium::setupSubscriptionOptions(
872872
not_null<Ui::VerticalLayout*> container) {
873873
const auto isEmojiStatus = (!!Ref::EmojiStatus::Parse(_ref));
874+
const auto isGift = (!!Ref::Gift::Parse(_ref));
874875

875876
const auto options = container->add(
876877
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
@@ -900,15 +901,19 @@ void Premium::setupSubscriptionOptions(
900901
Ui::AddSkip(content, lastSkip - st::defaultVerticalListSkip);
901902
Ui::AddSkip(skip->entity(), lastSkip);
902903

904+
if (isEmojiStatus || isGift) {
905+
options->toggle(false, anim::type::instant);
906+
skip->toggle(true, anim::type::instant);
907+
return;
908+
}
903909
auto toggleOn = rpl::combine(
904910
Data::AmPremiumValue(&_controller->session()),
905-
rpl::single(isEmojiStatus),
906911
apiPremium->statusTextValue(
907912
) | rpl::map([=] {
908913
return apiPremium->subscriptionOptions().size() < 2;
909914
})
910-
) | rpl::map([=](bool premium, bool isEmojiStatus, bool noOptions) {
911-
return !premium && !isEmojiStatus && !noOptions;
915+
) | rpl::map([=](bool premium, bool noOptions) {
916+
return !premium && !noOptions;
912917
});
913918
options->toggleOn(rpl::duplicate(toggleOn), anim::type::instant);
914919
skip->toggleOn(std::move(

0 commit comments

Comments
 (0)