From a144e35f84d661d85c8e7808e746ae609bf003fc Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Tue, 6 Feb 2018 17:46:00 +0300
Subject: [PATCH] Add content to feed info cover widget.

---
 Telegram/Resources/langs/lang.strings         |   2 +
 .../SourceFiles/info/feed/info_feed_cover.cpp | 157 +++++-------------
 .../SourceFiles/info/feed/info_feed_cover.h   |   5 +-
 Telegram/SourceFiles/info/info.style          |  17 +-
 4 files changed, 60 insertions(+), 121 deletions(-)

diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index a29f455c2..b40cc45d5 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -1425,6 +1425,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "lng_feed_channel_added" = "Channel added to your feed.";
 "lng_feed_channel_removed" = "Channel removed from your feed.";
 "lng_feed_no_messages" = "No messages in this feed yet";
+"lng_feed_channels#one" = "{count} channel";
+"lng_feed_channels#other" = "{count} channels";
 
 "lng_info_feed_title" = "Feed Info";
 
diff --git a/Telegram/SourceFiles/info/feed/info_feed_cover.cpp b/Telegram/SourceFiles/info/feed/info_feed_cover.cpp
index 132001db4..e06d23e04 100644
--- a/Telegram/SourceFiles/info/feed/info_feed_cover.cpp
+++ b/Telegram/SourceFiles/info/feed/info_feed_cover.cpp
@@ -8,9 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "info/feed/info_feed_cover.h"
 
 #include "data/data_feed.h"
+#include "data/data_session.h"
 #include "info/info_controller.h"
 #include "lang/lang_keys.h"
 #include "ui/widgets/labels.h"
+#include "ui/special_buttons.h"
+#include "auth_session.h"
 #include "styles/style_info.h"
 
 namespace Info {
@@ -26,88 +29,43 @@ Cover::Cover(
 		+ st::infoProfilePhotoBottom)
 , _controller(controller)
 , _feed(_controller->key().feed())
-//, _userpic(
-//	this,
-//	controller->parentController(),
-//	_peer,
-//	Ui::UserpicButton::Role::OpenPhoto,
-//	st::infoProfilePhoto)
+, _userpic(
+	this,
+	controller->parentController(),
+	_feed,
+	st::infoFeedProfilePhoto)
 , _name(this, st::infoProfileNameLabel)
 , _status(
-	this,
-	st::infoProfileMegagroupStatusLabel) {
+		this,
+		st::infoProfileMegagroupStatusLabel) {
+	_userpic->setPointerCursor(false);
 	_name->setSelectable(true);
 	_name->setContextCopyText(lang(lng_profile_copy_fullname));
+	refreshNameText();
 
 	initViewers();
 	setupChildGeometry();
 }
 
 void Cover::setupChildGeometry() {
-	using namespace rpl::mappers;
-	//
-	// Visual Studio 2017 15.5.1 internal compiler error here.
-	// See https://developercommunity.visualstudio.com/content/problem/165155/ice-regression-in-1551-after-successfull-build-in.html
-	//
-	//rpl::combine(
-	//	toggleShownValue(),
-	//	widthValue(),
-	//	_2
-	//) | rpl::map([](bool shown, int width) {
-
-	//rpl::combine(
-	//	toggleShownValue(),
-	//	widthValue()
-	//) | rpl::map([](bool shown, int width) {
-	//	return width;
-	//}) | rpl::start_with_next([this](int newWidth) {
-	//	_userpic->moveToLeft(
-	//		st::infoProfilePhotoLeft,
-	//		st::infoProfilePhotoTop,
-	//		newWidth);
-	//	refreshNameGeometry(newWidth);
-	//	refreshStatusGeometry(newWidth);
-	//}, lifetime());
+	widthValue(
+	) | rpl::start_with_next([=](int newWidth) {
+		_userpic->moveToLeft(
+			st::infoProfilePhotoLeft,
+			st::infoProfilePhotoTop,
+			newWidth);
+		refreshNameGeometry(newWidth);
+		refreshStatusGeometry(newWidth);
+	}, lifetime());
 }
 
 void Cover::initViewers() {
-	//using Flag = Notify::PeerUpdate::Flag;
-	//Notify::PeerUpdateValue(
-	//	_peer,
-	//	Flag::NameChanged
-	//) | rpl::start_with_next(
-	//	[this] { refreshNameText(); },
-	//	lifetime());
-	//Notify::PeerUpdateValue(
-	//	_peer,
-	//	Flag::UserOnlineChanged | Flag::MembersChanged
-	//) | rpl::start_with_next(
-	//	[this] { refreshStatusText(); },
-	//	lifetime());
-	//if (!_peer->isUser()) {
-	//	Notify::PeerUpdateValue(
-	//		_peer,
-	//		Flag::ChannelRightsChanged | Flag::ChatCanEdit
-	//	) | rpl::start_with_next(
-	//		[this] { refreshUploadPhotoOverlay(); },
-	//		lifetime());
-	//}
-	//VerifiedValue(
-	//	_peer
-	//) | rpl::start_with_next(
-	//	[this](bool verified) { setVerified(verified); },
-	//	lifetime());
-}
-
-void Cover::refreshUploadPhotoOverlay() {
-	//_userpic->switchChangePhotoOverlay([&] {
-	//	if (auto chat = _peer->asChat()) {
-	//		return chat->canEdit();
-	//	} else if (auto channel = _peer->asChannel()) {
-	//		return channel->canEditInformation();
-	//	}
-	//	return false;
-	//}());
+	Auth().data().feedUpdated(
+	) | rpl::filter([](const Data::FeedUpdate &update) {
+		return update.flag == Data::FeedUpdateFlag::Channels;
+	}) | rpl::start_with_next(
+		[=] { refreshStatusText(); },
+		lifetime());
 }
 
 void Cover::refreshNameText() {
@@ -116,56 +74,21 @@ void Cover::refreshNameText() {
 }
 
 void Cover::refreshStatusText() {
-	//auto hasMembersLink = [&] {
-	//	if (auto megagroup = _peer->asMegagroup()) {
-	//		return megagroup->canViewMembers();
-	//	}
-	//	return false;
-	//}();
-	//auto statusText = [&] {
-	//	auto currentTime = unixtime();
-	//	if (auto user = _peer->asUser()) {
-	//		const auto result = Data::OnlineTextFull(user, currentTime);
-	//		const auto showOnline = Data::OnlineTextActive(user, currentTime);
-	//		const auto updateIn = Data::OnlineChangeTimeout(user, currentTime);
-	//		if (showOnline) {
-	//			_refreshStatusTimer.callOnce(updateIn);
-	//		}
-	//		return showOnline
-	//			? textcmdLink(1, result)
-	//			: result;
-	//	} else if (auto chat = _peer->asChat()) {
-	//		if (!chat->amIn()) {
-	//			return lang(lng_chat_status_unaccessible);
-	//		}
-	//		auto fullCount = std::max(
-	//			chat->count,
-	//			int(chat->participants.size()));
-	//		return ChatStatusText(fullCount, _onlineCount, true);
-	//	} else if (auto channel = _peer->asChannel()) {
-	//		auto fullCount = qMax(channel->membersCount(), 1);
-	//		auto result = ChatStatusText(
-	//			fullCount,
-	//			_onlineCount,
-	//			channel->isMegagroup());
-	//		return hasMembersLink ? textcmdLink(1, result) : result;
-	//	}
-	//	return lang(lng_chat_status_unaccessible);
-	//}();
-	//_status->setRichText(statusText);
-	//if (hasMembersLink) {
-	//	_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
-	//		_controller->showSection(Info::Memento(
-	//			_controller->peerId(),
-	//			Section::Type::Members));
-	//	}));
-	//}
+	const auto statusText = [&] {
+		if (!_feed->channelsLoaded() || _feed->channels().empty()) {
+			return QString();
+		}
+		return lng_feed_channels(lt_count, _feed->channels().size());
+	}();
+	_status->setRichText(statusText);
+	//_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
+	//	_controller->showSection(Info::Memento(
+	//		_feed,
+	//		Section::Type::Channels));
+	//})); // #TODO channels list
 	refreshStatusGeometry(width());
 }
 
-Cover::~Cover() {
-}
-
 void Cover::refreshNameGeometry(int newWidth) {
 	auto nameLeft = st::infoProfileNameLeft;
 	auto nameTop = st::infoProfileNameTop;
@@ -187,5 +110,7 @@ void Cover::refreshStatusGeometry(int newWidth) {
 		newWidth);
 }
 
+Cover::~Cover() = default;
+
 } // namespace FeedProfile
 } // namespace Info
