Save last opened subsection within a launch.

This commit is contained in:
John Preston 2025-06-05 12:47:16 +04:00
parent 4b25406d14
commit 3bc20c3550
11 changed files with 103 additions and 8 deletions

View file

@ -409,8 +409,8 @@ void ChannelData::setPendingRequestsCount(
}
bool ChannelData::useSubsectionTabs() const {
return isForum()
&& (flags() & ChannelDataFlag::ForumTabs);
return amMonoforumAdmin()
|| (isForum() && (flags() & ChannelDataFlag::ForumTabs));
}
ChatRestrictionsInfo ChannelData::KickedRestrictedRights(

View file

@ -189,6 +189,9 @@ void Forum::applyTopicDeleted(MsgId rootId) {
reorderLastTopics();
}
if (_activeSubsectionTopic == raw) {
_activeSubsectionTopic = nullptr;
}
_topicDestroyed.fire(raw);
session().changes().topicUpdated(
raw,
@ -259,6 +262,20 @@ const std::vector<not_null<ForumTopic*>> &Forum::recentTopics() const {
return _lastTopics;
}
void Forum::saveActiveSubsectionThread(not_null<Thread*> thread) {
if (const auto topic = thread->asTopic()) {
Assert(topic->forum() == this);
_activeSubsectionTopic = topic->creating() ? nullptr : topic;
} else {
Assert(thread == history());
_activeSubsectionTopic = nullptr;
}
}
Thread *Forum::activeSubsectionThread() const {
return _activeSubsectionTopic;
}
void Forum::listMessageChanged(HistoryItem *from, HistoryItem *to) {
if (from || to) {
reorderLastTopics();

View file

@ -96,6 +96,9 @@ public:
[[nodiscard]] auto recentTopics() const
-> const std::vector<not_null<ForumTopic*>> &;
void saveActiveSubsectionThread(not_null<Thread*> thread);
[[nodiscard]] Thread *activeSubsectionThread() const;
[[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime;
}
@ -129,6 +132,8 @@ private:
std::vector<not_null<ForumTopic*>> _lastTopics;
int _lastTopicsVersion = 0;
ForumTopic *_activeSubsectionTopic = nullptr;
rpl::event_stream<> _chatsListChanges;
rpl::event_stream<> _chatsListLoadedEvents;

View file

@ -82,6 +82,20 @@ void SavedMessages::clear() {
_owningHistory = nullptr;
}
void SavedMessages::saveActiveSubsectionThread(not_null<Thread*> thread) {
if (const auto sublist = thread->asSublist()) {
Assert(sublist->parent() == this);
_activeSubsectionSublist = sublist;
} else {
Assert(thread == _owningHistory);
_activeSubsectionSublist = nullptr;
}
}
Thread *SavedMessages::activeSubsectionThread() const {
return _activeSubsectionSublist;
}
SavedMessages::~SavedMessages() {
clear();
}

View file

@ -77,6 +77,9 @@ public:
void clear();
void saveActiveSubsectionThread(not_null<Thread*> thread);
Thread *activeSubsectionThread() const;
[[nodiscard]] rpl::lifetime &lifetime();
private:
@ -132,6 +135,8 @@ private:
rpl::event_stream<> _chatsListChanges;
rpl::event_stream<> _chatsListLoadedEvents;
SavedSublist *_activeSubsectionSublist = nullptr;
bool _pinnedLoaded = false;
bool _unsupported = false;

View file

@ -7,9 +7,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_thread.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h"
#include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_peer.h"
#include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h"
#include "history/history.h"
#include "history/history_item.h"
@ -202,4 +205,16 @@ void Thread::setHasPinnedMessages(bool has) {
EntryUpdate::Flag::HasPinnedMessages);
}
void Thread::saveMeAsActiveSubsectionThread() {
if (const auto channel = owningHistory()->peer->asChannel()) {
if (channel->useSubsectionTabs()) {
if (const auto forum = channel->forum()) {
forum->saveActiveSubsectionThread(this);
} else if (const auto monoforum = channel->monoforum()) {
monoforum->saveActiveSubsectionThread(this);
}
}
}
}
} // namespace Data

View file

@ -120,6 +120,8 @@ public:
[[nodiscard]] bool hasPinnedMessages() const;
void setHasPinnedMessages(bool has);
void saveMeAsActiveSubsectionThread();
protected:
void setUnreadMarkFlag(bool unread);

View file

@ -79,6 +79,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_changes.h"
#include "data/data_download_manager.h"
#include "data/data_chat_filters.h"
#include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h"
#include "data/data_stories.h"
#include "info/downloads/info_downloads_widget.h"
@ -920,7 +921,8 @@ void Widget::chosenRow(const ChosenRow &row) {
&& history->isForum()
&& !row.message.fullId
&& (!controller()->adaptive().isOneColumn()
|| !history->peer->forum()->channel()->viewForumAsMessages())) {
|| !history->peer->forum()->channel()->viewForumAsMessages()
|| history->peer->forum()->channel()->useSubsectionTabs())) {
const auto forum = history->peer->forum();
if (controller()->shownForum().current() == forum) {
controller()->closeForum();
@ -943,6 +945,26 @@ void Widget::chosenRow(const ChosenRow &row) {
}
}
return;
} else if (history
&& history->amMonoforumAdmin()
&& !row.message.fullId) {
const auto monoforum = history->peer->monoforum();
if (row.newWindow) {
controller()->showInNewWindow(
Window::SeparateId(Window::SeparateType::Chat, history));
} else {
if (const auto active = monoforum->activeSubsectionThread()) {
controller()->showThread(
active,
ShowAtUnreadMsgId,
Window::SectionShow::Way::ClearStack);
} else {
controller()->showPeerHistory(
history,
Window::SectionShow::Way::ClearStack);
}
}
return;
} else if (history) {
const auto peer = history->peer;
const auto showAtMsgId = controller()->uniqueChatsInSearchResults()

View file

@ -4834,6 +4834,10 @@ void HistoryWidget::doneShow() {
controller()->widget()->setInnerFocus();
_preserveScrollTop = false;
checkSuggestToGigagroup();
if (_history) {
_history->saveMeAsActiveSubsectionThread();
}
}
void HistoryWidget::cornerButtonsShowAtPosition(

View file

@ -2880,6 +2880,12 @@ void ChatWidget::showFinishedHook() {
// because after that the method showChildren() is called.
setupDragArea();
updatePinnedVisibility();
if (_topic) {
_topic->saveMeAsActiveSubsectionThread();
} else if (_sublist) {
_sublist->saveMeAsActiveSubsectionThread();
}
}
bool ChatWidget::floatPlayerHandleWheelEvent(QEvent *e) {

View file

@ -586,7 +586,8 @@ void SessionNavigation::showPeerByLinkResolved(
if (const auto forum = peer->forum()) {
if (controller->windowId().hasChatsList()
&& !controller->adaptive().isOneColumn()
&& controller->shownForum().current() != forum) {
&& controller->shownForum().current() != forum
&& !forum->channel()->useSubsectionTabs()) {
controller->showForum(forum);
}
}
@ -1878,7 +1879,11 @@ void SessionController::showForum(
if (showForumInDifferentWindow(forum, params)) {
return;
} else if (forum->channel()->useSubsectionTabs()) {
showPeerHistory(forum->channel(), params);
if (const auto active = forum->activeSubsectionThread()) {
showThread(active, ShowAtUnreadMsgId, params);
} else {
showPeerHistory(forum->channel(), params);
}
return;
}
_shownForumLifetime.destroy();
@ -1992,9 +1997,9 @@ void SessionController::setActiveChatEntry(Dialogs::RowDescriptor row) {
Data::PeerFlagValue(
channel,
ChannelData::Flag::Forum
) | rpl::filter(
rpl::mappers::_1
) | rpl::start_with_next([=] {
) | rpl::filter([=](bool forum) {
return forum && !channel->useSubsectionTabs();
}) | rpl::start_with_next([=] {
clearSectionStack(
{ anim::type::normal, anim::activation::background });
showForum(channel->forum(),