From 267a51e800feedfcfd9842571401f8491ed23d6d Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Fri, 1 Nov 2024 17:27:06 +0400
Subject: [PATCH] Fix possible crash in scheduled sent toast.

---
 .../view/history_view_scheduled_section.cpp   | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
index 0b20db1b7..ec9843a5a 100644
--- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
+++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp
@@ -67,6 +67,29 @@ namespace {
 
 constexpr auto kVideoProcessingInfoDuration = 4 * crl::time(1000);
 
+[[nodiscard]] DocumentData *FindVideoFile(not_null<HistoryItem*> item) {
+	const auto fromItem = [](not_null<HistoryItem*> item) {
+		if (const auto media = item->media()) {
+			if (const auto document = media->document()) {
+				if (document->isVideoFile()) {
+					return document;
+				}
+			}
+		}
+		return (DocumentData*)nullptr;
+	};
+	if (const auto group = item->history()->owner().groups().find(item)) {
+		for (const auto &entry : group->items) {
+			if (const auto result = fromItem(entry)) {
+				return result;
+			}
+		}
+	} else if (const auto result = fromItem(item)) {
+		return result;
+	}
+	return nullptr;
+}
+
 } // namespace
 
 ScheduledMemento::ScheduledMemento(
@@ -1677,9 +1700,8 @@ bool ShowScheduledVideoPublished(
 	if (!controller->widget()->isActive()) {
 		return false;
 	}
-	const auto media = info.item->media();
-	const auto document = media ? media->document() : nullptr;
-	if (!document->isVideoFile()) {
+	const auto document = FindVideoFile(info.item);
+	if (!document) {
 		return false;
 	}
 	const auto history = info.item->history();