From 91a6af71a0e6347d2189fd834df5a2dd8ae112df Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Thu, 25 Oct 2018 17:22:44 +0400
Subject: [PATCH] Limit video messages size.

---
 Telegram/Resources/basic.style                |  6 ----
 Telegram/SourceFiles/history/history.style    |  7 +++++
 .../SourceFiles/history/history_media.cpp     |  1 +
 .../history/history_media_types.cpp           | 30 +++++++++++--------
 .../SourceFiles/overview/overview_layout.cpp  |  2 +-
 Telegram/SourceFiles/window/layer_widget.cpp  |  7 +++--
 6 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/Telegram/Resources/basic.style b/Telegram/Resources/basic.style
index 4badfb3a1..dfdda9022 100644
--- a/Telegram/Resources/basic.style
+++ b/Telegram/Resources/basic.style
@@ -243,12 +243,6 @@ dragPadding: margins(20px, 10px, 20px, 10px);
 
 dragHeight: 72px;
 
-minPhotoSize: 100px;
-maxMediaSize: 430px;
-maxStickerSize: 256px;
-maxGifSize: 320px;
-maxSignatureSize: 144px;
-
 radialSize: size(50px, 50px);
 radialLine: 3px;
 radialDuration: 350;
diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style
index 687a49aea..4c0d353a9 100644
--- a/Telegram/SourceFiles/history/history.style
+++ b/Telegram/SourceFiles/history/history.style
@@ -9,6 +9,13 @@ using "basic.style";
 using "dialogs/dialogs.style";
 using "ui/widgets/widgets.style";
 
+minPhotoSize: 100px;
+maxMediaSize: 430px;
+maxStickerSize: 256px;
+maxGifSize: 320px;
+maxVideoMessageSize: 240px;
+maxSignatureSize: 144px;
+
 historyMinimalWidth: 380px;
 
 historyScroll: ScrollArea(defaultScrollArea) {
diff --git a/Telegram/SourceFiles/history/history_media.cpp b/Telegram/SourceFiles/history/history_media.cpp
index fa8bbcdf4..b540556d8 100644
--- a/Telegram/SourceFiles/history/history_media.cpp
+++ b/Telegram/SourceFiles/history/history_media.cpp
@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "history/view/history_view_cursor_state.h"
 #include "storage/storage_shared_media.h"
 #include "ui/text_options.h"
+#include "styles/style_history.h"
 
 namespace {
 
diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp
index 09f70c04a..5553d3756 100644
--- a/Telegram/SourceFiles/history/history_media_types.cpp
+++ b/Telegram/SourceFiles/history/history_media_types.cpp
@@ -2030,13 +2030,16 @@ QSize HistoryGif::countOptimalSize() {
 			th = ConvertScale(_data->thumb->height());
 		}
 	}
-	if (tw > st::maxGifSize) {
-		th = (st::maxGifSize * th) / tw;
-		tw = st::maxGifSize;
+	const auto maxSize = _data->isVideoMessage()
+		? st::maxVideoMessageSize
+		: st::maxGifSize;
+	if (tw > maxSize) {
+		th = (maxSize * th) / tw;
+		tw = maxSize;
 	}
-	if (th > st::maxGifSize) {
-		tw = (st::maxGifSize * tw) / th;
-		th = st::maxGifSize;
+	if (th > maxSize) {
+		tw = (maxSize * tw) / th;
+		th = maxSize;
 	}
 	if (!tw || !th) {
 		tw = th = 1;
@@ -2085,13 +2088,16 @@ QSize HistoryGif::countCurrentSize(int newWidth) {
 			th = ConvertScale(_data->thumb->height());
 		}
 	}
-	if (tw > st::maxGifSize) {
-		th = (st::maxGifSize * th) / tw;
-		tw = st::maxGifSize;
+	const auto maxSize = _data->isVideoMessage()
+		? st::maxVideoMessageSize
+		: st::maxGifSize;
+	if (tw > maxSize) {
+		th = (maxSize * th) / tw;
+		tw = maxSize;
 	}
-	if (th > st::maxGifSize) {
-		tw = (st::maxGifSize * tw) / th;
-		th = st::maxGifSize;
+	if (th > maxSize) {
+		tw = (maxSize * tw) / th;
+		th = maxSize;
 	}
 	if (!tw || !th) {
 		tw = th = 1;
diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp
index 7e8d8bc43..6707ab601 100644
--- a/Telegram/SourceFiles/overview/overview_layout.cpp
+++ b/Telegram/SourceFiles/overview/overview_layout.cpp
@@ -386,7 +386,7 @@ Video::Video(
 }
 
 void Video::initDimensions() {
-	_maxw = 2 * st::minPhotoSize;
+	_maxw = 2 * st::overviewPhotoMinSize;
 	_minh = _maxw;
 }
 
diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp
index a1a34e513..cc1524bd4 100644
--- a/Telegram/SourceFiles/window/layer_widget.cpp
+++ b/Telegram/SourceFiles/window/layer_widget.cpp
@@ -16,9 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "mainwindow.h"
 #include "mainwidget.h"
 #include "core/file_utilities.h"
-#include "styles/style_boxes.h"
-#include "styles/style_widgets.h"
-#include "styles/style_chat_helpers.h"
 #include "ui/widgets/shadow.h"
 #include "ui/image/image.h"
 #include "ui/emoji_config.h"
@@ -26,6 +23,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "auth_session.h"
 #include "chat_helpers/stickers.h"
 #include "window/window_controller.h"
+#include "styles/style_boxes.h"
+#include "styles/style_widgets.h"
+#include "styles/style_chat_helpers.h"
+#include "styles/style_history.h"
 
 namespace {