From b2efc2ad14813b4ae8621ae5805cec632a4a29ed Mon Sep 17 00:00:00 2001
From: AlexeyZavar <sltkval1@gmail.com>
Date: Tue, 2 Jul 2024 17:29:20 +0300
Subject: [PATCH] feat: jump to beginning

---
 Telegram/Resources/icons/ayu/to_beginning.png | Bin 0 -> 480 bytes
 .../Resources/icons/ayu/to_beginning@2x.png   | Bin 0 -> 855 bytes
 .../Resources/icons/ayu/to_beginning@3x.png   | Bin 0 -> 1262 bytes
 Telegram/Resources/langs/lang.strings         |   1 +
 Telegram/SourceFiles/ayu/ui/ayu_icons.style   |   2 +
 .../SourceFiles/window/window_peer_menu.cpp   |  81 ++++++++++++++++++
 6 files changed, 84 insertions(+)
 create mode 100644 Telegram/Resources/icons/ayu/to_beginning.png
 create mode 100644 Telegram/Resources/icons/ayu/to_beginning@2x.png
 create mode 100644 Telegram/Resources/icons/ayu/to_beginning@3x.png

diff --git a/Telegram/Resources/icons/ayu/to_beginning.png b/Telegram/Resources/icons/ayu/to_beginning.png
new file mode 100644
index 0000000000000000000000000000000000000000..f43574b3487dd3fd26ed987debae77ac3bbe90c2
GIT binary patch
literal 480
zcmV<60U!Q}P)<h;3K|Lk000e1NJLTq000;O000;W1^@s6;CDUv00009a7bBm000XU
z000XU0RWnu7ytkO0drDELIAGL9O(c600d`2O+f$vv5yP<VFdsH0d+}4K~#7FwN{Oh
zMlcZF@8$|nf)40_4(NbR=ztDT2_;Yg9ne9}%gws)$P(X-H?xCC-pgixcoC7J2k}J@
z<J)GE<2dBHF8RJs%d%+ex{hq2Bn!h(wQZ~BdDb?Lqc%oWRcaMhXB?tHS(Y0~5Cn(!
z7{fat&+~f%bzSS7nuzxX4=@*ERsz@!7Ff7`5Gjh{TmTaRi9AhH700m{F926j0B%aI
zf}D{giE$3rA}K@xz;y0R4&wKFlNZRgHLZ^V?BaeAj$}`GCIW%AUbg40&`?a%G?57_
zAvH~-uPCxL%k<R*jC-C(ecx|m+pdraBxH(B3}E1hqUd-;a0~98kzd6?h~w`K0t114
zn%#+k5XZj<q}V=9Az<1q#`iTLq`6hGT-r&I{-20)|Fl(PS!Q~FT)@rFMg-p8YIbbc
z4YzC4kztJ6wb10w1=w{a0r-Q%A0Q;fRZD-d$`w{3UG1=87<AQ3)%*@?flu-HU&Rkt
Wv9oe43Th+(0000<MNUMnLSTaSn8oS<

literal 0
HcmV?d00001

diff --git a/Telegram/Resources/icons/ayu/to_beginning@2x.png b/Telegram/Resources/icons/ayu/to_beginning@2x.png
new file mode 100644
index 0000000000000000000000000000000000000000..609770ec00cf07c909529160b264117b11aa121e
GIT binary patch
literal 855
zcmV-d1E~CoP)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm00009a7bBm000&x
z000&x0ZCFM@Bjb+0drDELIAGL9O(c600d`2O+f$vv5yP<VFdsH0_;gdK~#7F?OB11
z>M#uToo)a&fDM2RU;@|xHh>La14dv3Mt}`~34jS;gZ{osu6+GzVyEd<NLaF3XdL@F
zsU5ptM3m7R(>J|2eE@V#Zx7&y64GEWpvh!H!{Ly6y<W-p`@P`n^;%pnmkXt&tO@5v
zXWQ*IyWMV?mN0g|-xsn?^-~kWkH=%Jf#>tNc+UKMKAmF|0I>_L*Xv&f;r?(qWV6{U
z%ePFe9G+nejII(^v2_42Kzbd9Z#EmR(Y_UgtR&1Gu^M`Xa-T;k3vNZ|FwSc?9-eDz
zc$MX9K$l@v!-J%U+A!V)0y>ibz{~X)#=AfuSTq8FtrOvqlCce9-V<JN1PO(F{X-e<
ztcHw6qrw0%?k%#=#bH|ExUl!FTZfI8;noU5Zl!?p(t2MS&nplE0^5&e0}gaQ;IIiG
zvBu-K>p$&$$nG3gO#q;T38_EUc+E2(&*$^fj()$d2OtGC2}NUI3<&6ES}YcN0Q>?$
zQAml57$L)|AT-Y5t-RaqoX?#V8444Srto;ZUgdQ<o&J(RF~f85d>F$rc&?qlZtRZ_
zfQF!8JRTQURtCzwO?eD2?j<l>UE_W8`v83VgtUY*(PccBl(@%#b>lS@1wgaJRg%WD
zmt7#N1kf%@3ZQB{whr(4SP(qE4gl!CH+#8Un!+fxlm}!O_2eUWXtX4<w(@|?N1pNi
z_=|K-9pwQ&kC~4WR7qx`PJ`vxERWf~L!#UTf%8~+g3xgqV=bKt&3IV}MjfZY#>yxe
z8@%raV62Riv1}qVDk;GzteF~g&(s{zM6h|JO%T%fWNj5NUO3s<Y6FBc-q@YfDR}GF
zVx2NxjTj(URmjTj1?G-u6x+R4?J9G)L+TGDJ&ZwiueM!Qt5p_b3q=YQUU&8R*&z9G
z10Or;zThO-iqu571Y-TfgjG!O4t+6-6oj*T-u@`AC`-Xy)PPY=o=zuvJRX#ak^<<0
hJ|DWfrVoIw=^x-b#F#*T8dm@S002ovPDHLkV1f#)dLsY;

literal 0
HcmV?d00001

diff --git a/Telegram/Resources/icons/ayu/to_beginning@3x.png b/Telegram/Resources/icons/ayu/to_beginning@3x.png
new file mode 100644
index 0000000000000000000000000000000000000000..0bc4291a1dc1b1bf263bbd9c283a61e5f9a9bdac
GIT binary patch
literal 1262
zcmV<K1QGj*P)<h;3K|Lk000e1NJLTq002k;002k`1^@s6RqeA!00009a7bBm001F4
z001F40Y#QEU;qFB0drDELIAGL9O(c600d`2O+f$vv5yP<VFdsH1cOOLK~#7F?OcmZ
zBQX#)rz?OCNC(gXPyuuR9Y6<!3ZMh%06IXaAV~#D2T2Ee`&MV<%z5pxJ>$(GKWTKg
zk=JWK&$B)LaAJ(<Ov5OCnT8-5K@l{9B4`9f&<Kj45fniqD1zUnGEPrV&Beuqxw*M9
zv)OF;KYoL`*zfmdyWI}9TCL1tu^9fv@3qlsTVMI^;o+hC`ugfhfjsW+?z*1bu148a
z2|^`aUS7K0Zr5qx?d?sSs1wVQBp{dhd~SNL38u3$f^_UN4AQf*vl0y9{r%lMKR*w7
zX+V_m$H&K@$3P;G+u7L}JI|h^?*9HhDACPkGe}RmK4Ju+pZWOs@D?6~Jv}`QX-dBX
zNr5a7Qb~5@nV>+v0!tF(voWIZn;=PL8NmI0l0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^Yimzh0jXJCnGC6ND$J)s^)sVu6`}NIzj&%+FxFXpb->7BPfDKPy~&j2pT~VG=d`d
Y1GnU6Y5WL5!2kdN07*qoM6N<$f){W>)&Kwi

literal 0
HcmV?d00001

diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings
index 334110cac..a47cec723 100644
--- a/Telegram/Resources/langs/lang.strings
+++ b/Telegram/Resources/langs/lang.strings
@@ -5681,6 +5681,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 "ayu_AyuForwardStatusFinished" = "Done";
 "ayu_AyuForwardStatusSentCount" = "sent %1$d of %2$d";
 "ayu_AyuForwardStatusChunkCount" = "chunk %1$d of %2$d";
+"ayu_JumpToBeginning" = "To Beginning";
 "ayu_ExpireMediaContextMenuText" = "Burn";
 "ayu_ExpiringVoiceMessageNote" = "This voice message can be played as many times as you want.";
 "ayu_ExpiringVideoMessageNote" = "This video message can be played as many times as you want.";
diff --git a/Telegram/SourceFiles/ayu/ui/ayu_icons.style b/Telegram/SourceFiles/ayu/ui/ayu_icons.style
index fa8f664c3..fb98cb99d 100644
--- a/Telegram/SourceFiles/ayu/ui/ayu_icons.style
+++ b/Telegram/SourceFiles/ayu/ui/ayu_icons.style
@@ -17,6 +17,8 @@ ayuLReadMenuIcon: icon {{ "ayu/lread", menuIconColor }};
 ayuSReadMenuIcon: icon {{ "ayu/sread", menuIconColor }};
 ayuStreamerModeMenuIcon: icon {{ "ayu/streamer", menuIconColor }};
 
+ayuMenuIconToBeginning: icon {{ "ayu/to_beginning", menuIconColor }};
+
 inChannelBadgeIcon: icon {{ "ayu/channel", msgInDateFg }};
 inChannelBadgeSelectedIcon: icon {{ "ayu/channel", msgInDateFgSelected }};
 outChannelBadgeIcon: icon {{ "ayu/channel", msgOutDateFg }};
diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp
index 712e022b0..f05e40fa1 100644
--- a/Telegram/SourceFiles/window/window_peer_menu.cpp
+++ b/Telegram/SourceFiles/window/window_peer_menu.cpp
@@ -98,6 +98,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 #include <QAction>
 #include <QtWidgets/QApplication>
 
+// AyuGram includes
+#include "styles/style_ayu_icons.h"
+
+
 namespace Window {
 namespace {
 
@@ -305,6 +309,7 @@ private:
 	void addVideoChat();
 	void addViewStatistics();
 	void addBoostChat();
+	void addJumpToBeginning();
 
 	not_null<SessionController*> _controller;
 	Dialogs::EntryState _request;
@@ -1081,6 +1086,80 @@ void Filler::addBoostChat() {
 	}
 }
 
+void Filler::addJumpToBeginning() {
+	const auto user = _peer->asUser();
+	const auto group = _peer->isChat() ? _peer->asChat() : nullptr;
+	const auto chat = _peer->isMegagroup() ? _peer->asMegagroup() : _peer->isChannel() ? _peer->asChannel() : nullptr;
+	const auto topic = _peer->isForum() ? _thread->asTopic() : nullptr;
+	if (!user && !group && !chat && !topic) {
+		return;
+	}
+	if (topic && topic->creating()) {
+		return;
+	}
+
+	const auto controller = _controller;
+	const auto jumpToDate = [=](auto history, auto callback)
+	{
+		const auto weak = base::make_weak(controller);
+		controller->session().api().resolveJumpToDate(
+			history,
+			QDate(2013, 8, 1),
+			[=](not_null<PeerData*> peer, MsgId id)
+			{
+				if (const auto strong = weak.get()) {
+					callback(peer, id);
+				}
+			});
+	};
+
+	const auto showPeerHistory = [=](auto peer, MsgId id)
+	{
+		controller->showPeerHistory(
+			peer,
+			SectionShow::Way::Forward,
+			id);
+	};
+
+	const auto showTopic = [=](auto topic, MsgId id)
+	{
+		controller->showTopic(
+			topic,
+			id,
+			SectionShow::Way::Forward);
+	};
+
+	_addAction(
+		tr::ayu_JumpToBeginning(tr::now),
+		[=]
+		{
+			if (user) {
+				jumpToDate(controller->session().data().history(user), showPeerHistory);
+			} else if (group && !chat) {
+				jumpToDate(controller->session().data().history(group), showPeerHistory);
+			} else if (chat && !topic) {
+				if (!chat->migrateFrom()) {
+					showPeerHistory(chat, 1);
+				} else {
+					jumpToDate(controller->session().data().history(chat), showPeerHistory);
+				}
+			} else if (topic) {
+				if (topic->isGeneral()) {
+					showTopic(topic, 1);
+				} else {
+					jumpToDate(
+						topic,
+						[=](not_null<PeerData*>, MsgId id)
+						{
+							showTopic(topic, id);
+						});
+				}
+			}
+		},
+		&st::ayuMenuIconToBeginning);
+}
+
+
 void Filler::addViewStatistics() {
 	if (const auto channel = _peer->asChannel()) {
 		const auto controller = _controller;
@@ -1407,6 +1486,7 @@ void Filler::fillContextMenuActions() {
 void Filler::fillHistoryActions() {
 	addToggleMuteSubmenu(true);
 	addInfo();
+	addJumpToBeginning();
 	addViewAsTopics();
 	addStoryArchive();
 	addSupportInfo();
@@ -1450,6 +1530,7 @@ void Filler::fillProfileActions() {
 void Filler::fillRepliesActions() {
 	if (_topic) {
 		addInfo();
+		addJumpToBeginning();
 		addManageTopic();
 	}
 	addCreatePoll();