Improve separate window support.

This commit is contained in:
John Preston 2025-05-30 18:33:47 +04:00
parent 50b761fab2
commit 6068678fa1
7 changed files with 31 additions and 29 deletions

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "data/data_abstract_structure.h" #include "data/data_abstract_structure.h"
#include "data/data_channel.h"
#include "data/data_forum.h" #include "data/data_forum.h"
#include "data/data_message_reactions.h" #include "data/data_message_reactions.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -1377,8 +1378,9 @@ Window::Controller *Application::windowForShowingHistory(
Window::Controller *Application::windowForShowingForum( Window::Controller *Application::windowForShowingForum(
not_null<Data::Forum*> forum) const { not_null<Data::Forum*> forum) const {
const auto tabs = forum->channel()->useSubsectionTabs();
const auto id = Window::SeparateId( const auto id = Window::SeparateId(
Window::SeparateType::Forum, tabs ? Window::SeparateType::Chat : Window::SeparateType::Forum,
forum->history()); forum->history());
if (const auto separate = separateWindowFor(id)) { if (const auto separate = separateWindowFor(id)) {
return separate; return separate;
@ -1386,11 +1388,17 @@ Window::Controller *Application::windowForShowingForum(
auto result = (Window::Controller*)nullptr; auto result = (Window::Controller*)nullptr;
enumerateWindows([&](not_null<Window::Controller*> window) { enumerateWindows([&](not_null<Window::Controller*> window) {
if (const auto controller = window->sessionController()) { if (const auto controller = window->sessionController()) {
if (tabs) {
if (controller->windowId() == id) {
result = window;
}
} else {
const auto current = controller->shownForum().current(); const auto current = controller->shownForum().current();
if (forum == current) { if (forum == current) {
result = window; result = window;
} }
} }
}
}); });
return result; return result;
} }

View file

@ -911,8 +911,10 @@ void Widget::chosenRow(const ChosenRow &row) {
if (controller()->shownForum().current() == forum) { if (controller()->shownForum().current() == forum) {
controller()->closeForum(); controller()->closeForum();
} else if (row.newWindow) { } else if (row.newWindow) {
controller()->showInNewWindow( const auto type = forum->channel()->useSubsectionTabs()
Window::SeparateId(Window::SeparateType::Forum, history)); ? Window::SeparateType::Chat
: Window::SeparateType::Forum;
controller()->showInNewWindow(Window::SeparateId(type, history));
} else { } else {
controller()->showForum( controller()->showForum(
forum, forum,

View file

@ -1176,9 +1176,11 @@ Window::SessionController *Manager::openNotificationMessage(
} }
}); });
const auto separateId = topic const auto separateId = !topic
? Window::SeparateId(Window::SeparateType::Forum, history) ? Window::SeparateId(history->peer)
: Window::SeparateId(history->peer); : history->peer->asChannel()->useSubsectionTabs()
? Window::SeparateId(Window::SeparateType::Chat, topic)
: Window::SeparateId(Window::SeparateType::Forum, history);
const auto separate = Core::App().separateWindowFor(separateId); const auto separate = Core::App().separateWindowFor(separateId);
const auto itemId = openExactlyMessage ? messageId : ShowAtUnreadMsgId; const auto itemId = openExactlyMessage ? messageId : ShowAtUnreadMsgId;
if (openSeparated && !separate && !topic) { if (openSeparated && !separate && !topic) {

View file

@ -669,7 +669,7 @@ void Filler::addNewWindow() {
if (const auto sublist = weak.get()) { if (const auto sublist = weak.get()) {
controller->showInNewWindow(SeparateId( controller->showInNewWindow(SeparateId(
SeparateType::SavedSublist, SeparateType::SavedSublist,
sublist->owner().history(sublist->sublistPeer()))); sublist));
} }
}, &st::menuIconNewWindow); }, &st::menuIconNewWindow);
AddSeparatorAndShiftUp(_addAction); AddSeparatorAndShiftUp(_addAction);
@ -690,7 +690,9 @@ void Filler::addNewWindow() {
_addAction(tr::lng_context_new_window(tr::now), [=] { _addAction(tr::lng_context_new_window(tr::now), [=] {
Ui::PreventDelayedActivation(); Ui::PreventDelayedActivation();
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
const auto forum = !strong->asTopic() && peer->isForum(); const auto forum = !strong->asTopic()
&& peer->isForum()
&& !peer->asChannel()->useSubsectionTabs();
controller->showInNewWindow(SeparateId( controller->showInNewWindow(SeparateId(
forum ? SeparateType::Forum : SeparateType::Chat, forum ? SeparateType::Forum : SeparateType::Chat,
strong)); strong));
@ -2472,7 +2474,7 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
return true; return true;
} }
const auto id = SeparateId( const auto id = SeparateId(
(peer->isForum() ((peer->isForum() && !peer->asChannel()->useSubsectionTabs())
? SeparateType::Forum ? SeparateType::Forum
: SeparateType::Chat), : SeparateType::Chat),
thread); thread);

View file

@ -31,14 +31,10 @@ SeparateId::SeparateId(SeparateType type, not_null<Main::Session*> session)
, account(&session->account()) { , account(&session->account()) {
} }
SeparateId::SeparateId( SeparateId::SeparateId(SeparateType type, not_null<Data::Thread*> thread)
SeparateType type,
not_null<Data::Thread*> thread,
ChannelData *parentChat)
: type(type) : type(type)
, account(&thread->session().account()) , account(&thread->session().account())
, thread(thread) , thread(thread) {
, parentChat((type == SeparateType::SavedSublist) ? parentChat : nullptr) {
} }
SeparateId::SeparateId(not_null<Data::Thread*> thread) SeparateId::SeparateId(not_null<Data::Thread*> thread)
@ -77,12 +73,9 @@ Data::Folder *SeparateId::folder() const {
} }
Data::SavedSublist *SeparateId::sublist() const { Data::SavedSublist *SeparateId::sublist() const {
const auto monoforum = parentChat ? parentChat->monoforum() : nullptr;
return (type != SeparateType::SavedSublist) return (type != SeparateType::SavedSublist)
? nullptr ? nullptr
: monoforum : thread->asSublist();
? monoforum->sublist(thread->peer()).get()
: thread->owner().savedMessages().sublist(thread->peer()).get();
} }
bool SeparateId::hasChatsList() const { bool SeparateId::hasChatsList() const {

View file

@ -46,10 +46,7 @@ struct SeparateId {
SeparateId(std::nullptr_t); SeparateId(std::nullptr_t);
SeparateId(not_null<Main::Account*> account); SeparateId(not_null<Main::Account*> account);
SeparateId(SeparateType type, not_null<Main::Session*> session); SeparateId(SeparateType type, not_null<Main::Session*> session);
SeparateId( SeparateId(SeparateType type, not_null<Data::Thread*> thread);
SeparateType type,
not_null<Data::Thread*> thread,
ChannelData *parentChat = nullptr);
SeparateId(not_null<Data::Thread*> thread); SeparateId(not_null<Data::Thread*> thread);
SeparateId(not_null<PeerData*> peer); SeparateId(not_null<PeerData*> peer);
SeparateId( SeparateId(
@ -60,7 +57,6 @@ struct SeparateId {
Storage::SharedMediaType sharedMediaType = {}; Storage::SharedMediaType sharedMediaType = {};
Main::Account *account = nullptr; Main::Account *account = nullptr;
Data::Thread *thread = nullptr; // For types except Main and Archive. Data::Thread *thread = nullptr; // For types except Main and Archive.
ChannelData *parentChat = nullptr;
[[nodiscard]] bool valid() const { [[nodiscard]] bool valid() const {
return account != nullptr; return account != nullptr;
} }

View file

@ -1877,8 +1877,7 @@ void SessionController::showForum(
const SectionShow &params) { const SectionShow &params) {
if (showForumInDifferentWindow(forum, params)) { if (showForumInDifferentWindow(forum, params)) {
return; return;
} else if (HistoryView::SubsectionTabs::UsedFor( } else if (forum->channel()->useSubsectionTabs()) {
forum->owner().history(forum->channel()))) {
showPeerHistory(forum->channel(), params); showPeerHistory(forum->channel(), params);
return; return;
} }