Fix third column profile in topics.

This commit is contained in:
John Preston 2022-10-25 12:07:47 +04:00
parent 602ba5bba9
commit 48fb410bc7
15 changed files with 63 additions and 28 deletions

View file

@ -69,6 +69,7 @@ bool UrlRequiresConfirmation(const QUrl &url) {
"|t\\.me" "|t\\.me"
"|te\\.?legra\\.ph" "|te\\.?legra\\.ph"
"|graph\\.org" "|graph\\.org"
"|fragment\\.com"
"|telesco\\.pe" "|telesco\\.pe"
")$", ")$",
url.host(), url.host(),

View file

@ -37,6 +37,11 @@ const PeerNotifySettings &Thread::notify() const {
return const_cast<Thread*>(this)->notify(); return const_cast<Thread*>(this)->notify();
} }
bool Thread::canWrite() const {
const auto topic = asTopic();
return topic ? topic->canWrite() : peer()->canWrite();
}
void Thread::setUnreadThingsKnown() { void Thread::setUnreadThingsKnown() {
_flags |= Flag::UnreadThingsKnown; _flags |= Flag::UnreadThingsKnown;
} }

View file

@ -66,6 +66,7 @@ public:
[[nodiscard]] PeerNotifySettings &notify(); [[nodiscard]] PeerNotifySettings &notify();
[[nodiscard]] const PeerNotifySettings &notify() const; [[nodiscard]] const PeerNotifySettings &notify() const;
[[nodiscard]] bool canWrite() const;
void setUnreadThingsKnown(); void setUnreadThingsKnown();
[[nodiscard]] HistoryUnreadThings::Proxy unreadMentions(); [[nodiscard]] HistoryUnreadThings::Proxy unreadMentions();
[[nodiscard]] HistoryUnreadThings::ConstProxy unreadMentions() const; [[nodiscard]] HistoryUnreadThings::ConstProxy unreadMentions() const;

View file

