Show restricted date to user (#6642)

* Show restricted date to user
* Fixed attach button toast
* Fixed attach button toast in scheduled messages
This commit is contained in:
RadRussianRus 2019-10-07 17:35:22 +03:00 committed by John Preston
parent 5f06279b9a
commit 261a83eda3
4 changed files with 41 additions and 2 deletions

View File

@ -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.";

View File

@ -754,6 +754,38 @@ std::optional<QString> 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

View File

@ -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;

View File

@ -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;
}