From c6d3fd883aa0fb7e6c42551556de46dbca973455 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Wed, 6 Dec 2017 18:15:41 +0400
Subject: [PATCH] Display right action button not too high.

---
 Telegram/SourceFiles/history/history.style    |  2 +-
 .../history/history_inner_widget.cpp          |  6 ++--
 .../history/history_inner_widget.h            |  4 +--
 .../SourceFiles/history/history_message.cpp   | 33 ++++++++++++++-----
 .../SourceFiles/history/history_widget.cpp    | 20 +++++------
 Telegram/SourceFiles/history/history_widget.h |  1 -
 Telegram/SourceFiles/mainwidget.cpp           |  2 +-
 7 files changed, 42 insertions(+), 26 deletions(-)

diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style
index df48d29ed..7da102ab5 100644
--- a/Telegram/SourceFiles/history/history.style
+++ b/Telegram/SourceFiles/history/history.style
@@ -460,4 +460,4 @@ historyFastShareBottom: 5px;
 historyFastShareIcon: icon {{ "fast_share", msgServiceFg, point(4px, 3px)}};
 historyGoToOriginalIcon: icon {{ "title_back-flip_horizontal", msgServiceFg, point(8px, 7px) }};
 
-historySavedFont: font(semibold 15px);
+historySavedFont: font(semibold 14px);
diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 6ec8085ce..02d51b1ac 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -86,10 +86,10 @@ int BinarySearchBlocksOrItems(const T &list, int edge) {
 // flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html
 
 HistoryInner::HistoryInner(
-	HistoryWidget *historyWidget,
+	not_null<HistoryWidget*> historyWidget,
 	not_null<Window::Controller*> controller,
 	Ui::ScrollArea *scroll,
-	History *history)
+	not_null<History*> history)
 : RpWidget(nullptr)
 , _controller(controller)
 , _peer(history->peer)
@@ -1171,7 +1171,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
 	}
 
 	auto selectedState = getSelectionState();
-	auto canSendMessages = _widget->canSendMessages(_peer);
+	auto canSendMessages = _peer->canWrite();
 
 	// -2 - has full selected items, but not over, -1 - has selection, but no over, 0 - no selection, 1 - over text, 2 - over full selected items
 	auto isUponSelected = 0;
diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h
index a1d2b2bd0..880a8f336 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.h
+++ b/Telegram/SourceFiles/history/history_inner_widget.h
@@ -42,10 +42,10 @@ class HistoryInner
 
 public:
 	HistoryInner(
-		HistoryWidget *historyWidget,
+		not_null<HistoryWidget*> historyWidget,
 		not_null<Window::Controller*> controller,
 		Ui::ScrollArea *scroll,
-		History *history);
+		not_null<History*> history);
 
 	void messagesReceived(PeerData *peer, const QVector<MTPMessage> &messages);
 	void messagesReceivedDown(PeerData *peer, const QVector<MTPMessage> &messages);
diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp
index 741bee6ed..8b52429f4 100644
--- a/Telegram/SourceFiles/history/history_message.cpp
+++ b/Telegram/SourceFiles/history/history_message.cpp
@@ -1276,7 +1276,7 @@ QRect HistoryMessage::countGeometry() const {
 		maxwidth = qMax(_media->currentWidth(), qMin(maxwidth, plainMaxWidth()));
 	}
 
-	auto outLayout = hasOutLayout();
+	const auto outLayout = hasOutLayout();
 	auto contentLeft = (outLayout && !Adaptive::ChatWide())
 		? st::msgMargin.right()
 		: st::msgMargin.left();
@@ -1297,8 +1297,12 @@ QRect HistoryMessage::countGeometry() const {
 		contentWidth = maxwidth;
 	}
 