@ -4618,13 +4618,13 @@ void HistoryWidget::showMembersDropdown() {
} }
bool HistoryWidget::pushTabbedSelectorToThirdSection( bool HistoryWidget::pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) { const Window::SectionShow &params) {
if (!_tabbedPanel) { if (!_tabbedPanel) {
return true; return true;
} else if (!peer->canWrite()) { } else if (!thread->canWrite()) {
Core::App().settings().setTabbedReplacedWithInfo(true); Core::App().settings().setTabbedReplacedWithInfo(true);
controller()->showPeerInfo(peer, params.withThirdColumn()); controller()->showPeerInfo(thread, params.withThirdColumn());
return false; return false;
} }
Core::App().settings().setTabbedReplacedWithInfo(false); Core::App().settings().setTabbedReplacedWithInfo(false);
@ -4670,7 +4670,7 @@ bool HistoryWidget::preventsClose(Fn<void()> &&continueCallback) const {
} }
void HistoryWidget::toggleTabbedSelectorMode() { void HistoryWidget::toggleTabbedSelectorMode() {
if (!_peer) { if (!_history) {
return; return;
} }
if (_tabbedPanel) { if (_tabbedPanel) {
@ -4679,7 +4679,7 @@ void HistoryWidget::toggleTabbedSelectorMode() {
Core::App().settings().setTabbedSelectorSectionEnabled(true); Core::App().settings().setTabbedSelectorSectionEnabled(true);
Core::App().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
pushTabbedSelectorToThirdSection( pushTabbedSelectorToThirdSection(
_peer, _history,
Window::SectionShow::Way::ClearStack); Window::SectionShow::Way::ClearStack);
} else { } else {
_tabbedPanel->toggleAnimated(); _tabbedPanel->toggleAnimated();

View file

@ -269,7 +269,7 @@ public:
// Tabbed selector management. // Tabbed selector management.
bool pushTabbedSelectorToThirdSection( bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) override; const Window::SectionShow &params) override;
bool returnTabbedSelector() override; bool returnTabbedSelector() override;

View file

@ -35,6 +35,7 @@ struct SendActionUpdate {
struct SetHistoryArgs { struct SetHistoryArgs {
required<History*> history; required<History*> history;
MsgId topicRootId = 0;
Fn<bool()> showSlowmodeError; Fn<bool()> showSlowmodeError;
rpl::producer<int> slowmodeSecondsLeft; rpl::producer<int> slowmodeSecondsLeft;
rpl::producer<bool> sendDisabledBySlowmode; rpl::producer<bool> sendDisabledBySlowmode;

View file

@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_chat.h" #include "data/data_chat.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_forum_topic.h"
#include "data/stickers/data_stickers.h" #include "data/stickers/data_stickers.h"
#include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_custom_emoji.h"
#include "data/data_web_page.h" #include "data/data_web_page.h"
@ -893,6 +894,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) {
Expects(!_history && *args.history); Expects(!_history && *args.history);
_showSlowmodeError = std::move(args.showSlowmodeError); _showSlowmodeError = std::move(args.showSlowmodeError);
_topicRootId = args.topicRootId;
_slowmodeSecondsLeft = rpl::single(0) _slowmodeSecondsLeft = rpl::single(0)
| rpl::then(std::move(args.slowmodeSecondsLeft)); | rpl::then(std::move(args.slowmodeSecondsLeft));
_sendDisabledBySlowmode = rpl::single(false) _sendDisabledBySlowmode = rpl::single(false)
@ -2287,7 +2289,7 @@ void ComposeControls::escape() {
} }
bool ComposeControls::pushTabbedSelectorToThirdSection( bool ComposeControls::pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) { const Window::SectionShow &params) {
if (!_tabbedPanel) { if (!_tabbedPanel) {
return true; return true;
@ -2344,8 +2346,11 @@ void ComposeControls::toggleTabbedSelectorMode() {
&& !_window->adaptive().isOneColumn()) { && !_window->adaptive().isOneColumn()) {
Core::App().settings().setTabbedSelectorSectionEnabled(true); Core::App().settings().setTabbedSelectorSectionEnabled(true);
Core::App().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
const auto topic = _topicRootId
? _history->peer->forumTopicFor(_topicRootId)
: nullptr;
pushTabbedSelectorToThirdSection( pushTabbedSelectorToThirdSection(
_history->peer, (topic ? topic : (Data::Thread*)_history),
Window::SectionShow::Way::ClearStack); Window::SectionShow::Way::ClearStack);
} else { } else {
_tabbedPanel->toggleAnimated(); _tabbedPanel->toggleAnimated();

View file

@ -143,7 +143,7 @@ public:
void setMimeDataHook(MimeDataHook hook); void setMimeDataHook(MimeDataHook hook);
bool pushTabbedSelectorToThirdSection( bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params); const Window::SectionShow &params);
bool returnTabbedSelector(); bool returnTabbedSelector();
@ -291,6 +291,7 @@ private:
rpl::variable<bool> _sendDisabledBySlowmode; rpl::variable<bool> _sendDisabledBySlowmode;
rpl::variable<std::optional<QString>> _writeRestriction; rpl::variable<std::optional<QString>> _writeRestriction;
rpl::variable<bool> _hidden; rpl::variable<bool> _hidden;
MsgId _topicRootId = 0;
Mode _mode = Mode::Normal; Mode _mode = Mode::Normal;
const std::unique_ptr<Ui::RpWidget> _wrap; const std::unique_ptr<Ui::RpWidget> _wrap;

View file

@ -1556,9 +1556,11 @@ void RepliesWidget::setInternalState(
} }
bool RepliesWidget::pushTabbedSelectorToThirdSection( bool RepliesWidget::pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) { const Window::SectionShow &params) {
return _composeControls->pushTabbedSelectorToThirdSection(peer, params); return _composeControls->pushTabbedSelectorToThirdSection(
thread,
params);
} }
bool RepliesWidget::returnTabbedSelector() { bool RepliesWidget::returnTabbedSelector() {

View file

@ -108,7 +108,7 @@ public:
// Tabbed selector management. // Tabbed selector management.
bool pushTabbedSelectorToThirdSection( bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) override; const Window::SectionShow &params) override;
bool returnTabbedSelector() override; bool returnTabbedSelector() override;

View file

@ -920,9 +920,11 @@ void ScheduledWidget::setInternalState(
} }
bool ScheduledWidget::pushTabbedSelectorToThirdSection( bool ScheduledWidget::pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) { const Window::SectionShow &params) {
return _composeControls->pushTabbedSelectorToThirdSection(peer, params); return _composeControls->pushTabbedSelectorToThirdSection(
thread,
params);
} }
bool ScheduledWidget::returnTabbedSelector() { bool ScheduledWidget::returnTabbedSelector() {

View file

@ -91,7 +91,7 @@ public:
// Tabbed selector management. // Tabbed selector management.
bool pushTabbedSelectorToThirdSection( bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const Window::SectionShow &params) override; const Window::SectionShow &params) override;
bool returnTabbedSelector() override; bool returnTabbedSelector() override;

View file

@ -380,7 +380,10 @@ void TopBarWidget::toggleInfoSection() {
Core::App().saveSettingsDelayed(); Core::App().saveSettingsDelayed();
if (isThreeColumn) { if (isThreeColumn) {
_controller->showSection( _controller->showSection(
Info::Memento::Default(_activeChat.key.peer()), (_activeChat.key.topic()
? std::make_shared<Info::Memento>(
_activeChat.key.topic())
: Info::Memento::Default(_activeChat.key.peer())),
Window::SectionShow().withThirdColumn()); Window::SectionShow().withThirdColumn());
} else { } else {
_controller->resizeForThirdSection(); _controller->resizeForThirdSection();
@ -1009,12 +1012,17 @@ void TopBarWidget::updateControlsVisibility() {
: (section == Section::ChatsList) : (section == Section::ChatsList)
? (_activeChat.key.peer() && _activeChat.key.peer()->isForum()) ? (_activeChat.key.peer() && _activeChat.key.peer()->isForum())
: false); : false);
const auto hasInfo = !_activeChat.key.folder()
&& (section == Section::History
? true
: (section == Section::Replies)
? (_activeChat.key.topic() != nullptr)
: false);
updateSearchVisibility(); updateSearchVisibility();
_menuToggle->setVisible(hasMenu _menuToggle->setVisible(hasMenu
&& !_chooseForReportReason && !_chooseForReportReason
&& !_narrowMode); && !_narrowMode);
_infoToggle->setVisible(historyMode _infoToggle->setVisible(hasInfo
&& !_activeChat.key.folder()
&& !isOneColumn && !isOneColumn
&& _controller->canShowThirdSection() && _controller->canShowThirdSection()
&& !_chooseForReportReason); && !_chooseForReportReason);

View file

@ -2194,16 +2194,24 @@ void MainWidget::updateControlsGeometry() {
anim::type::instant, anim::type::instant,
anim::activation::background); anim::activation::background);
const auto active = _controller->activeChatCurrent(); const auto active = _controller->activeChatCurrent();
if (const auto peer = active.peer()) { if (const auto thread = active.thread()) {
if (Core::App().settings().tabbedSelectorSectionEnabled()) { if (Core::App().settings().tabbedSelectorSectionEnabled()) {
if (_mainSection) { if (_mainSection) {
_mainSection->pushTabbedSelectorToThirdSection(peer, params); _mainSection->pushTabbedSelectorToThirdSection(
thread,
params);
} else { } else {
_history->pushTabbedSelectorToThirdSection(peer, params); _history->pushTabbedSelectorToThirdSection(
thread,
params);
} }
} else if (Core::App().settings().thirdSectionInfoEnabled()) { } else if (Core::App().settings().thirdSectionInfoEnabled()) {
_controller->showSection( _controller->showSection(
Info::Memento::Default(peer), (thread->asTopic()
? std::make_shared<Info::Memento>(
thread->asTopic())
: Info::Memento::Default(
thread->asHistory()->peer)),
params.withThirdColumn()); params.withThirdColumn());
} }
} }
@ -2491,11 +2499,11 @@ void MainWidget::updateThirdColumnToCurrentChat(
thirdSectionForCurrentMainSection(key), thirdSectionForCurrentMainSection(key),
params.withThirdColumn()); params.withThirdColumn());
}; };
auto switchTabbedFast = [&](not_null<PeerData*> peer) { auto switchTabbedFast = [&](not_null<Data::Thread*> thread) {
saveOldThirdSection(); saveOldThirdSection();
return _mainSection return _mainSection
? _mainSection->pushTabbedSelectorToThirdSection(peer, params) ? _mainSection->pushTabbedSelectorToThirdSection(thread, params)
: _history->pushTabbedSelectorToThirdSection(peer, params); : _history->pushTabbedSelectorToThirdSection(thread, params);
}; };
if (isThreeColumn() if (isThreeColumn()
&& settings.tabbedSelectorSectionEnabled() && settings.tabbedSelectorSectionEnabled()
@ -2505,8 +2513,8 @@ void MainWidget::updateThirdColumnToCurrentChat(
settings.setTabbedSelectorSectionEnabled(true); settings.setTabbedSelectorSectionEnabled(true);
settings.setTabbedReplacedWithInfo(true); settings.setTabbedReplacedWithInfo(true);
} else if (settings.tabbedReplacedWithInfo() } else if (settings.tabbedReplacedWithInfo()
&& key.history() && key.thread()
&& switchTabbedFast(key.history()->peer)) { && switchTabbedFast(key.thread())) {
settings.setTabbedReplacedWithInfo(false); settings.setTabbedReplacedWithInfo(false);
} }
} else { } else {

View file

@ -18,6 +18,7 @@ class PeerData;
namespace Data { namespace Data {
struct ReactionId; struct ReactionId;
class ForumTopic;
} // namespace Data } // namespace Data
namespace Main { namespace Main {
@ -58,7 +59,7 @@ public:
// Tabbed selector management. // Tabbed selector management.
virtual bool pushTabbedSelectorToThirdSection( virtual bool pushTabbedSelectorToThirdSection(
not_null<PeerData*> peer, not_null<Data::Thread*> thread,
const SectionShow &params) { const SectionShow &params) {
return false; return false;
} }