From b6c679449e65d66cffdf9b609fa915cee1d63126 Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Sat, 16 Dec 2023 23:23:24 +0000
Subject: [PATCH] Support custom channel backgrounds display.

---
 Telegram/SourceFiles/data/data_channel.cpp                | 8 ++++++++
 .../history/view/media/history_view_theme_document.cpp    | 5 ++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp
index 6f25e02c8..ca1bd81b2 100644
--- a/Telegram/SourceFiles/data/data_channel.cpp
+++ b/Telegram/SourceFiles/data/data_channel.cpp
@@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include "data/data_histories.h"
 #include "data/data_group_call.h"
 #include "data/data_message_reactions.h"
+#include "data/data_wall_paper.h"
 #include "data/notify/data_notify_settings.h"
 #include "main/main_session.h"
 #include "main/session/send_as_peers.h"
@@ -1142,6 +1143,13 @@ void ApplyChannelUpdate(
 		session->sendAsPeers().setChosen(channel, PeerId());
 	}
 
+	if (const auto paper = update.vwallpaper()) {
+		channel->setWallPaper(
+			Data::WallPaper::Create(&channel->session(), *paper));
+	} else {
+		channel->setWallPaper({});
+	}
+
 	// For clearUpTill() call.
 	channel->owner().sendHistoryChangeNotifications();
 }
diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp
index d268d4b3f..b9ebe4bb5 100644
--- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp
+++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp
@@ -509,8 +509,11 @@ rpl::producer<QString> ThemeDocumentBox::button() {
 }
 
 ClickHandlerPtr ThemeDocumentBox::createViewLink() {
-	const auto out = _parent->data()->out();
 	const auto to = _parent->history()->peer;
+	if (to->isChannel()) {
+		return nullptr;
+	}
+	const auto out = _parent->data()->out();
 	const auto media = _parent->data()->media();
 	const auto weak = base::make_weak(_parent);
 	const auto paper = media ? media->paper() : nullptr;