diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 29f0bad098..fdf645cbeb 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3518,6 +3518,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_forum_topic_edit" = "Edit Topic"; "lng_forum_topic_title" = "Topic Title"; "lng_forum_topic_closed" = "This topic is now closed."; +"lng_forum_topic_delete" = "Delete"; +"lng_forum_topic_delete_sure" = "Are you sure you want to delete this topic?"; "lng_forum_topics_switch" = "Topics"; "lng_forum_no_topics" = "No topics currently created in this forum."; "lng_forum_create_topic" = "Create topic"; diff --git a/Telegram/SourceFiles/api/api_attached_stickers.cpp b/Telegram/SourceFiles/api/api_attached_stickers.cpp index a100f6d95b..be87544be6 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.cpp +++ b/Telegram/SourceFiles/api/api_attached_stickers.cpp @@ -25,7 +25,7 @@ AttachedStickers::AttachedStickers(not_null api) void AttachedStickers::request( not_null controller, MTPmessages_GetAttachedStickers &&mtpRequest) { - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); _api.request(_requestId).cancel(); _requestId = _api.request( std::move(mtpRequest) diff --git a/Telegram/SourceFiles/api/api_bot.cpp b/Telegram/SourceFiles/api/api_bot.cpp index 43f0fd1b3f..a3ef5475b6 100644 --- a/Telegram/SourceFiles/api/api_bot.cpp +++ b/Telegram/SourceFiles/api/api_bot.cpp @@ -83,7 +83,7 @@ void SendBotCallbackData( if (withPassword) { flags |= MTPmessages_GetBotCallbackAnswer::Flag::f_password; } - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); const auto show = std::make_shared(controller); button->requestId = api->request(MTPmessages_GetBotCallbackAnswer( MTP_flags(flags), @@ -202,7 +202,7 @@ void SendBotCallbackDataWithPassword( return; } api->cloudPassword().reload(); - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); const auto show = std::make_shared(controller); SendBotCallbackData(controller, item, row, column, std::nullopt, [=](const QString &error) { auto box = PrePasswordErrorBox( diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 3f954c6c6c..8a5ae49875 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -107,7 +107,7 @@ void CheckChatInvite( const QString &hash, ChannelData *invitePeekChannel) { const auto session = &controller->session(); - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) { Core::App().hideMediaView(); result.match([=](const MTPDchatInvite &data) { diff --git a/Telegram/SourceFiles/api/api_toggling_media.cpp b/Telegram/SourceFiles/api/api_toggling_media.cpp index b67e3002de..9293043a81 100644 --- a/Telegram/SourceFiles/api/api_toggling_media.cpp +++ b/Telegram/SourceFiles/api/api_toggling_media.cpp @@ -66,7 +66,7 @@ void ToggleFavedSticker( if (faved && !document->sticker()) { return; } - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); auto done = [=] { document->owner().stickers().setFaved(weak.get(), document, faved); }; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 43079133c0..b7c397be02 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1815,7 +1815,7 @@ void ApiWrap::sendNotifySettingsUpdates() { } void ApiWrap::saveDraftToCloudDelayed(not_null thread) { - _draftsSaveRequestIds.emplace(base::make_weak(thread.get()), 0); + _draftsSaveRequestIds.emplace(base::make_weak(thread), 0); if (!_draftsSaveTimer.isActive()) { _draftsSaveTimer.callOnce(kSaveCloudDraftTimeout); } diff --git a/Telegram/SourceFiles/boxes/choose_filter_box.cpp b/Telegram/SourceFiles/boxes/choose_filter_box.cpp index d7fdaabbe1..a6b7d6ff4e 100644 --- a/Telegram/SourceFiles/boxes/choose_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/choose_filter_box.cpp @@ -148,7 +148,7 @@ void FillChooseFilterMenu( not_null controller, not_null menu, not_null history) { - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); const auto validator = ChooseFilterValidator(history); for (const auto &filter : history->owner().chatsFilters().list()) { const auto id = filter.id(); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index eccf38c8b0..60456fbd25 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/box_content_divider.h" #include "ui/text/text_utilities.h" -#include "ui/toast/toast.h" +#include "ui/toasts/common_toasts.h" #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_values.h" #include "boxes/peers/edit_participants_box.h" @@ -319,7 +319,7 @@ ChatAdminRights AdminRightsForOwnershipTransfer(bool isGroup) { Fn AboutGigagroupCallback( not_null channel, not_null controller) { - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); const auto converting = std::make_shared(); const auto convertSure = [=] { @@ -333,9 +333,10 @@ Fn AboutGigagroupCallback( channel->session().api().applyUpdates(result); if (const auto strongController = weak.get()) { strongController->window().hideSettingsAndLayer(); - Ui::Toast::Show( - strongController->widget(), - tr::lng_gigagroup_done(tr::now)); + Ui::ShowMultilineToast({ + .parentOverride = strongController->widget(), + .text = { tr::lng_gigagroup_done(tr::now) }, + }); } }).fail([=] { *converting = false; @@ -430,7 +431,8 @@ void EditPeerPermissionsBox::prepare() { disabledByAdminRights, tr::lng_rights_permission_cant_edit(tr::now)); if (const auto channel = _peer->asChannel()) { - if (channel->isPublic()) { + if (channel->isPublic() + || (channel->isMegagroup() && channel->linkedChat())) { result.emplace( Flag::ChangeInfo | Flag::PinMessages, tr::lng_rights_permission_unavailable(tr::now)); @@ -732,7 +734,10 @@ EditFlagsControl CreateEditFlags( ) | rpl::start_with_next([=](bool checked) { if (locked.has_value()) { if (checked != toggled) { - Ui::Toast::Show(parent, *locked); + Ui::ShowMultilineToast({ + .parentOverride = parent, + .text = { *locked }, + }); control->setChecked(toggled); } } else { diff --git a/Telegram/SourceFiles/boxes/premium_preview_box.cpp b/Telegram/SourceFiles/boxes/premium_preview_box.cpp index f410495b01..5d086001e6 100644 --- a/Telegram/SourceFiles/boxes/premium_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_preview_box.cpp @@ -1125,7 +1125,7 @@ void Show( } } - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); list.push_back({ .descriptor = descriptor, .media = (descriptor.requestedSticker diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 39240eb502..f18ab93247 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -1489,7 +1489,7 @@ void ShareGameScoreByHash( if (const auto item = session.data().message(peerId, msgId)) { FastShareMessage(controller, item); } else { - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); const auto resolveMessageAndShareScore = crl::guard(weak, [=]( PeerData *peer) { auto done = crl::guard(weak, [=] { diff --git a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp index 5a9f72d2cb..d5cb2f1452 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp @@ -193,7 +193,7 @@ object_ptr PrepareInviteBox( &st::groupCallInviteMembersList, &st::groupCallMultiSelect); - const auto weak = base::make_weak(call.get()); + const auto weak = base::make_weak(call); const auto invite = [=](const std::vector> &users) { const auto call = weak.get(); if (!call) { diff --git a/Telegram/SourceFiles/calls/group/calls_group_menu.cpp b/Telegram/SourceFiles/calls/group/calls_group_menu.cpp index 108441492f..d37085b29f 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_menu.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_menu.cpp @@ -455,7 +455,7 @@ void LeaveBox( st::boxRowPadding.right(), st::boxRowPadding.bottom())) : nullptr; - const auto weak = base::make_weak(call.get()); + const auto weak = base::make_weak(call); auto label = scheduled ? tr::lng_group_call_close() : tr::lng_group_call_leave(); @@ -488,7 +488,7 @@ void FillMenu( Fn chooseJoinAs, Fn chooseShareScreenSource, Fn)> showBox) { - const auto weak = base::make_weak(call.get()); + const auto weak = base::make_weak(call); const auto resolveReal = [=] { const auto real = peer->groupCall(); const auto strong = weak.get(); diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index d6da979664..76e0d0ef38 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -2552,7 +2552,7 @@ not_null Panel::widget() const { } Show::Show(not_null panel) -: _panel(base::make_weak(panel.get())) { +: _panel(base::make_weak(panel)) { } Show::~Show() = default; diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index 252b4be637..260f353d39 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -244,7 +244,7 @@ void SettingsBox( not_null call) { using namespace Settings; - const auto weakCall = base::make_weak(call.get()); + const auto weakCall = base::make_weak(call); const auto weakBox = Ui::MakeWeak(box); struct State { diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index 05360cf0f6..1a5efec605 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -167,7 +167,7 @@ void BotKeyboard::mouseReleaseEvent(QMouseEvent *e) { ActivateClickHandler(window(), activated, { e->button(), QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }) }); } diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 2a4fbc66ce..297b4837fc 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -435,7 +435,7 @@ void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) { ActivateClickHandler(window(), activated, { e->button(), QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }) }); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 827786c853..b56b700319 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -189,7 +189,7 @@ std::shared_ptr EmojiPack::image(EmojiPtr emoji) { } auto result = std::make_shared(); const auto raw = result.get(); - const auto weak = base::make_weak(_session.get()); + const auto weak = base::make_weak(_session); raw->load = [=] { Core::App().emojiImageLoader().with([=]( const EmojiImageLoader &loader) { diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp index 62e437dae2..fe36c825ca 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp @@ -49,7 +49,7 @@ auto LottieCachedFromContent( key, std::move(handler)); }; - const auto weak = base::make_weak(session.get()); + const auto weak = base::make_weak(session); const auto put = [=](QByteArray &&cached) { crl::on_main(weak, [=, data = std::move(cached)]() mutable { weak->data().cacheBigFile().put(key, std::move(data)); diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 7b97c31e53..e8a5cee73d 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -769,7 +769,7 @@ void Application::forceLogOut( })); box->setCloseByEscape(false); box->setCloseByOutsideClick(false); - const auto weak = base::make_weak(account.get()); + const auto weak = base::make_weak(account); connect(box, &QObject::destroyed, [=] { crl::on_main(weak, [=] { account->forcedLogOut(); diff --git a/Telegram/SourceFiles/data/data_download_manager.cpp b/Telegram/SourceFiles/data/data_download_manager.cpp index 2d08b0a8a5..b8bab17040 100644 --- a/Telegram/SourceFiles/data/data_download_manager.cpp +++ b/Telegram/SourceFiles/data/data_download_manager.cpp @@ -930,7 +930,7 @@ void DownloadManager::writePostponed(not_null session) { Fn()> DownloadManager::serializator( not_null session) const { - return [this, weak = base::make_weak(session.get())]() + return [this, weak = base::make_weak(session)]() -> std::optional { const auto strong = weak.get(); if (!strong) { diff --git a/Telegram/SourceFiles/data/data_forum.cpp b/Telegram/SourceFiles/data/data_forum.cpp index 539285cd81..ef67bd42b4 100644 --- a/Telegram/SourceFiles/data/data_forum.cpp +++ b/Telegram/SourceFiles/data/data_forum.cpp @@ -127,10 +127,13 @@ void Forum::applyReceivedTopics(const MTPmessages_ForumTopics &result) { void Forum::applyTopicDeleted(MsgId rootId) { const auto i = _topics.find(rootId); if (i != end(_topics)) { - Core::App().notifications().clearFromTopic(i->second.get()); - _topicDestroyed.fire(i->second.get()); - _history->destroyMessagesByTopic(rootId); + const auto raw = i->second.get(); + Core::App().notifications().clearFromTopic(raw); + owner().removeChatListEntry(raw); + _topicDestroyed.fire(raw); _topics.erase(i); + + _history->destroyMessagesByTopic(rootId); } } diff --git a/Telegram/SourceFiles/data/data_forum_topic.cpp b/Telegram/SourceFiles/data/data_forum_topic.cpp index 97b6514c69..31e179a356 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.cpp +++ b/Telegram/SourceFiles/data/data_forum_topic.cpp @@ -202,6 +202,13 @@ bool ForumTopic::canEdit() const { return (_flags & Flag::My) || channel()->canEditTopics(); } +bool ForumTopic::canDelete() const { + return !creating() + && (channel()->canEditTopics() + // We don't know if we can delete or not. + /*|| ((_flags & Flag::My) && onlyOneMyMessage)*/); +} + bool ForumTopic::canToggleClosed() const { return !creating() && canEdit(); } diff --git a/Telegram/SourceFiles/data/data_forum_topic.h b/Telegram/SourceFiles/data/data_forum_topic.h index 003cbbdd21..9bebe2eef1 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.h +++ b/Telegram/SourceFiles/data/data_forum_topic.h @@ -64,6 +64,7 @@ public: [[nodiscard]] bool canEdit() const; [[nodiscard]] bool canToggleClosed() const; [[nodiscard]] bool canTogglePinned() const; + [[nodiscard]] bool canDelete() const; [[nodiscard]] bool closed() const; void setClosed(bool closed); diff --git a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp index b90c290280..7a4cdb7ad7 100644 --- a/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp +++ b/Telegram/SourceFiles/data/stickers/data_custom_emoji.cpp @@ -628,7 +628,7 @@ auto CustomEmojiManager::createLoaderWithSetId( } } else { const auto i = SizeIndex(tag); - _loaders[i][documentId].push_back(base::make_weak(result.get())); + _loaders[i][documentId].push_back(base::make_weak(result)); _pendingForRequest.emplace(documentId); if (!_requestId && _pendingForRequest.size() == 1) { crl::on_main(this, [=] { request(); }); diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 6a86331262..3652e36214 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1659,7 +1659,7 @@ void InnerWidget::mouseActionFinish(const QPoint &screenPos, Qt::MouseButton but ? (ElementDelegate*)weak : nullptr; }, - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }) }); return; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index a4eedfc382..12d181bef6 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1836,7 +1836,7 @@ void HistoryInner::mouseActionFinish( : _mouseActionItem ? _mouseActionItem->fullId() : FullMsgId(); - const auto weak = base::make_weak(_controller.get()); + const auto weak = base::make_weak(_controller); mouseActionCancel(); ActivateClickHandler( window(), @@ -4176,7 +4176,7 @@ void HistoryInner::onParentGeometryChanged() { Fn HistoryInner::elementDelegateFactory( FullMsgId itemId) const { - const auto weak = base::make_weak(_controller.get()); + const auto weak = base::make_weak(_controller); return [=]() -> HistoryView::ElementDelegate* { if (const auto strong = weak.get()) { auto &data = strong->session().data(); @@ -4194,7 +4194,7 @@ ClickHandlerContext HistoryInner::prepareClickHandlerContext( return ClickHandlerContext{ .itemId = itemId, .elementDelegate = elementDelegateFactory(itemId), - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }; } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index cb68391996..019c086c1f 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -1439,7 +1439,7 @@ void AddEmojiPacksAction( menu->menu(), menu->st().menu, std::move(text)); - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); button->setClickedCallback([=] { const auto strong = weak.get(); if (!strong) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 14714e1c50..a5971937ab 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -3087,7 +3087,7 @@ void ListWidget::mouseActionFinish( ? (ElementDelegate*)weak : nullptr; }, - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }) }); return; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 6b45e3830f..779527b6c7 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -2862,7 +2862,7 @@ ClickHandlerPtr Message::rightActionLink() const { savedFromPeer->session().api().requestMessageData( savedFromPeer, savedFromMsgId, - [=, weak = base::make_weak(controller.get())] { + [=, weak = base::make_weak(controller)] { if (const auto strong = showByThreadWeak.lock()) { if (const auto strongController = weak.get()) { *prequested = 2; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index b66736c2d1..6b75f1370a 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -578,7 +578,7 @@ void RepliesWidget::setupComposeControls() { const auto topic = _topic ? _topic : _history->peer->forumTopicFor(_rootId); - return (topic->canToggleClosed() || !topic->closed()) + return (!topic || topic->canToggleClosed() || !topic->closed()) ? std::optional() : tr::lng_forum_topic_closed(tr::now); }); diff --git a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp index a230b55849..889bf0c642 100644 --- a/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp +++ b/Telegram/SourceFiles/history/view/history_view_spoiler_click_handler.cpp @@ -20,7 +20,7 @@ void FillTextWithAnimatedSpoilers( not_null view, Ui::Text::String &text) { if (text.hasSpoilers()) { - text.setSpoilerLinkFilter([weak = base::make_weak(view.get())]( + text.setSpoilerLinkFilter([weak = base::make_weak(view)]( const ClickContext &context) { const auto my = context.other.value(); const auto button = context.button; diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp index b12df0e2f2..d63225cb06 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp @@ -967,7 +967,7 @@ AttachSelectorResult MakeJustSelectorMenu( state.toggling); }, selector->lifetime()); - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); controller->enableGifPauseReason( Window::GifPauseReason::MediaPreview); QObject::connect(menu.get(), &QObject::destroyed, [weak] { @@ -1040,7 +1040,7 @@ AttachSelectorResult AttachSelectorToMenu( state.toggling); }, selector->lifetime()); - const auto weak = base::make_weak(controller.get()); + const auto weak = base::make_weak(controller); controller->enableGifPauseReason( Window::GifPauseReason::MediaPreview); QObject::connect(menu.get(), &QObject::destroyed, [weak] { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 4053c11a3b..e5b5b95cab 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -1726,7 +1726,7 @@ void ListWidget::mouseActionFinish( QVariant::fromValue(ClickHandlerContext{ .itemId = fullId, .sessionWindow = base::make_weak( - _controller->parentController().get()), + _controller->parentController()), }) }); return; diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index c91683ad07..81605435b4 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -293,7 +293,7 @@ object_ptr DetailsFiller::setupInfo() { const auto context = ClickContext{ button, QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(window.get()), + .sessionWindow = base::make_weak(window), .peer = peer, }) }; @@ -740,7 +740,7 @@ void ActionsFiller::addBotCommandActions(not_null user) { BotCommandClickHandler('/' + original).onClick(ClickContext{ Qt::LeftButton, QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(window.get()), + .sessionWindow = base::make_weak(window), .peer = user, }) }); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index 013c37beb2..7a2b22d5c3 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -253,7 +253,7 @@ void Inner::mouseReleaseEvent(QMouseEvent *e) { ActivateClickHandler(window(), activated, { e->button(), QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(_controller.get()), + .sessionWindow = base::make_weak(_controller), }) }); } diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp index 116991c06a..4447475847 100644 --- a/Telegram/SourceFiles/menu/menu_mute.cpp +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -112,7 +112,7 @@ MuteItem::MuteItem( st::defaultPopupMenu.showDuration); }, lifetime()); - const auto weak = base::make_weak(thread.get()); + const auto weak = base::make_weak(thread); setClickedCallback([=] { if (const auto strong = weak.get()) { strong->owner().notifySettings().update( @@ -161,7 +161,7 @@ void MuteBox(not_null box, not_null thread) { : tr::lng_mute_menu_mute(); }) | rpl::flatten_latest(); - const auto weak = base::make_weak(thread.get()); + const auto weak = base::make_weak(thread); Ui::ConfirmBox(box, { .confirmed = [=] { if (const auto strong = weak.get()) { @@ -191,7 +191,7 @@ void PickMuteBox( const auto pickerCallback = TimePickerBox(box, seconds, phrases, 0); - const auto weak = base::make_weak(thread.get()); + const auto weak = base::make_weak(thread); Ui::ConfirmBox(box, { .confirmed = [=] { const auto muteFor = pickerCallback(); @@ -240,7 +240,7 @@ void FillMuteMenu( not_null menu, not_null thread, std::shared_ptr show) { - const auto weak = base::make_weak(thread.get()); + const auto weak = base::make_weak(thread); const auto with = [=](Fn thread)> handler) { return [=] { if (const auto strong = weak.get()) { diff --git a/Telegram/SourceFiles/menu/menu_send.cpp b/Telegram/SourceFiles/menu/menu_send.cpp index 707e33bca0..370dd8ff99 100644 --- a/Telegram/SourceFiles/menu/menu_send.cpp +++ b/Telegram/SourceFiles/menu/menu_send.cpp @@ -225,7 +225,7 @@ void SetupUnreadMentionsMenu( const auto sendRequest = [=]( not_null thread, Fn done) { - sendOne(base::make_weak(thread.get()), std::move(done), sendOne); + sendOne(base::make_weak(thread), std::move(done), sendOne); }; SetupReadAllMenu(button, currentThread, text, sendRequest); } @@ -266,7 +266,7 @@ void SetupUnreadReactionsMenu( const auto sendRequest = [=]( not_null thread, Fn done) { - sendOne(base::make_weak(thread.get()), std::move(done), sendOne); + sendOne(base::make_weak(thread), std::move(done), sendOne); }; SetupReadAllMenu(button, currentThread, text, sendRequest); } diff --git a/Telegram/SourceFiles/mtproto/mtproto_concurrent_sender.cpp b/Telegram/SourceFiles/mtproto/mtproto_concurrent_sender.cpp index 93a00302d4..5bb4d5d205 100644 --- a/Telegram/SourceFiles/mtproto/mtproto_concurrent_sender.cpp +++ b/Telegram/SourceFiles/mtproto/mtproto_concurrent_sender.cpp @@ -28,7 +28,7 @@ DoneHandler ConcurrentSender::HandlerMaker::MakeDone( not_null sender, Fn)> runner) { return [ - weak = base::make_weak(sender.get()), + weak = base::make_weak(sender), runner = std::move(runner) ](const Response &response) mutable { runner([=]() mutable { @@ -47,7 +47,7 @@ FailHandler ConcurrentSender::HandlerMaker::MakeFail( Fn)> runner, FailSkipPolicy skipPolicy) { return [ - weak = base::make_weak(sender.get()), + weak = base::make_weak(sender), runner = std::move(runner), skipPolicy ](const Error &error, const Response &response) mutable { diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index ae6d3c3364..a7d80084b8 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -988,7 +988,7 @@ TopBar::TopBar( ActivateClickHandler(_about, handler, { button, QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(controller.get()), + .sessionWindow = base::make_weak(controller), .botStartAutoSubmit = true, }) }); @@ -1795,7 +1795,7 @@ not_null CreateSubscribeButton( UrlClickHandler::Open( local, QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(controller.get()), + .sessionWindow = base::make_weak(controller), .botStartAutoSubmit = true, })); } else { diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 3ae1efa8c8..4c845ea218 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -176,7 +176,7 @@ void Account::startAdded(MTP::AuthKeyPtr localKey) { } void Account::clearLegacyFiles() { - const auto weak = base::make_weak(_owner.get()); + const auto weak = base::make_weak(_owner); ClearLegacyFiles(_basePath, [weak, this]( FnMut&&)> then) { crl::on_main(weak, [this, then = std::move(then)]() mutable { diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index b38d907d4d..57d7816497 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -155,7 +155,7 @@ void PeerMenuAddMuteSubmenuAction( const PeerMenuCallback &addAction) { const auto notifySettings = &thread->owner().notifySettings(); notifySettings->request(thread); - const auto weak = base::make_weak(thread.get()); + const auto weak = base::make_weak(thread); const auto with = [=](Fn)> callback) { return [=] { if (const auto strong = weak.get()) { @@ -830,12 +830,24 @@ void Filler::addDeleteContact() { } void Filler::addDeleteTopic() { - if (!_topic/* || !_topic->canDelete()*/) { + if (!_topic || !_topic->canDelete()) { return; } + const auto controller = _controller; + const auto weak = base::make_weak(_topic); + const auto callback = [=] { + if (const auto strong = weak.get()) { + PeerMenuDeleteTopicWithConfirmation(controller, strong); + } + }; + _addAction({ + .text = tr::lng_forum_topic_delete(tr::now), + .handler = callback, + .icon = &st::menuIconDeleteAttention, + .isAttention = true, + }); } - void Filler::addManageTopic() { if (!_topic || !_topic->canEdit()) { return; @@ -971,6 +983,7 @@ void Filler::addCreateTopic() { } const auto peer = _peer; const auto controller = _controller; + _addAction(PeerMenuCallback::Args{ .isSeparator = true }); _addAction(tr::lng_forum_create_topic(tr::now), [=] { if (const auto forum = peer->forum()) { controller->show(Box( @@ -979,7 +992,6 @@ void Filler::addCreateTopic() { forum->history())); } }, &st::menuIconDiscussion); - _addAction(PeerMenuCallback::Args{ .isSeparator = true }); } void Filler::addViewAsMessages() { @@ -1004,7 +1016,6 @@ void Filler::fillChatsListActions() { if (!_peer || !_peer->isForum()) { return; } - addCreateTopic(); addViewAsMessages(); addInfo(); addNewMembers(); @@ -1017,6 +1028,7 @@ void Filler::fillChatsListActions() { } else { addJoinChat(); } + addCreateTopic(); } void Filler::fillContextMenuActions() { @@ -1082,10 +1094,10 @@ void Filler::fillRepliesActions() { addInfo(); addManageTopic(); addManageChat(); - addDeleteTopic(); } addCreatePoll(); addToggleTopicClosed(); + addDeleteTopic(); } void Filler::fillScheduledActions() { @@ -1159,6 +1171,49 @@ void PeerMenuDeleteContact( Ui::LayerOption::CloseOther); } + +void PeerMenuDeleteTopicWithConfirmation( + not_null navigation, + not_null topic) { + const auto weak = base::make_weak(topic); + const auto callback = [=](Fn &&close) { + close(); + if (const auto strong = weak.get()) { + PeerMenuDeleteTopic(navigation, strong); + } + }; + navigation->parentController()->show(Ui::MakeConfirmBox({ + .text = tr::lng_forum_topic_delete_sure(tr::now), + .confirmed = callback, + .confirmText = tr::lng_box_delete(), + .confirmStyle = &st::attentionBoxButton, + })); +} + +void PeerMenuDeleteTopic( + not_null navigation, + not_null channel, + MsgId rootId) { + const auto api = &channel->session().api(); + api->request(MTPchannels_DeleteTopicHistory( + channel->inputChannel, + MTP_int(rootId) + )).done([=](const MTPmessages_AffectedHistory &result) { + const auto offset = api->applyAffectedHistory(channel, result); + if (offset > 0) { + PeerMenuDeleteTopic(navigation, channel, rootId); + } else if (const auto forum = channel->forum()) { + forum->applyTopicDeleted(rootId); + } + }).send(); +} + +void PeerMenuDeleteTopic( + not_null navigation, + not_null topic) { + PeerMenuDeleteTopic(navigation, topic->channel(), topic->rootId()); +} + void PeerMenuShareContactBox( not_null navigation, not_null user) { diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index ed3ce11031..f834d237f5 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -24,6 +24,7 @@ namespace Data { class Folder; class Session; struct ForwardDraft; +class ForumTopic; } // namespace Data namespace Dialogs { @@ -74,6 +75,12 @@ void PeerMenuCreatePoll( PollData::Flags disabled = PollData::Flags(), Api::SendType sendType = Api::SendType::Normal, SendMenu::Type sendMenuType = SendMenu::Type::Scheduled); +void PeerMenuDeleteTopicWithConfirmation( + not_null navigation, + not_null topic); +void PeerMenuDeleteTopic( + not_null navigation, + not_null topic); struct ClearChat { }; diff --git a/Telegram/lib_base b/Telegram/lib_base index 2a94813b6a..12814dcf50 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 2a94813b6aa1f8645fd9de88a78981356259fab7 +Subproject commit 12814dcf5067d687c47c710689902fd1219bec4f