2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

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 { bool ChannelData::useSubsectionTabs() const {
return isForum() return amMonoforumAdmin()
&& (flags() & ChannelDataFlag::ForumTabs); || (isForum() && (flags() & ChannelDataFlag::ForumTabs));
} }
ChatRestrictionsInfo ChannelData::KickedRestrictedRights( ChatRestrictionsInfo ChannelData::KickedRestrictedRights(

View File

@@ -189,6 +189,9 @@ void Forum::applyTopicDeleted(MsgId rootId) {
reorderLastTopics(); reorderLastTopics();
} }
if (_activeSubsectionTopic == raw) {
_activeSubsectionTopic = nullptr;
}
_topicDestroyed.fire(raw); _topicDestroyed.fire(raw);
session().changes().topicUpdated( session().changes().topicUpdated(
raw, raw,
@@ -259,6 +262,20 @@ const std::vector<not_null<ForumTopic*>> &Forum::recentTopics() const {
return _lastTopics; 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) { void Forum::listMessageChanged(HistoryItem *from, HistoryItem *to) {
if (from || to) { if (from || to) {
reorderLastTopics(); reorderLastTopics();

View File

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

View File

@@ -82,6 +82,20 @@ void SavedMessages::clear() {
_owningHistory = nullptr; _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() { SavedMessages::~SavedMessages() {
clear(); clear();
} }

View File

@@ -77,6 +77,9 @@ public:
void clear(); void clear();
void saveActiveSubsectionThread(not_null<Thread*> thread);
Thread *activeSubsectionThread() const;
[[nodiscard]] rpl::lifetime &lifetime(); [[nodiscard]] rpl::lifetime &lifetime();
private: private:
@@ -132,6 +135,8 @@ private:
rpl::event_stream<> _chatsListChanges; rpl::event_stream<> _chatsListChanges;
rpl::event_stream<> _chatsListLoadedEvents; rpl::event_stream<> _chatsListLoadedEvents;
SavedSublist *_activeSubsectionSublist = nullptr;
bool _pinnedLoaded = false; bool _pinnedLoaded = false;
bool _unsupported = 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_thread.h"
#include "data/data_forum.h"
#include "data/data_forum_topic.h" #include "data/data_forum_topic.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h" #include "data/data_saved_sublist.h"
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
@@ -202,4 +205,16 @@ void Thread::setHasPinnedMessages(bool has) {
EntryUpdate::Flag::HasPinnedMessages); 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 } // namespace Data

View File

@@ -120,6 +120,8 @@ public:
[[nodiscard]] bool hasPinnedMessages() const; [[nodiscard]] bool hasPinnedMessages() const;
void setHasPinnedMessages(bool has); void setHasPinnedMessages(bool has);
void saveMeAsActiveSubsectionThread();
protected: protected:
void setUnreadMarkFlag(bool unread); 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_changes.h"
#include "data/data_download_manager.h" #include "data/data_download_manager.h"
#include "data/data_chat_filters.h" #include "data/data_chat_filters.h"
#include "data/data_saved_messages.h"
#include "data/data_saved_sublist.h" #include "data/data_saved_sublist.h"
#include "data/data_stories.h" #include "data/data_stories.h"
#include "info/downloads/info_downloads_widget.h" #include "info/downloads/info_downloads_widget.h"
@@ -920,7 +921,8 @@ void Widget::chosenRow(const ChosenRow &row) {
&& history->isForum() && history->isForum()
&& !row.message.fullId && !row.message.fullId
&& (!controller()->adaptive().isOneColumn() && (!controller()->adaptive().isOneColumn()
|| !history->peer->forum()->channel()->viewForumAsMessages())) { || !history->peer->forum()->channel()->viewForumAsMessages()
|| history->peer->forum()->channel()->useSubsectionTabs())) {
const auto forum = history->peer->forum(); const auto forum = history->peer->forum();
if (controller()->shownForum().current() == forum) { if (controller()->shownForum().current() == forum) {
controller()->closeForum(); controller()->closeForum();
@@ -943,6 +945,26 @@ void Widget::chosenRow(const ChosenRow &row) {
} }
} }
return; 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) { } else if (history) {
const auto peer = history->peer; const auto peer = history->peer;
const auto showAtMsgId = controller()->uniqueChatsInSearchResults() const auto showAtMsgId = controller()->uniqueChatsInSearchResults()

View File

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

View File

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

View File

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