diff --git a/Telegram/SourceFiles/core/credits_amount.h b/Telegram/SourceFiles/core/credits_amount.h index e4c3a2d09f..098266d887 100644 --- a/Telegram/SourceFiles/core/credits_amount.h +++ b/Telegram/SourceFiles/core/credits_amount.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/algorithm.h" #include "base/basic_types.h" class MTPstarsAmount; @@ -77,6 +78,17 @@ public: return !empty(); } + [[nodiscard]] CreditsAmount multiplied(float64 rate) const { + const auto result = value() * rate; + const auto abs = std::abs(result); + const auto whole = std::floor(abs); + const auto nano = base::SafeRound((abs - whole) * kOneStarInNano); + return CreditsAmount( + (result < 0) ? -whole : whole, + (result < 0) ? -nano : nano, + type()); + } + inline CreditsAmount &operator+=(CreditsAmount other) { _whole += other._whole; _nano += other._nano; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp index ba27d9fd86..14767395db 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "history/history_item_components.h" +#include "info/channel_statistics/earn/earn_format.h" #include "info/channel_statistics/earn/earn_icons.h" #include "lang/lang_keys.h" #include "lottie/lottie_icon.h" @@ -93,8 +94,7 @@ void AddApproximateUsd( const auto rate = amount.ton() ? appConfig->currencyWithdrawRate() : (appConfig->starsWithdrawRate() / 100.); - const auto precise = amount.value() * rate; - return u"~$"_q + QString::number(precise, 'f', 2); + return Info::ChannelEarn::ToUsd(amount, rate, 2); }); const auto usd = Ui::CreateChild( field, @@ -677,13 +677,10 @@ CreditsAmount PriceAfterCommission( const auto mul = price.stars() ? appConfig->suggestedPostCommissionStars() : appConfig->suggestedPostCommissionTon(); - - const auto value = (price.value() * mul / 1000.); - const auto whole = int(std::floor(value)); - const auto nano = price.stars() - ? 0 - : int(base::SafeRound((value - whole) * Ui::kNanosInOne)); - return CreditsAmount(whole, nano, price.type()); + const auto exact = price.multiplied(mul / 1000.); + return price.stars() + ? CreditsAmount(exact.whole(), 0, CreditsType::Stars) + : exact; } QString FormatAfterCommissionPercent( diff --git a/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp b/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp index f063510cb9..b8b0b6f1c5 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_todo_list.cpp @@ -177,7 +177,9 @@ QSize TodoList::countOptimalSize() { } bool TodoList::canComplete() const { - return (_parent->data()->out() || _todolist->othersCanComplete()) + return (_parent->data()->out() + || _parent->history()->peer->isSelf() + || _todolist->othersCanComplete()) && _parent->data()->isRegular() && !_parent->data()->Has(); } diff --git a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp index 0e4451f27f..cdc8dc29f2 100644 --- a/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp +++ b/Telegram/SourceFiles/statistics/view/chart_rulers_view.cpp @@ -45,14 +45,17 @@ void ChartRulersView::setChartData( _leftCustomCaption = [=](float64 value) { return FormatF(value / float64(kOneStarInNano)); }; + _rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) { + return Info::ChannelEarn::ToUsd(v / float64(kOneStarInNano), rate, 0); + }; } else { _leftCustomCaption = [=](float64 value) { return FormatF(value); }; + _rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) { + return Info::ChannelEarn::ToUsd(v, rate, 0); + }; } - _rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) { - return Info::ChannelEarn::ToUsd(v, rate, 0); - }; _rightPen = QPen(st::windowSubTextFg); } if (_isDouble && (chartData.lines.size() == 2)) { diff --git a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp index d3f0afbdad..97704994aa 100644 --- a/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp +++ b/Telegram/SourceFiles/statistics/widgets/point_details_widget.cpp @@ -186,7 +186,7 @@ PointDetailsWidget::PointDetailsWidget( const auto usdText = Ui::Text::String( _textStyle, Info::ChannelEarn::ToUsd( - value, + value / multiplier, _chartData.currencyRate, 0)); const auto width = std::max( @@ -361,7 +361,7 @@ void PointDetailsWidget::setXIndex(int xIndex) { textLine.value.setText( _textStyle, Info::ChannelEarn::ToUsd( - dataLine.y[xIndex], + dataLine.y[xIndex] / multiplier, _chartData.currencyRate, 0)); } _lines.push_back(std::move(textLine));