diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index a9243a7d6..2d2a3faf6 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -21,12 +21,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_suggestions_widget.h" #include "countries/countries_instance.h" // Countries::ExtractPhoneCode. #include "window/window_session_controller.h" +#include "menu/menu_ttl.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/toast/toast.h" #include "ui/special_buttons.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" @@ -42,7 +45,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_invite_links.h" #include "api/api_peer_photo.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" @@ -66,6 +71,7 @@ bool IsValidPhone(QString phone) { void ChatCreateDone( not_null navigation, QImage image, + TimeId ttlPeriod, const MTPUpdates &updates) { navigation->session().api().applyUpdates(updates); @@ -97,6 +103,9 @@ void ChatCreateDone( chat, std::move(image)); } + if (ttlPeriod) { + chat->setMessagesTTL(ttlPeriod); + } navigation->showPeerHistory(chat); }; if (!success) { @@ -516,6 +525,39 @@ void GroupInfoBox::prepare() { [=] { submit(); }); addButton(tr::lng_cancel(), [this] { closeBox(); }); + if (_type == Type::Group) { + const auto top = addTopButton(st::infoTopBarMenu); + const auto menu = + top->lifetime().make_state>(); + top->setClickedCallback([=] { + *menu = base::make_unique_q( + top, + st::popupMenuWithIcons); + + const auto text = tr::lng_manage_messages_ttl_menu(tr::now) + + (_ttlPeriod + ? ('\t' + Ui::FormatTTLTiny(_ttlPeriod)) + : QString()); + (*menu)->addAction( + text, + [=, show = std::make_shared(this)] { + show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ + .show = show, + .startTtl = _ttlPeriod, + .about = nullptr, + .callback = crl::guard(this, [=]( + TimeId t, + Fn close) { + _ttlPeriod = t; + close(); + }), + })); + }, &st::menuIconTTL); + (*menu)->popup(QCursor::pos()); + return true; + }); + } + updateMaxHeight(); } @@ -593,16 +635,18 @@ void GroupInfoBox::createGroup( return; } _creationRequestId = _api.request(MTPmessages_CreateChat( - MTP_flags(0), + MTP_flags(_ttlPeriod + ? MTPmessages_CreateChat::Flag::f_ttl_period + : MTPmessages_CreateChat::Flags(0)), MTP_vector(inputs), MTP_string(title), - MTPint() // ttl_period + MTP_int(_ttlPeriod) )).done([=](const MTPUpdates &result) { auto image = _photo->takeResultImage(); const auto navigation = _navigation; getDelegate()->hideLayer(); // Destroys 'this'. - ChatCreateDone(navigation, std::move(image), result); + ChatCreateDone(navigation, std::move(image), _ttlPeriod, result); }).fail([=](const MTP::Error &error) { const auto &type = error.type(); _creationRequestId = 0; @@ -678,16 +722,19 @@ void GroupInfoBox::createChannel( const QString &description) { Expects(!_creationRequestId); - const auto flags = (_type == Type::Megagroup) - ? MTPchannels_CreateChannel::Flag::f_megagroup - : MTPchannels_CreateChannel::Flag::f_broadcast; + const auto flags = ((_type == Type::Megagroup) + ? MTPchannels_CreateChannel::Flag::f_megagroup + : MTPchannels_CreateChannel::Flag::f_broadcast) + | (_ttlPeriod + ? MTPchannels_CreateChannel::Flag::f_ttl_period + : MTPchannels_CreateChannel::Flags(0)); _creationRequestId = _api.request(MTPchannels_CreateChannel( MTP_flags(flags), MTP_string(title), MTP_string(description), MTPInputGeoPoint(), // geo_point MTPstring(), // address - MTPint() // ttl_period + MTP_int((_type == Type::Megagroup) ? _ttlPeriod : 0) )).done([=](const MTPUpdates &result) { _navigation->session().api().applyUpdates(result); @@ -720,6 +767,9 @@ void GroupInfoBox::createChannel( channel, std::move(image)); } + if (_ttlPeriod && channel->isMegagroup()) { + channel->setMessagesTTL(_ttlPeriod); + } channel->session().api().requestFullPeer(channel); _createdChannel = channel; checkInviteLink(); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index 8900a8a24..bc4bb2dcf 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -139,6 +139,7 @@ private: mtpRequestId _creationRequestId = 0; bool _creatingInviteLink = false; ChannelData *_createdChannel = nullptr; + TimeId _ttlPeriod = 0; }; diff --git a/Telegram/SourceFiles/menu/menu_ttl.cpp b/Telegram/SourceFiles/menu/menu_ttl.cpp index ca27d0f63..2d067c872 100644 --- a/Telegram/SourceFiles/menu/menu_ttl.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl.cpp @@ -190,7 +190,9 @@ void TTLBox(not_null box, Args args) { const auto pickerTtl = TimePickerBox(box, ttls, phrases, args.startTtl); Ui::ConfirmBox(box, { - .confirmed = [=] { args.callback(pickerTtl()); }, + .confirmed = [=](Fn close) { + args.callback(pickerTtl(), std::move(close)); + }, .confirmText = tr::lng_settings_save(), .cancelText = tr::lng_cancel(), }); @@ -199,7 +201,7 @@ void TTLBox(not_null box, Args args) { if (args.startTtl && !args.hideDisable) { box->addLeftButton(tr::lng_manage_messages_ttl_disable(), [=] { - args.callback(0); + args.callback(0, [=] { box->closeBox(); }); box->getDelegate()->hideLayer(); }); } diff --git a/Telegram/SourceFiles/menu/menu_ttl.h b/Telegram/SourceFiles/menu/menu_ttl.h index a70f419b5..86437e7d9 100644 --- a/Telegram/SourceFiles/menu/menu_ttl.h +++ b/Telegram/SourceFiles/menu/menu_ttl.h @@ -22,7 +22,7 @@ struct Args { std::shared_ptr show; TimeId startTtl; rpl::producer about; - Fn callback; + Fn)> callback; bool hideDisable = false; }; diff --git a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp index 93ea0a227..a81108a1b 100644 --- a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp @@ -68,7 +68,9 @@ Args TTLValidator::createArgs() const { mtpRequestId savingRequestId = 0; }; const auto state = std::make_shared(); - auto callback = [=, toastParent = show->toastParent()](TimeId period) { + auto callback = [=, toastParent = show->toastParent()]( + TimeId period, + Fn) { auto &api = peer->session().api(); if (state->savingRequestId) { if (period == state->savingPeriod) { @@ -84,11 +86,6 @@ Args TTLValidator::createArgs() const { peer->session().api().applyUpdates(result); ShowAutoDeleteToast(toastParent, peer); state->savingRequestId = 0; -#if 0 - if (const auto strong = state->weak.data()) { - strong->closeBox(); - } -#endif }).fail([=] { state->savingRequestId = 0; }).send(); diff --git a/Telegram/SourceFiles/settings/settings_global_ttl.cpp b/Telegram/SourceFiles/settings/settings_global_ttl.cpp index 627f5cade..acb1d4656 100644 --- a/Telegram/SourceFiles/settings/settings_global_ttl.cpp +++ b/Telegram/SourceFiles/settings/settings_global_ttl.cpp @@ -356,7 +356,7 @@ void GlobalTTL::setupContent() { show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ .show = show, .startTtl = _group->value(), - .callback = [=](TimeId ttl) { showSure(ttl, true); }, + .callback = [=](TimeId ttl, Fn) { showSure(ttl, true); }, .hideDisable = true, })); });