mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support correct paid-media-from-bot phrases.
This commit is contained in:
parent
9ea495f59d
commit
a2785867b2
5 changed files with 59 additions and 30 deletions
|
@ -2376,6 +2376,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_credits_box_out_sure#other" = "Do you want to buy **\"{text}\"** in **{bot}** for **{count} Stars**?";
|
"lng_credits_box_out_sure#other" = "Do you want to buy **\"{text}\"** in **{bot}** for **{count} Stars**?";
|
||||||
"lng_credits_box_out_media#one" = "Do you want to unlock {media} in {chat} for **{count} Star**?";
|
"lng_credits_box_out_media#one" = "Do you want to unlock {media} in {chat} for **{count} Star**?";
|
||||||
"lng_credits_box_out_media#other" = "Do you want to unlock {media} in {chat} for **{count} Stars**?";
|
"lng_credits_box_out_media#other" = "Do you want to unlock {media} in {chat} for **{count} Stars**?";
|
||||||
|
"lng_credits_box_out_media_user#one" = "Do you want to unlock {media} from {user} for **{count} Star**?";
|
||||||
|
"lng_credits_box_out_media_user#other" = "Do you want to unlock {media} from {user} for **{count} Stars**?";
|
||||||
"lng_credits_box_out_photo" = "a photo";
|
"lng_credits_box_out_photo" = "a photo";
|
||||||
"lng_credits_box_out_photos#one" = "{count} photo";
|
"lng_credits_box_out_photos#one" = "{count} photo";
|
||||||
"lng_credits_box_out_photos#other" = "{count} photos";
|
"lng_credits_box_out_photos#other" = "{count} photos";
|
||||||
|
@ -2390,6 +2392,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_credits_media_done_title" = "Media Unlocked";
|
"lng_credits_media_done_title" = "Media Unlocked";
|
||||||
"lng_credits_media_done_text#one" = "**{count} Star** transferred to {chat}.";
|
"lng_credits_media_done_text#one" = "**{count} Star** transferred to {chat}.";
|
||||||
"lng_credits_media_done_text#other" = "**{count} Stars** transferred to {chat}.";
|
"lng_credits_media_done_text#other" = "**{count} Stars** transferred to {chat}.";
|
||||||
|
"lng_credits_media_done_text_user#one" = "**{count} Star** transferred to {user}.";
|
||||||
|
"lng_credits_media_done_text_user#other" = "**{count} Stars** transferred to {user}.";
|
||||||
"lng_credits_summary_in_toast_title" = "Stars Acquired";
|
"lng_credits_summary_in_toast_title" = "Stars Acquired";
|
||||||
"lng_credits_summary_in_toast_about#one" = "**{count}** Star added to your balance.";
|
"lng_credits_summary_in_toast_about#one" = "**{count}** Star added to your balance.";
|
||||||
"lng_credits_summary_in_toast_about#other" = "**{count}** Stars added to your balance.";
|
"lng_credits_summary_in_toast_about#other" = "**{count}** Stars added to your balance.";
|
||||||
|
|
|
@ -81,14 +81,12 @@ struct PaidMediaData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto bot = item->viaBot();
|
||||||
const auto sender = item->originalSender();
|
const auto sender = item->originalSender();
|
||||||
const auto broadcast = (sender && sender->isBroadcast())
|
|
||||||
? sender
|
|
||||||
: message->peer.get();
|
|
||||||
return {
|
return {
|
||||||
.invoice = invoice,
|
.invoice = invoice,
|
||||||
.item = item,
|
.item = item,
|
||||||
.peer = broadcast,
|
.peer = (bot ? bot : sender ? sender : message->peer.get()),
|
||||||
.photos = photos,
|
.photos = photos,
|
||||||
.videos = videos,
|
.videos = videos,
|
||||||
};
|
};
|
||||||
|
@ -131,6 +129,16 @@ struct PaidMediaData {
|
||||||
lt_video,
|
lt_video,
|
||||||
std::move(videosBold),
|
std::move(videosBold),
|
||||||
Ui::Text::WithEntities);
|
Ui::Text::WithEntities);
|
||||||
|
if (const auto user = data.peer->asUser()) {
|
||||||
|
return tr::lng_credits_box_out_media_user(
|
||||||
|
lt_count,
|
||||||
|
rpl::single(form->invoice.amount) | tr::to_count(),
|
||||||
|
lt_media,
|
||||||
|
std::move(media),
|
||||||
|
lt_user,
|
||||||
|
rpl::single(Ui::Text::Bold(user->shortName())),
|
||||||
|
Ui::Text::RichLangValue);
|
||||||
|
}
|
||||||
return tr::lng_credits_box_out_media(
|
return tr::lng_credits_box_out_media(
|
||||||
lt_count,
|
lt_count,
|
||||||
rpl::single(form->invoice.amount) | tr::to_count(),
|
rpl::single(form->invoice.amount) | tr::to_count(),
|
||||||
|
|
|
@ -81,43 +81,42 @@ rpl::producer<bool> Credits::loadedValue() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 Credits::balance() const {
|
uint64 Credits::balance() const {
|
||||||
const auto balance = _balance.current();
|
return _nonLockedBalance.current();
|
||||||
const auto locked = _locked.current();
|
|
||||||
return (balance >= locked) ? (balance - locked) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<uint64> Credits::balanceValue() const {
|
rpl::producer<uint64> Credits::balanceValue() const {
|
||||||
return rpl::combine(
|
return _nonLockedBalance.value();
|
||||||
_balance.value(),
|
}
|
||||||
_locked.value()
|
|
||||||
) | rpl::map([=](uint64 balance, uint64 locked) {
|
void Credits::updateNonLockedValue() {
|
||||||
return (balance >= locked) ? (balance - locked) : 0;
|
_nonLockedBalance = (_balance >= _locked) ? (_balance - _locked) : 0;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Credits::lock(int count) {
|
void Credits::lock(int count) {
|
||||||
Expects(loaded());
|
Expects(loaded());
|
||||||
Expects(count >= 0);
|
Expects(count >= 0);
|
||||||
|
Expects(_locked + count <= _balance);
|
||||||
|
|
||||||
_locked = _locked.current() + count;
|
_locked += count;
|
||||||
|
|
||||||
Ensures(_locked.current() <= _balance.current());
|
updateNonLockedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Credits::unlock(int count) {
|
void Credits::unlock(int count) {
|
||||||
Expects(count >= 0);
|
Expects(count >= 0);
|
||||||
Expects(_locked.current() >= count);
|
Expects(_locked >= count);
|
||||||
|
|
||||||
_locked = _locked.current() - count;
|
_locked -= count;
|
||||||
|
|
||||||
|
updateNonLockedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Credits::withdrawLocked(int count) {
|
void Credits::withdrawLocked(int count) {
|
||||||
Expects(count >= 0);
|
Expects(count >= 0);
|
||||||
Expects(_locked.current() >= count);
|
Expects(_locked >= count);
|
||||||
|
|
||||||
const auto balance = _balance.current();
|
_locked -= count;
|
||||||
_locked = _locked.current() - count;
|
apply(_balance >= count ? (_balance - count) : 0);
|
||||||
apply(balance >= count ? (balance - count) : 0);
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +126,7 @@ void Credits::invalidate() {
|
||||||
|
|
||||||
void Credits::apply(uint64 balance) {
|
void Credits::apply(uint64 balance) {
|
||||||
_balance = balance;
|
_balance = balance;
|
||||||
|
updateNonLockedValue();
|
||||||
|
|
||||||
const auto was = std::exchange(_lastLoaded, crl::now());
|
const auto was = std::exchange(_lastLoaded, crl::now());
|
||||||
if (!was) {
|
if (!was) {
|
||||||
|
|
|
@ -41,12 +41,15 @@ public:
|
||||||
void apply(const MTPDupdateStarsBalance &data);
|
void apply(const MTPDupdateStarsBalance &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateNonLockedValue();
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
|
|
||||||
std::unique_ptr<Api::CreditsStatus> _loader;
|
std::unique_ptr<Api::CreditsStatus> _loader;
|
||||||
|
|
||||||
rpl::variable<uint64> _balance;
|
uint64 _balance = 0;
|
||||||
rpl::variable<uint64> _locked;
|
uint64 _locked = 0;
|
||||||
|
rpl::variable<uint64> _nonLockedBalance;
|
||||||
rpl::event_stream<> _loadedChanges;
|
rpl::event_stream<> _loadedChanges;
|
||||||
crl::time _lastLoaded = 0;
|
crl::time _lastLoaded = 0;
|
||||||
float64 _rate = 0.;
|
float64 _rate = 0.;
|
||||||
|
|
|
@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_wall_paper.h"
|
#include "data/data_wall_paper.h"
|
||||||
#include "data/data_media_types.h"
|
#include "data/data_media_types.h"
|
||||||
|
#include "data/data_user.h"
|
||||||
#include "history/view/history_view_element.h"
|
#include "history/view/history_view_element.h"
|
||||||
#include "history/view/media/history_view_media_grouped.h"
|
#include "history/view/media/history_view_media_grouped.h"
|
||||||
#include "history/view/media/history_view_photo.h"
|
#include "history/view/media/history_view_photo.h"
|
||||||
|
@ -210,16 +211,29 @@ void ShowPaidMediaUnlockedToast(
|
||||||
const auto broadcast = (sender && sender->isBroadcast())
|
const auto broadcast = (sender && sender->isBroadcast())
|
||||||
? sender
|
? sender
|
||||||
: item->history()->peer.get();
|
: item->history()->peer.get();
|
||||||
|
const auto user = item->viaBot()
|
||||||
|
? item->viaBot()
|
||||||
|
: item->originalSender()
|
||||||
|
? item->originalSender()->asUser()
|
||||||
|
: nullptr;
|
||||||
auto text = tr::lng_credits_media_done_title(
|
auto text = tr::lng_credits_media_done_title(
|
||||||
tr::now,
|
tr::now,
|
||||||
Ui::Text::Bold
|
Ui::Text::Bold
|
||||||
).append('\n').append(tr::lng_credits_media_done_text(
|
).append('\n').append(user
|
||||||
tr::now,
|
? tr::lng_credits_media_done_text_user(
|
||||||
lt_count,
|
tr::now,
|
||||||
invoice->amount,
|
lt_count,
|
||||||
lt_chat,
|
invoice->amount,
|
||||||
Ui::Text::Bold(broadcast->name()),
|
lt_user,
|
||||||
Ui::Text::RichLangValue));
|
Ui::Text::Bold(user->shortName()),
|
||||||
|
Ui::Text::RichLangValue)
|
||||||
|
: tr::lng_credits_media_done_text(
|
||||||
|
tr::now,
|
||||||
|
lt_count,
|
||||||
|
invoice->amount,
|
||||||
|
lt_chat,
|
||||||
|
Ui::Text::Bold(broadcast->name()),
|
||||||
|
Ui::Text::RichLangValue));
|
||||||
controller->showToast(std::move(text), kMediaUnlockedTooltipDuration);
|
controller->showToast(std::move(text), kMediaUnlockedTooltipDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue