Add 'Clear History' to channels as auto-delete entry point.

This commit is contained in:
John Preston 2021-02-15 14:57:07 +04:00
parent 781e7a2e79
commit 14d525dade
3 changed files with 25 additions and 7 deletions

View file

@ -1073,6 +1073,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_sure_leave_group" = "Are you sure you want to leave this group?";
"lng_sure_delete_group" = "Are you sure, you want to delete this group? All members will be removed and all messages will be lost.";
"lng_sure_delete_saved_messages" = "Are you sure, you want to delete all your saved messages?\n\nThis action cannot be undone.";
"lng_no_clear_history_channel" = "In channels you can enable auto-delete for messages.";
"lng_no_clear_history_group" = "In public groups you can enable auto-delete for messages.";
"lng_message_empty" = "Empty Message";
"lng_message_unsupported" = "This message is not supported by your version of Telegram Desktop. Please update to the latest version in Settings, or install it from {link}";

View file

@ -583,9 +583,20 @@ void DeleteMessagesBox::prepare() {
auto deleteText = lifetime().make_state<rpl::variable<QString>>();
*deleteText = tr::lng_box_delete();
auto deleteStyle = &st::defaultBoxButton;
auto canDelete = true;
if (const auto peer = _wipeHistoryPeer) {
if (_wipeHistoryJustClear) {
details.text = peer->isSelf()
const auto isChannel = peer->isBroadcast();
const auto isPublicGroup = peer->isMegagroup()
&& peer->asChannel()->isPublic();
if (isChannel || isPublicGroup) {
canDelete = false;
}
details.text = isChannel
? tr::lng_no_clear_history_channel(tr::now)
: isPublicGroup
? tr::lng_no_clear_history_group(tr::now)
: peer->isSelf()
? tr::lng_sure_delete_saved_messages(tr::now)
: peer->isUser()
? tr::lng_sure_delete_history(tr::now, lt_contact, peer->name)
@ -671,11 +682,15 @@ void DeleteMessagesBox::prepare() {
});
}
addButton(
deleteText->value(),
[=] { deleteAndClear(); },
*deleteStyle);
addButton(tr::lng_cancel(), [=] { closeBox(); });
if (canDelete) {
addButton(
deleteText->value(),
[=] { deleteAndClear(); },
*deleteStyle);
addButton(tr::lng_cancel(), [=] { closeBox(); });
} else {
addButton(tr::lng_about_done(), [=] { closeBox(); });
}
auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom();
if (_moderateFrom) {

View file

@ -582,7 +582,8 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
}
}
if (channel->amIn()) {
if (isGroup && !channel->isPublic()) {
if ((isGroup && !channel->isPublic())
|| channel->canDeleteMessages()) {
_addAction(
tr::lng_profile_clear_history(tr::now),
ClearHistoryHandler(channel));