diff --git a/Telegram/SourceFiles/info/feed/info_feed_cover.h b/Telegram/SourceFiles/info/feed/info_feed_cover.h
index cb4609f40..3c600f18b 100644
--- a/Telegram/SourceFiles/info/feed/info_feed_cover.h
+++ b/Telegram/SourceFiles/info/feed/info_feed_cover.h
@@ -20,7 +20,7 @@ class Feed;
 } // namespace Data
 
 namespace Ui {
-class UserpicButton;
+class FeedUserpicButton;
 class FlatLabel;
 template <typename Widget>
 class SlideWrap;
@@ -48,12 +48,11 @@ private:
 	void refreshStatusText();
 	void refreshNameGeometry(int newWidth);
 	void refreshStatusGeometry(int newWidth);
-	void refreshUploadPhotoOverlay();
 
 	not_null<Controller*> _controller;
 	not_null<Data::Feed*> _feed;
 
-	//object_ptr<Ui::UserpicButton> _userpic;
+	object_ptr<Ui::FeedUserpicButton> _userpic;
 	object_ptr<Ui::FlatLabel> _name = { nullptr };
 	object_ptr<Ui::FlatLabel> _status = { nullptr };
 	//object_ptr<CoverDropArea> _dropArea = { nullptr };
diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style
index a943d5e31..b66d599a3 100644
--- a/Telegram/SourceFiles/info/info.style
+++ b/Telegram/SourceFiles/info/info.style
@@ -260,9 +260,22 @@ infoTabs: SettingsSlider(defaultTabsSlider) {
 	labelTop: 19px;
 }
 
+infoProfilePhotoInnerSize: 72px;
+infoProfilePhotoSize: size(
+	infoProfilePhotoInnerSize,
+	infoProfilePhotoInnerSize);
 infoProfilePhoto: UserpicButton(defaultUserpicButton) {
-	size: size(72px, 72px);
-	photoSize: 72px;
+	size: infoProfilePhotoSize;
+	photoSize: infoProfilePhotoInnerSize;
+}
+infoFeedProfilePhoto: FeedUserpicButton(defaultFeedUserpicButton) {
+	size: infoProfilePhotoSize;
+	innerSize: infoProfilePhotoInnerSize;
+	innerPart: UserpicButton(defaultUserpicButton) {
+		size: size(35px, 35px);
+		photoSize: 35px;
+	}
+
 }
 infoProfilePhotoLeft: 19px;
 infoProfilePhotoTop: 18px;