From 74aa1ad71e55fde73802508df844ea369001e20c Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 Feb 2018 17:00:14 +0300 Subject: [PATCH] Ungroup all feed channels from context menu. --- Telegram/Resources/langs/lang.strings | 3 +++ Telegram/SourceFiles/apiwrap.cpp | 13 +++++++++++++ Telegram/SourceFiles/apiwrap.h | 1 + Telegram/SourceFiles/window/window_peer_menu.cpp | 16 ++++++++++++++++ Telegram/SourceFiles/window/window_peer_menu.h | 1 + 5 files changed, 34 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0d26daeebd..8baad03360 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1429,6 +1429,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_feed_channels#one" = "{count} channel"; "lng_feed_channels#other" = "{count} channels"; "lng_feed_notifications" = "Feed notifications"; +"lng_feed_ungroup_all" = "Ungroup all channels"; +"lng_feed_sure_ungroup_all" = "Are you sure you want to ungroup all channels from this feed?"; +"lng_feed_ungroup_sure" = "Ungroup"; "lng_info_feed_title" = "Feed Info"; "lng_info_feed_is_default" = "Group new channels"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 42a818a833..739df26fb8 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -203,6 +203,19 @@ void ApiWrap::toggleChannelGrouping( _channelGroupingRequests.emplace(channel, requestId, callback); } +void ApiWrap::ungroupAllFromFeed(not_null feed) { + const auto flags = MTPchannels_SetFeedBroadcasts::Flag::f_channels + | MTPchannels_SetFeedBroadcasts::Flag::f_also_newly_joined; + request(MTPchannels_SetFeedBroadcasts( + MTP_flags(flags), + MTP_int(feed->id()), + MTP_vector(0), + MTP_bool(false) + )).done([=](const MTPUpdates &result) { + applyUpdates(result); + }).send(); +} + void ApiWrap::sendMessageFail(const RPCError &error) { if (error.type() == qstr("PEER_FLOOD")) { Ui::show(Box( diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 8578aa26fb..6556bafb38 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -60,6 +60,7 @@ public: not_null channel, bool group, base::lambda callback); + void ungroupAllFromFeed(not_null feed); using RequestMessageDataCallback = base::lambda; void requestMessageData( diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 23ebd9c8a0..f22aace8ba 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -76,6 +76,7 @@ private: void addInfo(); void addSearch(); void addNotifications(); + void addUngroup(); not_null _controller; not_null _feed; @@ -423,6 +424,7 @@ void FeedFiller::fill() { if (_source == PeerMenuSource::ChatsList) { addSearch(); } + addUngroup(); } bool FeedFiller::showInfo() { @@ -477,6 +479,13 @@ void FeedFiller::addSearch() { }); } +void FeedFiller::addUngroup() { + const auto feed = _feed; + _addAction(lang(lng_feed_ungroup_all), [=] { + PeerMenuUngroupFeed(feed); + }); +} + } // namespace void PeerMenuDeleteContact(not_null user) { @@ -647,6 +656,13 @@ void PeerMenuAddMuteAction( Ui::AttachAsChild(muteAction, std::move(lifetime)); } +void PeerMenuUngroupFeed(not_null feed) { + Ui::show(Box( + lang(lng_feed_sure_ungroup_all), + lang(lng_feed_ungroup_sure), + [=] { Ui::hideLayer(); Auth().api().ungroupAllFromFeed(feed); })); +} + void ToggleChannelGrouping(not_null channel, bool group) { const auto callback = [=] { Ui::Toast::Show(lang(group diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index f3d85ae2a4..4cc0b0bd37 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -48,6 +48,7 @@ void PeerMenuDeleteContact(not_null user); void PeerMenuShareContactBox(not_null user); void PeerMenuAddContact(not_null user); void PeerMenuAddChannelMembers(not_null channel); +void PeerMenuUngroupFeed(not_null feed); void ToggleChannelGrouping(not_null channel, bool group); base::lambda ClearHistoryHandler(not_null peer);