diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 8fd1f5c2b..9819c855c 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -12,12 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "ui/boxes/confirm_box.h" #include "boxes/abstract_box.h" -#include "boxes/peer_list_controllers.h" #include "boxes/premium_limits_box.h" #include "boxes/peers/add_participants_box.h" #include "boxes/peers/edit_peer_common.h" #include "boxes/peers/edit_participant_box.h" -#include "boxes/peers/edit_participants_box.h" #include "core/application.h" #include "core/core_settings.h" #include "chat_helpers/emoji_suggestions_widget.h" @@ -27,34 +25,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "menu/menu_ttl.h" #include "ui/controls/userpic_button.h" #include "ui/widgets/checkbox.h" -#include "ui/widgets/buttons.h" -#include "ui/widgets/labels.h" #include "ui/toast/toast.h" #include "ui/widgets/fields/input_field.h" #include "ui/widgets/fields/special_fields.h" #include "ui/widgets/popup_menu.h" #include "ui/text/format_values.h" -#include "ui/text/text_options.h" #include "ui/text/text_utilities.h" -#include "ui/unread_badge.h" -#include "ui/ui_utility.h" #include "ui/painter.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" #include "data/data_session.h" #include "data/data_changes.h" -#include "data/data_cloud_file.h" #include "apiwrap.h" #include "api/api_invite_links.h" #include "api/api_peer_photo.h" +#include "api/api_self_destruct.h" #include "main/main_session.h" #include "styles/style_info.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" -#include "styles/style_boxes.h" -#include "styles/style_dialogs.h" -#include "styles/style_widgets.h" #include #include @@ -599,6 +589,8 @@ void GroupInfoBox::prepare() { addButton(tr::lng_cancel(), [this] { closeBox(); }); if (_type == Type::Group) { + _navigation->session().api().selfDestruct().reload(); + const auto top = addTopButton(st::infoTopBarMenu); const auto menu = top->lifetime().make_state>(); @@ -607,21 +599,21 @@ void GroupInfoBox::prepare() { top, st::popupMenuWithIcons); + const auto ttl = ttlPeriod(); const auto text = tr::lng_manage_messages_ttl_menu(tr::now) - + (_ttlPeriod - ? ('\t' + Ui::FormatTTLTiny(_ttlPeriod)) - : QString()); + + (ttl ? ('\t' + Ui::FormatTTLTiny(ttl)) : QString()); (*menu)->addAction( text, [=, show = uiShow()] { show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ .show = show, - .startTtl = _ttlPeriod, + .startTtl = ttlPeriod(), .about = nullptr, .callback = crl::guard(this, [=]( TimeId t, Fn close) { _ttlPeriod = t; + _ttlPeriodOverridden = true; close(); }), })); @@ -687,6 +679,13 @@ void GroupInfoBox::submitName() { } } +TimeId GroupInfoBox::ttlPeriod() const { + return _ttlPeriodOverridden + ? _ttlPeriod + : _navigation->session().api().selfDestruct() + .periodDefaultHistoryTTLCurrent(); +} + void GroupInfoBox::createGroup( QPointer selectUsersBox, const QString &title, @@ -705,15 +704,13 @@ void GroupInfoBox::createGroup( } } _creationRequestId = _api.request(MTPmessages_CreateChat( - MTP_flags(_ttlPeriod - ? MTPmessages_CreateChat::Flag::f_ttl_period - : MTPmessages_CreateChat::Flags(0)), + MTP_flags(MTPmessages_CreateChat::Flag::f_ttl_period), MTP_vector(inputs), MTP_string(title), - MTP_int(_ttlPeriod) + MTP_int(ttlPeriod()) )).done([=](const MTPUpdates &result) { auto image = _photo->takeResultImage(); - const auto period = _ttlPeriod; + const auto period = ttlPeriod(); const auto navigation = _navigation; const auto done = _done; @@ -799,16 +796,17 @@ void GroupInfoBox::createChannel( ? Flag::f_megagroup : Flag::f_broadcast) | ((_type == Type::Forum) ? Flag::f_forum : Flag()) - | ((_type == Type::Megagroup && _ttlPeriod) + | ((_type == Type::Megagroup) ? MTPchannels_CreateChannel::Flag::f_ttl_period : MTPchannels_CreateChannel::Flags(0)); + const auto ttl = ttlPeriod(); _creationRequestId = _api.request(MTPchannels_CreateChannel( MTP_flags(flags), MTP_string(title), MTP_string(description), MTPInputGeoPoint(), // geo_point MTPstring(), // address - MTP_int((_type == Type::Megagroup) ? _ttlPeriod : 0) + MTP_int((_type == Type::Megagroup) ? ttl : 0) )).done([=](const MTPUpdates &result) { _navigation->session().api().applyUpdates(result); @@ -841,8 +839,8 @@ void GroupInfoBox::createChannel( channel, { std::move(image) }); } - if (_ttlPeriod && channel->isMegagroup()) { - channel->setMessagesTTL(_ttlPeriod); + if (ttl && channel->isMegagroup()) { + channel->setMessagesTTL(ttl); } channel->session().api().requestFullPeer(channel); _createdChannel = channel; diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index ef70f7c3b..6d19a2d7f 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -132,6 +132,8 @@ private: void descriptionResized(); void updateMaxHeight(); + [[nodiscard]] TimeId ttlPeriod() const; + const not_null _navigation; MTP::Sender _api; @@ -150,6 +152,7 @@ private: bool _creatingInviteLink = false; ChannelData *_createdChannel = nullptr; TimeId _ttlPeriod = 0; + bool _ttlPeriodOverridden = false; };