From b3a723c871ab5ca3449d5a6bde3e7e5d9dc23463 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sun, 17 Dec 2017 11:25:02 +0400
Subject: [PATCH] Fix crash in message history context menu.

Regression was introduced in 6d48ca850e.
---
 Telegram/SourceFiles/history/history_inner_widget.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp
index 0d7275e3d..10997d5ed 100644
--- a/Telegram/SourceFiles/history/history_inner_widget.cpp
+++ b/Telegram/SourceFiles/history/history_inner_widget.cpp
@@ -1387,14 +1387,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
 		auto item = App::hoveredItem()
 			? App::hoveredItem()
 			: App::hoveredLinkItem();
-		const auto group = item->getFullGroup();
-		if (group) {
+		if (const auto group = item ? item->getFullGroup() : nullptr) {
 			item = group->others.empty()
 				? group->leader
 				: group->others.front().get();
 		}
-		bool canDelete = item && item->canDelete() && (item->id > 0 || !item->serviceMsg());
-		bool canForward = item && item->canForward();
+		const auto canDelete = item
+			&& item->canDelete()
+			&& (item->id > 0 || !item->serviceMsg());
+		const auto canForward = item
+			&& item->canForward();
 
 		auto msg = dynamic_cast<HistoryMessage*>(item);
 		if (isUponSelected > 0) {