mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Payment service messages supported.
This commit is contained in:
parent
2019c24e08
commit
7b5985445c
5 changed files with 63 additions and 13 deletions
|
@ -670,6 +670,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
"lng_action_call_incoming_duration" = "Incoming call ({duration}) at {time}";
|
||||
"lng_action_call_incoming_missed" = "Missed call at {time}";
|
||||
"lng_action_call_outgoing_missed" = "Cancelled call at {time}";
|
||||
"lng_action_payment_done" = "You have just successfully transferred {amount} to {user}";
|
||||
"lng_action_payment_done_for" = "You have just successfully transferred {amount} to {user} for {invoice}";
|
||||
|
||||
"lng_profile_migrate_reached" = "{count:_not_used_|# member|# members} limit reached";
|
||||
"lng_profile_migrate_body" = "To get over this limit, you can upgrade your group to a supergroup.";
|
||||
|
|
|
@ -3441,9 +3441,7 @@ HistoryInvoice::HistoryInvoice(HistoryItem *parent, const HistoryInvoice &other)
|
|||
, _status(other._status) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
QString fillAmountAndCurrency(int amount, const QString ¤cy) {
|
||||
QString HistoryInvoice::fillAmountAndCurrency(int amount, const QString ¤cy) {
|
||||
static auto shortCurrencyNames = QMap<QString, QString> {
|
||||
{ qsl("USD"), qsl("$") },
|
||||
{ qsl("GBP"), qsl("£") },
|
||||
|
@ -3457,8 +3455,6 @@ QString fillAmountAndCurrency(int amount, const QString ¤cy) {
|
|||
return currencyText + amountText;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void HistoryInvoice::fillFromData(const MTPDmessageMediaInvoice &data) {
|
||||
// init attach
|
||||
if (data.has_photo()) {
|
||||
|
|
|
@ -876,7 +876,7 @@ public:
|
|||
HistoryInvoice(HistoryItem *parent, const MTPDmessageMediaInvoice &data);
|
||||
HistoryInvoice(HistoryItem *parent, const HistoryInvoice &other);
|
||||
HistoryMediaType type() const override {
|
||||
return MediaTypeGame;
|
||||
return MediaTypeInvoice;
|
||||
}
|
||||
std::unique_ptr<HistoryMedia> clone(HistoryItem *newParent) const override {
|
||||
return std::make_unique<HistoryInvoice>(newParent, *this);
|
||||
|
@ -885,6 +885,11 @@ public:
|
|||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
QString getTitle() const {
|
||||
return _title.originalText();
|
||||
}
|
||||
static QString fillAmountAndCurrency(int amount, const QString ¤cy);
|
||||
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, TimeMs ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
|
|
|
@ -2011,6 +2011,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) {
|
|||
case mtpc_messageActionPinMessage: messageText = preparePinnedText(); break;
|
||||
case mtpc_messageActionGameScore: messageText = prepareGameScoreText(); break;
|
||||
case mtpc_messageActionPhoneCall: messageText = preparePhoneCallText(action.c_messageActionPhoneCall()); break;
|
||||
case mtpc_messageActionPaymentSent: messageText = preparePaymentSentText(); break;
|
||||
default: messageText.text = lang(lng_message_empty); break;
|
||||
}
|
||||
|
||||
|
@ -2151,16 +2152,16 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
|
|||
}
|
||||
|
||||
HistoryService::PreparedText HistoryService::prepareGameScoreText() {
|
||||
auto result = PreparedText { QString(), { peerOpenClickHandler(_from) } };
|
||||
auto result = PreparedText {};
|
||||
auto gamescore = Get<HistoryServiceGameScore>();
|
||||
|
||||
auto gameTitle = ([gamescore, &result]() -> QString {
|
||||
auto computeGameTitle = [gamescore, &result]() -> QString {
|
||||
if (gamescore && gamescore->msg) {
|
||||
if (auto media = gamescore->msg->getMedia()) {
|
||||
if (media->type() == MediaTypeGame) {
|
||||
result.links.push_back(MakeShared<ReplyMarkupClickHandler>(gamescore->msg, 0, 0));
|
||||
auto titleText = static_cast<HistoryGame*>(media)->game()->title;
|
||||
return textcmdLink(2, titleText);
|
||||
return textcmdLink(result.links.size(), titleText);
|
||||
}
|
||||
}
|
||||
return lang(lng_deleted_message);
|
||||
|
@ -2168,26 +2169,54 @@ HistoryService::PreparedText HistoryService::prepareGameScoreText() {
|
|||
return lang(lng_contacts_loading);
|
||||
}
|
||||
return QString();
|
||||
})();
|
||||
};
|
||||
|
||||
auto scoreNumber = gamescore ? gamescore->score : 0;
|
||||
if (_from->isSelf()) {
|
||||
auto gameTitle = computeGameTitle();
|
||||
if (gameTitle.isEmpty()) {
|
||||
result.text = lng_action_game_you_scored_no_game(lt_count, scoreNumber);
|
||||
} else {
|
||||
result.text = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle);
|
||||
}
|
||||
} else {
|
||||
auto from = textcmdLink(1, _from->name);
|
||||
result.links.push_back(fromLink());
|
||||
auto gameTitle = computeGameTitle();
|
||||
if (gameTitle.isEmpty()) {
|
||||
result.text = lng_action_game_score_no_game(lt_from, from, lt_count, scoreNumber);
|
||||
result.text = lng_action_game_score_no_game(lt_from, fromLinkText(), lt_count, scoreNumber);
|
||||
} else {
|
||||
result.text = lng_action_game_score(lt_from, from, lt_count, scoreNumber, lt_game, gameTitle);
|
||||
result.text = lng_action_game_score(lt_from, fromLinkText(), lt_count, scoreNumber, lt_game, gameTitle);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HistoryService::PreparedText HistoryService::preparePaymentSentText() {
|
||||
auto result = PreparedText {};
|
||||
auto payment = Get<HistoryServicePayment>();
|
||||
|
||||
auto invoiceTitle = ([payment]() -> QString {
|
||||
if (payment && payment->msg) {
|
||||
if (auto media = payment->msg->getMedia()) {
|
||||
if (media->type() == MediaTypeInvoice) {
|
||||
return static_cast<HistoryInvoice*>(media)->getTitle();
|
||||
}
|
||||
}
|
||||
return lang(lng_deleted_message);
|
||||
} else if (payment && payment->msgId) {
|
||||
return lang(lng_contacts_loading);
|
||||
}
|
||||
return QString();
|
||||
})();
|
||||
|
||||
if (invoiceTitle.isEmpty()) {
|
||||
result.text = lng_action_payment_done(lt_amount, payment->amount, lt_user, history()->peer->name);
|
||||
} else {
|
||||
result.text = lng_action_payment_done_for(lt_amount, payment->amount, lt_user, history()->peer->name, lt_invoice, invoiceTitle);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HistoryService::HistoryService(History *history, const MTPDmessageService &msg) :
|
||||
HistoryItem(history, msg.vid.v, mtpCastFlags(msg.vflags.v), ::date(msg.vdate), msg.has_from_id() ? msg.vfrom_id.v : 0) {
|
||||
createFromMtp(msg);
|
||||
|
@ -2366,6 +2395,10 @@ HistoryTextState HistoryService::getState(int x, int y, HistoryStateRequest requ
|
|||
if (!result.link && result.cursor == HistoryInTextCursorState && outer.contains(x, y)) {
|
||||
result.link = gamescore->lnk;
|
||||
}
|
||||
} else if (auto payment = Get<HistoryServicePayment>()) {
|
||||
if (!result.link && result.cursor == HistoryInTextCursorState && outer.contains(x, y)) {
|
||||
result.link = payment->lnk;
|
||||
}
|
||||
}
|
||||
} else if (_media) {
|
||||
result = _media->getState(x - st::msgServiceMargin.left() - (width - _media->maxWidth()) / 2, y - st::msgServiceMargin.top() - height - st::msgServiceMargin.top(), request);
|
||||
|
@ -2377,6 +2410,11 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) {
|
|||
if (message.vaction.type() == mtpc_messageActionGameScore) {
|
||||
UpdateComponents(HistoryServiceGameScore::Bit());
|
||||
Get<HistoryServiceGameScore>()->score = message.vaction.c_messageActionGameScore().vscore.v;
|
||||
} else if (message.vaction.type() == mtpc_messageActionPaymentSent) {
|
||||
UpdateComponents(HistoryServicePayment::Bit());
|
||||
auto amount = message.vaction.c_messageActionPaymentSent().vtotal_amount.v;
|
||||
auto currency = qs(message.vaction.c_messageActionPaymentSent().vcurrency);
|
||||
Get<HistoryServicePayment>()->amount = HistoryInvoice::fillAmountAndCurrency(amount, currency);
|
||||
}
|
||||
if (message.has_reply_to_msg_id()) {
|
||||
if (message.vaction.type() == mtpc_messageActionPinMessage) {
|
||||
|
@ -2447,6 +2485,8 @@ void HistoryService::updateDependentText() {
|
|||
text = preparePinnedText();
|
||||
} else if (Has<HistoryServiceGameScore>()) {
|
||||
text = prepareGameScoreText();
|
||||
} else if (Has<HistoryServicePayment>()) {
|
||||
text = preparePaymentSentText();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -250,6 +250,10 @@ struct HistoryServiceGameScore : public RuntimeComponent<HistoryServiceGameScore
|
|||
int score = 0;
|
||||
};
|
||||
|
||||
struct HistoryServicePayment : public RuntimeComponent<HistoryServicePayment>, public HistoryServiceDependentData {
|
||||
QString amount;
|
||||
};
|
||||
|
||||
namespace HistoryLayout {
|
||||
class ServiceMessagePainter;
|
||||
} // namespace HistoryLayout
|
||||
|
@ -344,6 +348,8 @@ private:
|
|||
return pinned;
|
||||
} else if (auto gamescore = Get<HistoryServiceGameScore>()) {
|
||||
return gamescore;
|
||||
} else if (auto payment = Get<HistoryServicePayment>()) {
|
||||
return payment;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -359,6 +365,7 @@ private:
|
|||
|
||||
PreparedText preparePinnedText();
|
||||
PreparedText prepareGameScoreText();
|
||||
PreparedText preparePaymentSentText();
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue