From 261a83eda352786c083824d29b2a77e8af3f881e Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Mon, 7 Oct 2019 17:35:22 +0300 Subject: [PATCH] Show restricted date to user (#6642) * Show restricted date to user * Fixed attach button toast * Fixed attach button toast in scheduled messages --- Telegram/Resources/langs/lang.strings | 7 ++++ Telegram/SourceFiles/data/data_peer.cpp | 32 +++++++++++++++++++ .../SourceFiles/history/history_widget.cpp | 2 +- .../view/history_view_scheduled_section.cpp | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7afb4b7bc9..5b6d8f672e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1768,6 +1768,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_restricted_send_inline" = "The admins of this group restricted you from posting inline content here."; "lng_restricted_send_polls" = "The admins of this group restricted you from posting polls here."; +"lng_restricted_send_message_until" = "The admins of this group restricted you from writing here until {date}, {time}."; +"lng_restricted_send_media_until" = "The admins of this group restricted you from posting media content here until {date}, {time}."; +"lng_restricted_send_stickers_until" = "The admins of this group restricted you from posting stickers here until {date}, {time}."; +"lng_restricted_send_gifs_until" = "The admins of this group restricted you from posting GIFs here until {date}, {time}."; +"lng_restricted_send_inline_until" = "The admins of this group restricted you from posting inline content here until {date}, {time}."; +"lng_restricted_send_polls_until" = "The admins of this group restricted you from posting polls here until {date}, {time}."; + "lng_restricted_send_message_all" = "Writing messages isn't allowed in this group."; "lng_restricted_send_media_all" = "Posting media content isn't allowed in this group."; "lng_restricted_send_stickers_all" = "Posting stickers isn't allowed in this group."; diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index de36eab498..cfb91084e1 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -754,6 +754,38 @@ std::optional RestrictionError( using Flag = ChatRestriction; if (const auto restricted = peer->amRestricted(restriction)) { const auto all = restricted.isWithEveryone(); + const auto channel = peer->asChannel(); + if (!all && channel) { + auto restrictedUntil = channel->restrictedUntil(); + if (restrictedUntil > 0 && !ChannelData::IsRestrictedForever(restrictedUntil)) { + auto restrictedUntilDateTime = base::unixtime::parse(channel->restrictedUntil()); + auto date = restrictedUntilDateTime.toString(qsl("dd.MM.yy")); + auto time = restrictedUntilDateTime.toString(cTimeFormat()); + + switch (restriction) { + case Flag::f_send_polls: + return tr::lng_restricted_send_polls_until( + tr::now, lt_date, date, lt_time, time); + case Flag::f_send_messages: + return tr::lng_restricted_send_message_until( + tr::now, lt_date, date, lt_time, time); + case Flag::f_send_media: + return tr::lng_restricted_send_media_until( + tr::now, lt_date, date, lt_time, time); + case Flag::f_send_stickers: + return tr::lng_restricted_send_stickers_until( + tr::now, lt_date, date, lt_time, time); + case Flag::f_send_gifs: + return tr::lng_restricted_send_gifs_until( + tr::now, lt_date, date, lt_time, time); + case Flag::f_send_inline: + case Flag::f_send_games: + return tr::lng_restricted_send_inline_until( + tr::now, lt_date, date, lt_time, time); + } + Unexpected("Restriction in Data::RestrictionErrorKey."); + } + } switch (restriction) { case Flag::f_send_polls: return all diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 320d11a645..fd549bf9af 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3219,7 +3219,7 @@ void HistoryWidget::chooseAttach() { } else if (const auto error = Data::RestrictionError( _peer, ChatRestriction::f_send_media)) { - Ui::Toast::Show(*error); + ShowErrorToast(*error); return; } else if (showSlowmodeError()) { return; diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 9e51ada7ea..f2813348f6 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -170,7 +170,7 @@ void ScheduledWidget::chooseAttach() { if (const auto error = Data::RestrictionError( _history->peer, ChatRestriction::f_send_media)) { - Ui::Toast::Show(*error); + ShowErrorToast(*error); return; }