Add "View Discussion" button to third column.

This commit is contained in:
John Preston 2024-12-11 12:48:26 +04:00
parent 65d6636a41
commit e92270a9ab
9 changed files with 65 additions and 17 deletions

View file

@ -121,8 +121,12 @@ struct EntryState {
FilterId filterId = 0; FilterId filterId = 0;
FullReplyTo currentReplyTo; FullReplyTo currentReplyTo;
friend inline auto operator<=>(EntryState, EntryState) noexcept friend inline auto operator<=>(
= default; const EntryState&,
const EntryState&) = default;
friend inline bool operator==(
const EntryState&,
const EntryState&) = default;
}; };
struct SearchState { struct SearchState {

View file

@ -1014,7 +1014,7 @@ void HistoryWidget::refreshTopBarActiveChat() {
const auto state = computeDialogsEntryState(); const auto state = computeDialogsEntryState();
_topBar->setActiveChat(state, _history->sendActionPainter()); _topBar->setActiveChat(state, _history->sendActionPainter());
if (state.key) { if (state.key) {
controller()->setCurrentDialogsEntryState(state); controller()->setDialogsEntryState(state);
} }
} }
@ -1989,7 +1989,7 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived(
UserData *samePeerBot, UserData *samePeerBot,
MsgId samePeerReplyTo) { MsgId samePeerReplyTo) {
if (samePeerBot) { if (samePeerBot) {
const auto to = controller()->currentDialogsEntryState(); const auto to = controller()->dialogsEntryStateCurrent();
if (!to.key.owningHistory()) { if (!to.key.owningHistory()) {
return false; return false;
} }
@ -2222,7 +2222,7 @@ void HistoryWidget::showHistory(
_showAtMsgHighlightPart = {}; _showAtMsgHighlightPart = {};
_showAtMsgHighlightPartOffsetHint = 0; _showAtMsgHighlightPartOffsetHint = 0;
const auto wasState = controller()->currentDialogsEntryState(); const auto wasState = controller()->dialogsEntryStateCurrent();
const auto startBot = (showAtMsgId == ShowAndStartBotMsgId); const auto startBot = (showAtMsgId == ShowAndStartBotMsgId);
_showAndMaybeSendStart = (showAtMsgId == ShowAndMaybeStartBotMsgId); _showAndMaybeSendStart = (showAtMsgId == ShowAndMaybeStartBotMsgId);
if (startBot || _showAndMaybeSendStart) { if (startBot || _showAndMaybeSendStart) {

View file

@ -1521,7 +1521,7 @@ void RepliesWidget::refreshTopBarActiveChat() {
}; };
_topBar->setActiveChat(state, _sendAction.get()); _topBar->setActiveChat(state, _sendAction.get());
_composeControls->setCurrentDialogsEntryState(state); _composeControls->setCurrentDialogsEntryState(state);
controller()->setCurrentDialogsEntryState(state); controller()->setDialogsEntryState(state);
} }
void RepliesWidget::refreshUnreadCountBadge(std::optional<int> count) { void RepliesWidget::refreshUnreadCountBadge(std::optional<int> count) {

View file

@ -186,7 +186,7 @@ ScheduledWidget::ScheduledWidget(
}; };
_topBar->setActiveChat(state, nullptr); _topBar->setActiveChat(state, nullptr);
_composeControls->setCurrentDialogsEntryState(state); _composeControls->setCurrentDialogsEntryState(state);
controller->setCurrentDialogsEntryState(state); controller->setDialogsEntryState(state);
_topBar->move(0, 0); _topBar->move(0, 0);
_topBar->resizeToWidth(width()); _topBar->resizeToWidth(width());

View file

@ -967,6 +967,8 @@ private:
not_null<UserData*> user); not_null<UserData*> user);
Ui::MultiSlideTracker fillChannelButtons( Ui::MultiSlideTracker fillChannelButtons(
not_null<ChannelData*> channel); not_null<ChannelData*> channel);
Ui::MultiSlideTracker fillDiscussionButtons(
not_null<ChannelData*> channel);
void addReportReaction(Ui::MultiSlideTracker &tracker); void addReportReaction(Ui::MultiSlideTracker &tracker);
void addReportReaction( void addReportReaction(
@ -1915,7 +1917,11 @@ void DetailsFiller::setupMainButtons() {
return fillUserButtons(user); return fillUserButtons(user);
}); });
} else if (const auto channel = _peer->asChannel()) { } else if (const auto channel = _peer->asChannel()) {
if (!channel->isMegagroup()) { if (channel->isMegagroup()) {
wrapButtons([=] {
return fillDiscussionButtons(channel);
});
} else {
wrapButtons([=] { wrapButtons([=] {
return fillChannelButtons(channel); return fillChannelButtons(channel);
}); });
@ -2080,6 +2086,37 @@ Ui::MultiSlideTracker DetailsFiller::fillChannelButtons(
return tracker; return tracker;
} }
Ui::MultiSlideTracker DetailsFiller::fillDiscussionButtons(
not_null<ChannelData*> channel) {
using namespace rpl::mappers;
Ui::MultiSlideTracker tracker;
auto window = _controller->parentController();
auto viewDiscussionVisible = rpl::combine(
_controller->wrapValue(),
window->dialogsEntryStateValue()
) | rpl::map([=](Wrap wrap, const Dialogs::EntryState &state) {
const auto history = state.key.history();
return (wrap == Wrap::Side)
&& (state.section == Dialogs::EntryState::Section::Replies)
&& history
&& (history->peer == channel);
});
auto viewDiscussion = [=] {
window->showPeerHistory(
channel,
Window::SectionShow::Way::Forward);
};
AddMainButton(
_wrap,
tr::lng_profile_view_discussion(),
std::move(viewDiscussionVisible),
std::move(viewDiscussion),
tracker);
return tracker;
}
object_ptr<Ui::RpWidget> DetailsFiller::fill() { object_ptr<Ui::RpWidget> DetailsFiller::fill() {
Expects(!_topic || !_topic->creating()); Expects(!_topic || !_topic->creating());

View file

@ -348,7 +348,7 @@ WebViewContext ResolveContext(
WebViewContext context) { WebViewContext context) {
if (!context.dialogsEntryState.key) { if (!context.dialogsEntryState.key) {
if (const auto strong = context.controller.get()) { if (const auto strong = context.controller.get()) {
context.dialogsEntryState = strong->currentDialogsEntryState(); context.dialogsEntryState = strong->dialogsEntryStateCurrent();
} }
} }
if (!context.action) { if (!context.action) {

View file

@ -700,7 +700,7 @@ void Inner::switchPm() {
} else { } else {
_inlineBot->botInfo->startToken = _switchPmStartToken; _inlineBot->botInfo->startToken = _switchPmStartToken;
_inlineBot->botInfo->inlineReturnTo _inlineBot->botInfo->inlineReturnTo
= _controller->currentDialogsEntryState(); = _controller->dialogsEntryStateCurrent();
_controller->showPeerHistory( _controller->showPeerHistory(
_inlineBot, _inlineBot,
Window::SectionShow::Way::ClearStack, Window::SectionShow::Way::ClearStack,

View file

@ -1847,13 +1847,18 @@ bool SessionController::jumpToChatListEntry(Dialogs::RowDescriptor row) {
return false; return false;
} }
void SessionController::setCurrentDialogsEntryState( void SessionController::setDialogsEntryState(
Dialogs::EntryState state) { Dialogs::EntryState state) {
_currentDialogsEntryState = state; _dialogsEntryState = state;
} }
Dialogs::EntryState SessionController::currentDialogsEntryState() const { Dialogs::EntryState SessionController::dialogsEntryStateCurrent() const {
return _currentDialogsEntryState; return _dialogsEntryState.current();
}
auto SessionController::dialogsEntryStateValue() const
-> rpl::producer<Dialogs::EntryState> {
return _dialogsEntryState.value();
} }
bool SessionController::switchInlineQuery( bool SessionController::switchInlineQuery(

View file

@ -394,8 +394,10 @@ public:
rpl::producer<Dialogs::Key> activeChatValue() const; rpl::producer<Dialogs::Key> activeChatValue() const;
bool jumpToChatListEntry(Dialogs::RowDescriptor row); bool jumpToChatListEntry(Dialogs::RowDescriptor row);
void setCurrentDialogsEntryState(Dialogs::EntryState state); void setDialogsEntryState(Dialogs::EntryState state);
[[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const; [[nodiscard]] Dialogs::EntryState dialogsEntryStateCurrent() const;
[[nodiscard]] auto dialogsEntryStateValue() const
-> rpl::producer<Dialogs::EntryState>;
bool switchInlineQuery( bool switchInlineQuery(
Dialogs::EntryState to, Dialogs::EntryState to,
not_null<UserData*> bot, not_null<UserData*> bot,
@ -708,7 +710,7 @@ private:
int _chatEntryHistoryPosition = -1; int _chatEntryHistoryPosition = -1;
bool _filtersActivated = false; bool _filtersActivated = false;
Dialogs::EntryState _currentDialogsEntryState; rpl::variable<Dialogs::EntryState> _dialogsEntryState;
base::Timer _invitePeekTimer; base::Timer _invitePeekTimer;