From 906cb95e675e55a35f257602815110d1426842db Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 8 Feb 2018 12:20:14 +0300 Subject: [PATCH] Channels list in feed info with leave channel. --- Telegram/Resources/scheme.tl | 8 +- Telegram/SourceFiles/apiwrap.cpp | 22 ++++- Telegram/SourceFiles/apiwrap.h | 2 + Telegram/SourceFiles/app.cpp | 16 +++- Telegram/SourceFiles/data/data_feed.cpp | 57 +++++++++---- Telegram/SourceFiles/data/data_feed.h | 4 + Telegram/SourceFiles/data/data_session.cpp | 31 +++++++ Telegram/SourceFiles/data/data_session.h | 6 ++ .../history/feed/history_feed_section.cpp | 19 +++-- .../info/feed/info_feed_channels.cpp | 15 +--- .../feed/info_feed_channels_controllers.cpp | 83 ++++++++++++++++--- .../feed/info_feed_channels_controllers.h | 4 +- .../info/feed/info_feed_channels_widget.cpp | 9 ++ .../info/feed/info_feed_channels_widget.h | 9 ++ .../feed/info_feed_profile_inner_widget.cpp | 38 ++++----- Telegram/SourceFiles/info/info.style | 2 + .../info/profile/info_profile_actions.cpp | 23 +++-- 17 files changed, 259 insertions(+), 89 deletions(-) create mode 100644 Telegram/SourceFiles/info/feed/info_feed_channels_widget.cpp create mode 100644 Telegram/SourceFiles/info/feed/info_feed_channels_widget.h diff --git a/Telegram/Resources/scheme.tl b/Telegram/Resources/scheme.tl index 0233f47461..a628b86c9b 100644 --- a/Telegram/Resources/scheme.tl +++ b/Telegram/Resources/scheme.tl @@ -273,7 +273,7 @@ messageActionCustomAction#fae69f56 message:string = MessageAction; messageActionBotAllowed#abe9affe domain:string = MessageAction; dialog#e4def5db flags:# pinned:flags.2?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; -dialogFeed#907750e4 flags:# pinned:flags.2?true peer:Peer top_message:int feed_id:int feed_other_channels:Vector read_max_position:flags.3?FeedPosition unread_count:int unread_muted_count:int sources_hash:int = Dialog; +dialogFeed#36086d42 flags:# pinned:flags.2?true peer:Peer top_message:int feed_id:int feed_other_channels:Vector read_max_position:flags.3?FeedPosition unread_count:int unread_muted_count:int = Dialog; photoEmpty#2331b22d id:long = Photo; photo#9288dd29 flags:# has_stickers:flags.0?true id:long access_hash:long date:int sizes:Vector = Photo; @@ -1199,11 +1199,11 @@ channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool; channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates; -channels.getFeed#18117df2 flags:# offset_to_max_read:flags.3?true feed_id:int offset_position:flags.0?FeedPosition add_offset:int limit:int max_position:flags.1?FeedPosition min_position:flags.2?FeedPosition sources_hash:int hash:int = messages.FeedMessages; +channels.getFeed#b90f450 flags:# offset_to_max_read:flags.3?true feed_id:int offset_position:flags.0?FeedPosition add_offset:int limit:int max_position:flags.1?FeedPosition min_position:flags.2?FeedPosition hash:int = messages.FeedMessages; channels.searchFeed#88325369 feed_id:int q:string offset_date:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; channels.getFeedSources#d8ce236e flags:# feed_id:flags.0?int hash:int = channels.FeedSources; -channels.changeFeedBroadcast#2528871e flags:# channel:InputChannel feed_id:flags.0?int = Bool; -channels.setFeedBroadcasts#7e91b8f2 feed_id:int channels:Vector also_newly_joined:Bool = Bool; +channels.changeFeedBroadcast#ffb37511 flags:# channel:InputChannel feed_id:flags.0?int = Updates; +channels.setFeedBroadcasts#ea80bfae flags:# feed_id:int channels:flags.0?Vector also_newly_joined:flags.1?Bool = Updates; channels.readFeed#9c3011d feed_id:int max_position:FeedPosition = Updates; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index cd83e853af..42a818a833 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -187,7 +187,8 @@ void ApiWrap::toggleChannelGrouping( MTP_flags(flags), channel->inputChannel, MTP_int(feedId) - )).done([=](const MTPBool &result) { + )).done([=](const MTPUpdates &result) { + applyUpdates(result); if (group) { channel->setFeed(Auth().data().feed(feedId)); } else { @@ -2993,6 +2994,11 @@ void ApiWrap::requestFeedChannels(not_null feed) { App::feedUsers(data.vusers); App::feedChats(data.vchats); + if (data.has_newly_joined_feed()) { + _session->data().setDefaultFeedId( + data.vnewly_joined_feed.v); + } + if (feed->channelsLoaded()) { feedChannelsDone(feed); } else { @@ -3044,7 +3050,6 @@ void ApiWrap::requestFeedMessages( } Unexpected("Direction in PrepareSearchRequest"); }(); - const auto sourcesHash = feed->channelsHash(); const auto hash = int32(0); const auto flags = (messageId && messageId.fullId.channel) ? MTPchannels_GetFeed::Flag::f_offset_position @@ -3060,7 +3065,6 @@ void ApiWrap::requestFeedMessages( MTP_int(limit), MTPFeedPosition(), MTPFeedPosition(), - MTP_int(sourcesHash), MTP_int(hash) )).done([=](const MTPmessages_FeedMessages &result) { const auto key = std::make_tuple(feed, messageId, slice); @@ -3172,6 +3176,18 @@ void ApiWrap::feedMessagesDone( } } +void ApiWrap::saveDefaultFeedId(FeedId id, bool isDefaultFeedId) { + if (const auto already = base::take(_saveDefaultFeedIdRequest)) { + request(already).cancel(); + } + _saveDefaultFeedIdRequest = request(MTPchannels_SetFeedBroadcasts( + MTP_flags(MTPchannels_SetFeedBroadcasts::Flag::f_also_newly_joined), + MTP_int(id), + MTPVector(), + MTP_bool(isDefaultFeedId) + )).send(); +} + void ApiWrap::sendAction(const SendOptions &options) { readServerHistory(options.history); options.history->getReadyFor(ShowAtTheEndMsgId); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index ca176564fb..8578aa26fb 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -177,6 +177,7 @@ public: not_null feed, Data::MessagePosition messageId, SliceType slice); + void saveDefaultFeedId(FeedId id, bool isDefaultFeedId); void stickerSetInstalled(uint64 setId) { _stickerSetInstalled.fire_copy(setId); @@ -507,6 +508,7 @@ private: not_null, Data::MessagePosition, SliceType>> _feedMessagesRequestsPending; + mtpRequestId _saveDefaultFeedIdRequest = 0; rpl::event_stream _sendActions; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 7858994d2d..52787fe331 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -575,10 +575,14 @@ namespace { cdata->setPhoto(d.vphoto); - if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn; + if (wasInChannel != cdata->amIn()) { + update.flags |= UpdateFlag::ChannelAmIn; + } if (canViewAdmins != cdata->canViewAdmins() || canViewMembers != cdata->canViewMembers() - || canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelRightsChanged; + || canAddMembers != cdata->canAddMembers()) { + update.flags |= UpdateFlag::ChannelRightsChanged; + } } break; case mtpc_channelForbidden: { auto &d(chat.c_channelForbidden()); @@ -612,10 +616,14 @@ namespace { cdata->date = 0; cdata->setMembersCount(0); - if (wasInChannel != cdata->amIn()) update.flags |= UpdateFlag::ChannelAmIn; + if (wasInChannel != cdata->amIn()) { + update.flags |= UpdateFlag::ChannelAmIn; + } if (canViewAdmins != cdata->canViewAdmins() || canViewMembers != cdata->canViewMembers() - || canAddMembers != cdata->canAddMembers()) update.flags |= UpdateFlag::ChannelRightsChanged; + || canAddMembers != cdata->canAddMembers()) { + update.flags |= UpdateFlag::ChannelRightsChanged; + } } break; } if (!data) { diff --git a/Telegram/SourceFiles/data/data_feed.cpp b/Telegram/SourceFiles/data/data_feed.cpp index 575e6ce92e..9b3a3fef67 100644 --- a/Telegram/SourceFiles/data/data_feed.cpp +++ b/Telegram/SourceFiles/data/data_feed.cpp @@ -84,6 +84,19 @@ void Feed::registerOne(not_null channel) { } else if (lastMessageKnown()) { _parent->session().api().requestDialogEntry(history); } + if (unreadCountKnown()) { + if (history->unreadCountKnown()) { + // If history unreadCount is known that means that we've + // already had the channel information and if it was in the + // feed already (not yet known) it wouldn't get here. + // That means here we get if we add a new channel to feed. + if (const auto count = history->unreadCount()) { + unreadCountChanged(count, history->mute() ? count : 0); + } + } else if (!_settingChannels) { + _parent->session().api().requestDialogEntry(this); + } + } if (invisible && _channels.size() > 1) { updateChatListExistence(); for (const auto history : _channels) { @@ -105,9 +118,20 @@ void Feed::unregisterOne(not_null channel) { _parent->session().storage().remove( Storage::FeedMessagesRemoveAll(_id, channel->bareId())); - if (const auto last = lastMessage()) { - if (last->history() == history) { - recountLastMessage(); + if (lastMessageKnown()) { + if (const auto last = lastMessage()) { + if (last->history() == history) { + recountLastMessage(); + } + } + } + if (unreadCountKnown()) { + if (history->unreadCountKnown()) { + if (const auto delta = -history->unreadCount()) { + unreadCountChanged(delta, history->mute() ? delta : 0); + } + } else { + _parent->session().api().requestDialogEntry(this); } } if (visible && _channels.size() < 2) { @@ -188,7 +212,7 @@ void Feed::setChannels(std::vector> channels) { const auto remove = ranges::view::all( _channels ) | ranges::view::transform([](not_null history) { - return history->peer->asChannel(); + return not_null(history->peer->asChannel()); }) | ranges::view::filter([&](not_null channel) { return !base::contains(channels, channel); }) | ranges::to_vector; @@ -201,8 +225,21 @@ void Feed::setChannels(std::vector> channels) { channel.get(), [](auto history) { return history->peer->asChannel(); } ) == end(_channels); + }) | ranges::view::transform([](ChannelData *channel) { + return not_null(channel); }) | ranges::to_vector; + changeChannelsList(add, remove); + + setChannelsLoaded(true); +} + +void Feed::changeChannelsList( + const std::vector> &add, + const std::vector> &remove) { + _settingChannels = true; + const auto restore = gsl::finally([&] { _settingChannels = false; }); + for (const auto channel : remove) { channel->clearFeed(); } @@ -216,14 +253,6 @@ void Feed::setChannels(std::vector> channels) { channel->setFeed(this); } _lastMessage = oldLastMessage; - - _channels.clear(); - for (const auto channel : channels) { - Assert(channel->feed() == this); - - _channels.push_back(App::history(channel)); - } - setChannelsLoaded(true); } bool Feed::justUpdateLastMessage(not_null item) { @@ -328,10 +357,6 @@ void Feed::applyDialog(const MTPDdialogFeed &data) { if (data.has_read_max_position()) { setUnreadPosition(FeedPositionFromMTP(data.vread_max_position)); } - - if (channelsHash() != data.vsources_hash.v) { - setChannelsLoaded(false); - } } void Feed::setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount) { diff --git a/Telegram/SourceFiles/data/data_feed.h b/Telegram/SourceFiles/data/data_feed.h index 23b2b71bb3..0add867704 100644 --- a/Telegram/SourceFiles/data/data_feed.h +++ b/Telegram/SourceFiles/data/data_feed.h @@ -87,10 +87,14 @@ private: void setLastMessageFromChannels(); bool justUpdateLastMessage(not_null item); void updateChatsListDate(); + void changeChannelsList( + const std::vector> &add, + const std::vector> &remove); FeedId _id = 0; not_null _parent; std::vector> _channels; + bool _settingChannels = false; bool _channelsLoaded = false; QString _name; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 1562391765..14c17cc8cf 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -60,6 +60,11 @@ void UpdateImage(ImagePtr &old, ImagePtr now) { Session::Session(not_null session) : _session(session) , _groups(this) { + setupContactViewsViewer(); + setupChannelLeavingViewer(); +} + +void Session::setupContactViewsViewer() { Notify::PeerUpdateViewer( Notify::PeerUpdate::Flag::UserIsContact ) | rpl::map([](const Notify::PeerUpdate &update) { @@ -71,6 +76,20 @@ Session::Session(not_null session) }, _lifetime); } +void Session::setupChannelLeavingViewer() { + Notify::PeerUpdateViewer( + Notify::PeerUpdate::Flag::ChannelAmIn + ) | rpl::map([](const Notify::PeerUpdate &update) { + return update.peer->asChannel(); + }) | rpl::filter([](ChannelData *channel) { + return (channel != nullptr) + && !(channel->amIn()) + && (channel->feed() != nullptr); + }) | rpl::start_with_next([=](not_null channel) { + channel->clearFeed(); + }, _lifetime); +} + Session::~Session() = default; template @@ -1447,6 +1466,18 @@ Feed *Session::feedLoaded(FeedId id) { return (it == end(_feeds)) ? nullptr : it->second.get(); } +void Session::setDefaultFeedId(FeedId id) { + _defaultFeedId = id; +} + +FeedId Session::defaultFeedId() const { + return _defaultFeedId.current(); +} + +rpl::producer Session::defaultFeedIdValue() const { + return _defaultFeedId.value(); +} + void Session::forgetMedia() { for (const auto &[id, photo] : _photos) { photo->forget(); diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 4c851e818c..2f1e871d6d 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -347,6 +347,9 @@ public: not_null feed(FeedId id); Feed *feedLoaded(FeedId id); + void setDefaultFeedId(FeedId id); + FeedId defaultFeedId() const; + rpl::producer defaultFeedIdValue() const; void forgetMedia(); @@ -361,6 +364,8 @@ public: } private: + void setupContactViewsViewer(); + void setupChannelLeavingViewer(); void photoApplyFields( not_null photo, const MTPPhoto &data); @@ -517,6 +522,7 @@ private: std::deque _pinnedDialogs; base::flat_map> _feeds; + rpl::variable _defaultFeedId = FeedId(); Groups _groups; std::map< not_null, diff --git a/Telegram/SourceFiles/history/feed/history_feed_section.cpp b/Telegram/SourceFiles/history/feed/history_feed_section.cpp index a8c91d2e52..4f3c36b63d 100644 --- a/Telegram/SourceFiles/history/feed/history_feed_section.cpp +++ b/Telegram/SourceFiles/history/feed/history_feed_section.cpp @@ -110,6 +110,7 @@ Widget::Widget( _showNext->setClickedCallback([this] { // #TODO feeds show next }); + _showNext->hide(); _feed->unreadPositionChanges( ) | rpl::filter([=](const Data::MessagePosition &position) { @@ -463,8 +464,8 @@ void Widget::updateControlsGeometry() { const auto bottom = height(); const auto scrollHeight = bottom - - _topBar->height() - - _showNext->height(); + - _topBar->height(); +// - _showNext->height(); const auto scrollSize = QSize(contentWidth, scrollHeight); if (_scroll->size() != scrollSize) { _skipScrollEvent = true; @@ -480,12 +481,12 @@ void Widget::updateControlsGeometry() { } updateScrollDownPosition(); - const auto fullWidthButtonRect = myrtlrect( - 0, - bottom - _showNext->height(), - contentWidth, - _showNext->height()); - _showNext->setGeometry(fullWidthButtonRect); + //const auto fullWidthButtonRect = myrtlrect( + // 0, + // bottom - _showNext->height(), + // contentWidth, + // _showNext->height()); + //_showNext->setGeometry(fullWidthButtonRect); if (_emptyTextView) { _emptyTextView->resizeGetHeight(width()); @@ -515,7 +516,7 @@ void Widget::paintEvent(QPaintEvent *e) { const auto clip = e->rect(); const auto left = 0; const auto top = (height() - - _showNext->height() +// - _showNext->height() - _emptyTextView->height()) / 2; p.translate(left, top); _emptyTextView->draw( diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp index bde6ea7757..8fd15113a2 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/padding_wrap.h" #include "ui/search_field_controller.h" #include "boxes/peer_list_controllers.h" +#include "data/data_feed.h" #include "lang/lang_keys.h" #include "styles/style_boxes.h" #include "styles/style_info.h" @@ -57,16 +58,8 @@ Channels::Channels( int Channels::desiredHeight() const { auto desired = _header ? _header->height() : 0; - //auto count = [this] { - // if (auto chat = _peer->asChat()) { - // return chat->count; - // } else if (auto channel = _peer->asChannel()) { - // return channel->membersCount(); - // } - // return 0; - //}(); - //desired += qMax(count, _list->fullRowsCount()) - // * st::infoMembersList.item.height; + desired += st::infoMembersList.item.height + * std::max(int(_feed->channels().size()), _list->fullRowsCount()); return qMax(height(), desired); } @@ -171,7 +164,7 @@ void Channels::setupList() { _list = object_ptr( this, _listController.get(), - st::infoMembersList); + st::infoCommonGroupsList); _list->scrollToRequests( ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { auto addmin = (request.ymin < 0 || !_header) diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp index 24bca29490..823b300862 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.cpp @@ -11,12 +11,73 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "info/info_controller.h" #include "lang/lang_keys.h" -#include "auth_session.h" #include "history/history.h" +#include "window/window_peer_menu.h" +#include "auth_session.h" +#include "styles/style_widgets.h" +#include "styles/style_info.h" +#include "styles/style_boxes.h" namespace Info { namespace FeedProfile { +class ChannelsController::Row final : public PeerListRow { +public: + Row(not_null channel); + + QSize actionSize() const override; + QMargins actionMargins() const override; + void paintAction( + Painter &p, + TimeMs ms, + int x, + int y, + int outerWidth, + bool selected, + bool actionSelected) override; + + not_null channel() const { + return peer()->asChannel(); + } + +}; + +ChannelsController::Row::Row(not_null channel) +: PeerListRow(channel) { +} + +QSize ChannelsController::Row::actionSize() const { + return QRect( + QPoint(), + st::smallCloseIcon.size()).marginsAdded( + st::infoFeedLeaveIconMargins).size(); +} + +QMargins ChannelsController::Row::actionMargins() const { + return QMargins( + 0, + (st::infoCommonGroupsList.item.height - actionSize().height()) / 2, + 0, + 0); +} + +void ChannelsController::Row::paintAction( + Painter &p, + TimeMs ms, + int x, + int y, + int outerWidth, + bool selected, + bool actionSelected) { + if (selected) { + x += st::infoFeedLeaveIconMargins.left(); + y += st::infoFeedLeaveIconMargins.top(); + (actionSelected + ? st::smallCloseIconOver + : st::smallCloseIcon).paint(p, x, y, outerWidth); + } +} + ChannelsController::ChannelsController(not_null controller) : PeerListController() , _controller(controller) @@ -24,16 +85,16 @@ ChannelsController::ChannelsController(not_null controller) _controller->setSearchEnabledByContent(false); } -std::unique_ptr ChannelsController::createRow( - not_null peer) { - auto result = std::make_unique(peer); +auto ChannelsController::createRow(not_null channel) +-> std::unique_ptr { + auto result = std::make_unique(channel); result->setCustomStatus(QString()); return result; } std::unique_ptr ChannelsController::createRestoredRow( not_null peer) { - return createRow(peer); + return createRow(peer->asChannel()); } void ChannelsController::prepare() { @@ -43,10 +104,7 @@ void ChannelsController::prepare() { rebuildRows(); using Flag = Data::FeedUpdateFlag; - rpl::single( - Data::FeedUpdate{ _feed, Flag::Channels } - ) | rpl::then( - Auth().data().feedUpdated() + Auth().data().feedUpdated( ) | rpl::filter([=](const Data::FeedUpdate &update) { return (update.feed == _feed) && (update.flag == Flag::Channels); }) | rpl::filter([=] { @@ -75,10 +133,11 @@ void ChannelsController::rebuildRows() { } } for (const auto history : channels) { - if (auto row = createRow(history->peer)) { + if (auto row = createRow(history->peer->asChannel())) { delegate()->peerListAppendRow(std::move(row)); } } + delegate()->peerListRefreshRows(); } std::unique_ptr ChannelsController::saveState() const { @@ -106,5 +165,9 @@ void ChannelsController::rowClicked(not_null row) { Window::SectionShow::Way::Forward); } +void ChannelsController::rowActionClicked(not_null row) { + Window::DeleteAndLeaveHandler(row->peer())(); +} + } // namespace FeedProfile } // namespace Info diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.h b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.h index 32b3e94905..2889e51c12 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.h +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_controllers.h @@ -27,6 +27,7 @@ public: void prepare() override; void rowClicked(not_null row) override; + void rowActionClicked(not_null row) override; std::unique_ptr createRestoredRow( not_null peer) override; @@ -35,12 +36,13 @@ public: void restoreState(std::unique_ptr state) override; private: + class Row; struct SavedState : SavedStateBase { rpl::lifetime lifetime; }; void rebuildRows(); - std::unique_ptr createRow(not_null peer); + std::unique_ptr createRow(not_null channel); const not_null _controller; not_null _feed; diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_widget.cpp b/Telegram/SourceFiles/info/feed/info_feed_channels_widget.cpp new file mode 100644 index 0000000000..436009363c --- /dev/null +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_widget.cpp @@ -0,0 +1,9 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "info/feed/info_feed_channels_widget.h" + diff --git a/Telegram/SourceFiles/info/feed/info_feed_channels_widget.h b/Telegram/SourceFiles/info/feed/info_feed_channels_widget.h new file mode 100644 index 0000000000..73e0063250 --- /dev/null +++ b/Telegram/SourceFiles/info/feed/info_feed_channels_widget.h @@ -0,0 +1,9 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + diff --git a/Telegram/SourceFiles/info/feed/info_feed_profile_inner_widget.cpp b/Telegram/SourceFiles/info/feed/info_feed_profile_inner_widget.cpp index c88fdbb1d1..2fee32e9bb 100644 --- a/Telegram/SourceFiles/info/feed/info_feed_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/feed/info_feed_profile_inner_widget.cpp @@ -40,26 +40,26 @@ object_ptr InnerWidget::setupContent( _cover = result->add(object_ptr( result, _controller)); - //auto details = Profile::SetupFeedDetails(_controller, parent, _feed); - //result->add(std::move(details)); - //result->add(object_ptr(result)); + auto details = Profile::SetupFeedDetails(_controller, parent, _feed); + result->add(std::move(details)); + result->add(object_ptr(result)); - //_channels = result->add(object_ptr( - // result, - // _controller) - //); - //_channels->scrollToRequests( - //) | rpl::start_with_next([this](Ui::ScrollToRequest request) { - // auto min = (request.ymin < 0) - // ? request.ymin - // : mapFromGlobal(_channels->mapToGlobal({ 0, request.ymin })).y(); - // auto max = (request.ymin < 0) - // ? mapFromGlobal(_channels->mapToGlobal({ 0, 0 })).y() - // : (request.ymax < 0) - // ? request.ymax - // : mapFromGlobal(_channels->mapToGlobal({ 0, request.ymax })).y(); - // _scrollToRequests.fire({ min, max }); - //}, _channels->lifetime()); + _channels = result->add(object_ptr( + result, + _controller) + ); + _channels->scrollToRequests( + ) | rpl::start_with_next([this](Ui::ScrollToRequest request) { + auto min = (request.ymin < 0) + ? request.ymin + : mapFromGlobal(_channels->mapToGlobal({ 0, request.ymin })).y(); + auto max = (request.ymin < 0) + ? mapFromGlobal(_channels->mapToGlobal({ 0, 0 })).y() + : (request.ymax < 0) + ? request.ymax + : mapFromGlobal(_channels->mapToGlobal({ 0, request.ymax })).y(); + _scrollToRequests.fire({ min, max }); + }, _channels->lifetime()); return std::move(result); } diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index b66d599a33..c1c6c7c72e 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -691,3 +691,5 @@ topBarFeedInfoButton: FeedUserpicButton(defaultFeedUserpicButton) { photoSize: 20px; } } + +infoFeedLeaveIconMargins: margins(10px, 12px, 20px, 10px); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index fa4ac4ec77..0cc9f205c4 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include "data/data_peer_values.h" +#include "data/data_session.h" +#include "data/data_feed.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/padding_wrap.h" #include "ui/wrap/slide_wrap.h" @@ -580,19 +582,11 @@ void ActionsFiller::addBlockAction(not_null user) { void ActionsFiller::addLeaveChannelAction( not_null channel) { - auto callback = [=] { - auto text = lang(channel->isMegagroup() - ? lng_sure_leave_group - : lng_sure_leave_channel); - Ui::show(Box(text, lang(lng_box_leave), [=] { - Auth().api().leaveChannel(channel); - }), LayerOption::KeepOther); - }; AddActionButton( _wrap, Lang::Viewer(lng_profile_leave_channel), AmInChannelValue(channel), - std::move(callback)); + Window::DeleteAndLeaveHandler(channel)); } void ActionsFiller::addJoinChannelAction( @@ -700,15 +694,20 @@ object_ptr FeedDetailsFiller::fill() { } object_ptr FeedDetailsFiller::setupDefaultToggle() { - const auto feed = _feed; + using namespace rpl::mappers; + const auto feedId = _feed->id(); auto result = object_ptr