-	auto contentTop = marginTop();
-	return QRect(contentLeft, contentTop, contentWidth, _height - contentTop - marginBottom());
+	const auto contentTop = marginTop();
+	return QRect(
+		contentLeft,
+		contentTop,
+		contentWidth,
+		_height - contentTop - marginBottom());
 }
 
 void HistoryMessage::fromNameUpdated(int32 width) const {
@@ -1876,8 +1880,12 @@ void HistoryMessage::draw(Painter &p, QRect clip, TextSelection selection, TimeM
 			HistoryMessage::drawInfo(p, g.left() + g.width(), g.top() + g.height(), 2 * g.left() + g.width(), selected, InfoDisplayDefault);
 		}
 		if (displayRightAction()) {
-			auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
-			auto fastShareTop = g.top() + g.height() - st::historyFastShareBottom - st::historyFastShareSize;
+			const auto fastShareSkip = snap(
+				(g.height() - st::historyFastShareSize) / 2,
+				0,
+				st::historyFastShareBottom);
+			const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
+			const auto fastShareTop = g.top() + g.height() - fastShareSkip - st::historyFastShareSize;
 			drawRightAction(p, fastShareLeft, fastShareTop, width());
 		}
 	} else if (_media) {
@@ -2241,9 +2249,18 @@ HistoryTextState HistoryMessage::getState(QPoint point, HistoryStateRequest requ
 			}
 		}
 		if (displayRightAction()) {
-			auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
-			auto fastShareTop = g.top() + g.height() - st::historyFastShareBottom - st::historyFastShareSize;
-			if (QRect(fastShareLeft, fastShareTop, st::historyFastShareSize, st::historyFastShareSize).contains(point)) {
+			const auto fastShareSkip = snap(
+				(g.height() - st::historyFastShareSize) / 2,
+				0,
+				st::historyFastShareBottom);
+			const auto fastShareLeft = g.left() + g.width() + st::historyFastShareLeft;
+			const auto fastShareTop = g.top() + g.height() - fastShareSkip - st::historyFastShareSize;
+			if (QRect(
+				fastShareLeft,
+				fastShareTop,
+				st::historyFastShareSize,
+				st::historyFastShareSize
+			).contains(point)) {
 				result.link = rightActionLink();
 			}
 		}
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index f5ebcb7bb..833ad1b37 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -1742,7 +1742,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
 	if (peerId) {
 		_peer = App::peer(peerId);
 		_channel = peerToChannel(_peer->id);
-		_canSendMessages = canSendMessages(_peer);
+		_canSendMessages = _peer->canWrite();
 		_tabbedSelector->setCurrentPeer(_peer);
 	}
 	_topBar->setHistoryPeer(_peer);
@@ -3658,10 +3658,6 @@ void HistoryWidget::updateDragAreas() {
 	};
 }
 
-bool HistoryWidget::canSendMessages(PeerData *peer) const {
-	return peer && peer->canWrite();
-}
-
 bool HistoryWidget::readyToForward() const {
 	return _canSendMessages && !_toForward.empty();
 }
@@ -5345,7 +5341,9 @@ void HistoryWidget::onPhotoSend(PhotoData *photo) {
 }
 
 void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot) {
-	if (!_history || !result || !canSendMessages(_peer)) return;
+	if (!_peer || !_peer->canWrite() || !result) {
+		return;
+	}
 
 	auto errorText = result->getErrorOnSend(_history);
 	if (!errorText.isEmpty()) {
@@ -5527,7 +5525,7 @@ void HistoryWidget::destroyPinnedBar() {
 }
 
 bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &caption) {
-	if (!_history || !doc || !canSendMessages(_peer)) {
+	if (!_peer || !_peer->canWrite() || !doc) {
 		return false;
 	}
 
@@ -5592,7 +5590,9 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti
 }
 
 void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) {
-	if (!_history || !photo || !canSendMessages(_peer)) return;
+	if (!_peer || !_peer->canWrite() || !photo) {
+		return;
+	}
 
 	App::main()->readServerHistory(_history);
 	fastShowAtEnd(_history);
@@ -6108,7 +6108,7 @@ void HistoryWidget::onCancel() {
 
 void HistoryWidget::fullPeerUpdated(PeerData *peer) {
 	if (_list && peer == _peer) {
-		bool newCanSendMessages = canSendMessages(_peer);
+		auto newCanSendMessages = _peer->canWrite();
 		if (newCanSendMessages != _canSendMessages) {
 			_canSendMessages = newCanSendMessages;
 			if (!_canSendMessages) {
@@ -6151,7 +6151,7 @@ void HistoryWidget::handlePeerUpdate() {
 		if (_unblock->isHidden() == isBlocked() || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) {
 			resize = true;
 		}
-		bool newCanSendMessages = canSendMessages(_peer);
+		bool newCanSendMessages = _peer->canWrite();
 		if (newCanSendMessages != _canSendMessages) {
 			_canSendMessages = newCanSendMessages;
 			if (!_canSendMessages) {
diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h
index de7143ae9..0b8d2b57a 100644
--- a/Telegram/SourceFiles/history/history_widget.h
+++ b/Telegram/SourceFiles/history/history_widget.h
@@ -318,7 +318,6 @@ public:
 	void updateFieldSubmitSettings();
 
 	void setInnerFocus();
-	bool canSendMessages(PeerData *peer) const;
 
 	void updateNotifySettings();
 
diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp
index dfb8ebf8d..1825583d9 100644
--- a/Telegram/SourceFiles/mainwidget.cpp
+++ b/Telegram/SourceFiles/mainwidget.cpp
@@ -1464,7 +1464,7 @@ void MainWidget::sendMessage(const MessageToSend &message) {
 	readServerHistory(history);
 	_history->fastShowAtEnd(history);
 
-	if (!history || !_history->canSendMessages(history->peer)) {
+	if (!history || !history->peer->canWrite()) {
 		return;
 	}
 	saveRecentHashtags(textWithTags.text);