feat: jump to beginning

This commit is contained in:
AlexeyZavar 2024-07-02 17:29:20 +03:00
parent 257b8552f7
commit b2efc2ad14
6 changed files with 84 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -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.";

View file

@ -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 }};

View file

@ -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();