diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 5aa666cc9..86066c2e0 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -1817,20 +1817,21 @@ void InnerWidget::contextMenuEvent(QContextMenuEvent *e) { } else if (const auto history = row.key.history()) { Window::FillPeerMenu( _controller, - history->peer, - _filterId, + Window::PeerMenuRequest{ + .peer = history->peer, + .source = Window::PeerMenuRequest::Source::ChatsList, + .filterId = _filterId, + }, [&](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); - }, - Window::PeerMenuSource::ChatsList); + }); } else if (const auto folder = row.key.folder()) { Window::FillFolderMenu( _controller, - folder, + Window::FolderMenuRequest{ folder }, [&](const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); - }, - Window::PeerMenuSource::ChatsList); + }); } connect(_menu.get(), &QObject::destroyed, [=] { if (_menuRow.key) { diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 5e82e23b9..c41aeb2d3 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -523,8 +523,10 @@ void Widget::refreshFolderTopBar() { updateControlsGeometry(); } _folderTopBar->setActiveChat( - _openedFolder, - HistoryView::TopBarWidget::Section::History, + HistoryView::TopBarWidget::ActiveChat{ + .key = _openedFolder, + .section = HistoryView::TopBarWidget::Section::Dialogs, + }, nullptr); } else { _folderTopBar.destroy(); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index bf3c6989c..c672f9072 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -171,7 +171,13 @@ void activateBotCommand( } } if (const auto m = CheckMainWidget(&msg->history()->session())) { - Window::PeerMenuCreatePoll(m->controller(), msg->history()->peer, chosen, disabled); + const auto replyToId = MsgId(0); + Window::PeerMenuCreatePoll( + m->controller(), + msg->history()->peer, + replyToId, + chosen, + disabled); } } break; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 75bd8b335..122792c35 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -707,6 +707,16 @@ void HistoryWidget::setGeometryWithTopMoved( _topDelta = 0; } +void HistoryWidget::refreshTopBarActiveChat() { + _topBar->setActiveChat( + HistoryView::TopBarWidget::ActiveChat{ + .key = _history, + .section = HistoryView::TopBarWidget::Section::History, + .currentReplyToId = replyToId(), + }, + _history->sendActionPainter()); +} + void HistoryWidget::refreshTabbedPanel() { if (_peer && controller()->hasTabbedSelectorOwnership()) { createTabbedPanel(); @@ -1588,6 +1598,7 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) { updateControlsVisibility(); updateControlsGeometry(); } + refreshTopBarActiveChat(); return; } @@ -1607,7 +1618,7 @@ void HistoryWidget::applyDraft(FieldHistoryAction fieldHistoryAction) { } updateControlsVisibility(); updateControlsGeometry(); - + refreshTopBarActiveChat(); if (_editMsgId || _replyToId) { updateReplyEditTexts(); if (!_replyEditMsg) { @@ -1825,10 +1836,7 @@ void HistoryWidget::showHistory( } _history->setFakeUnreadWhileOpened(true); - _topBar->setActiveChat( - _history, - HistoryView::TopBarWidget::Section::History, - _history->sendActionPainter()); + refreshTopBarActiveChat(); updateTopBarSelection(); if (_channel) { @@ -1915,10 +1923,7 @@ void HistoryWidget::showHistory( unreadCountUpdated(); // set _historyDown badge. showAboutTopPromotion(); } else { - _topBar->setActiveChat( - Dialogs::Key(), - HistoryView::TopBarWidget::Section::History, - nullptr); + refreshTopBarActiveChat(); updateTopBarSelection(); clearFieldText(); @@ -4763,6 +4768,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { updateMouseTracking(); } } + refreshTopBarActiveChat(); updateControlsGeometry(); update(); } @@ -5479,6 +5485,7 @@ void HistoryWidget::replyToMessage(not_null item) { updateReplyToName(); updateControlsGeometry(); updateField(); + refreshTopBarActiveChat(); } _saveDraftText = true; @@ -5605,7 +5612,7 @@ bool HistoryWidget::cancelReply(bool lastKeyboardUsed) { } updateBotKeyboard(); - + refreshTopBarActiveChat(); updateControlsGeometry(); update(); } else if (auto localDraft = (_history ? _history->localDraft() : nullptr)) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 57c964f03..b05e6fb36 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -353,6 +353,7 @@ private: void createTabbedPanel(); void setTabbedPanel(std::unique_ptr panel); void updateField(); + void refreshTopBarActiveChat(); void requestMessageData(MsgId msgId); void messageDataReceived(ChannelData *channel, MsgId msgId); diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 9699c13f0..2d8d2fa92 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -102,8 +102,10 @@ PinnedWidget::PinnedWidget( st::historyComposeButton)) , _scrollDown(_scroll.get(), st::historyToDown) { _topBar->setActiveChat( - _history, - TopBarWidget::Section::Pinned, + TopBarWidget::ActiveChat{ + .key = _history, + .section = TopBarWidget::Section::Pinned, + }, nullptr); _topBar->move(0, 0); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 76755b0b3..18fe048d0 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -167,10 +167,7 @@ RepliesWidget::RepliesWidget( session().api().requestFullPeer(_history->peer); - _topBar->setActiveChat( - _history, - TopBarWidget::Section::Replies, - _sendAction.get()); + refreshTopBarActiveChat(); _topBar->move(0, 0); _topBar->resizeToWidth(width()); @@ -220,7 +217,7 @@ RepliesWidget::RepliesWidget( _inner->replyToMessageRequested( ) | rpl::start_with_next([=](auto fullId) { - _composeControls->replyToMessage(fullId); + replyToMessage(fullId); }, _inner->lifetime()); _composeControls->sendActionUpdates( @@ -714,6 +711,7 @@ void RepliesWidget::sendingFilesConfirmed( } if (_composeControls->replyingToMessage().msg == replyTo) { _composeControls->cancelReplyMessage(); + refreshTopBarActiveChat(); } } @@ -1138,6 +1136,17 @@ SendMenu::Type RepliesWidget::sendMenuType() const { : SendMenu::Type::Scheduled; } +void RepliesWidget::refreshTopBarActiveChat() { + _topBar->setActiveChat( + TopBarWidget::ActiveChat{ + .key = _history, + .section = TopBarWidget::Section::Replies, + .rootId = _rootId, + .currentReplyToId = replyToId(), + }, + _sendAction.get()); +} + MsgId RepliesWidget::replyToId() const { const auto custom = _composeControls->replyingToMessage().msg; return custom ? custom : _rootId; @@ -1181,6 +1190,7 @@ void RepliesWidget::finishSending() { //if (_previewData && _previewData->pendingTill) previewCancel(); doSetInnerFocus(); showAtEnd(); + refreshTopBarActiveChat(); } void RepliesWidget::showAtPosition( @@ -1394,13 +1404,13 @@ bool RepliesWidget::replyToMessage(not_null item) { if (item->history() != _history || item->replyToTop() != _rootId) { return false; } - _composeControls->replyToMessage(item->fullId()); + replyToMessage(item->fullId()); return true; } -MsgId RepliesWidget::currentReplyToIdFor( - not_null history) const { - return (_history == history) ? replyToId() : 0; +void RepliesWidget::replyToMessage(FullMsgId itemId) { + _composeControls->replyToMessage(itemId); + refreshTopBarActiveChat(); } void RepliesWidget::saveState(not_null memento) { @@ -1626,6 +1636,7 @@ void RepliesWidget::listCancelRequest() { clearSelected(); return; } else if (_composeControls->handleCancelRequest()) { + refreshTopBarActiveChat(); return; } controller()->showBackFromStack(); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index 308368438..66e8b7eb0 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -88,8 +88,6 @@ public: const Window::SectionShow ¶ms, MsgId messageId) override; bool replyToMessage(not_null item) override; - MsgId currentReplyToIdFor( - not_null history) const override; void setInternalState( const QRect &geometry, @@ -200,6 +198,8 @@ private: void restoreReplyReturns(const std::vector &list); void checkReplyReturns(); void recountChatWidth(); + void replyToMessage(FullMsgId itemId); + void refreshTopBarActiveChat(); void uploadFile(const QByteArray &fileContent, SendMediaType type); bool confirmSendingFiles( diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index f1c14871a..9c5f32ca5 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -100,8 +100,10 @@ ScheduledWidget::ScheduledWidget( ComposeControls::Mode::Scheduled)) , _scrollDown(_scroll, st::historyToDown) { _topBar->setActiveChat( - _history, - TopBarWidget::Section::Scheduled, + TopBarWidget::ActiveChat{ + .key = _history, + .section = TopBarWidget::Section::Scheduled, + }, nullptr); _topBar->move(0, 0); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index a4edc14ef..432694aaa 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -115,7 +115,7 @@ TopBarWidget::TopBarWidget( using AnimationUpdate = Data::Session::SendActionAnimationUpdate; session().data().sendActionAnimationUpdated( ) | rpl::filter([=](const AnimationUpdate &update) { - return (update.history == _activeChat.history()); + return (update.history == _activeChat.key.history()); }) | rpl::start_with_next([=] { update(); }, lifetime()); @@ -191,13 +191,13 @@ void TopBarWidget::refreshLang() { } void TopBarWidget::onSearch() { - if (_activeChat) { - _controller->content()->searchInChat(_activeChat); + if (_activeChat.key) { + _controller->content()->searchInChat(_activeChat.key); } } void TopBarWidget::onCall() { - if (const auto peer = _activeChat.peer()) { + if (const auto peer = _activeChat.key.peer()) { if (const auto user = peer->asUser()) { Core::App().calls().startOutgoingCall(user, false); } @@ -205,7 +205,7 @@ void TopBarWidget::onCall() { } void TopBarWidget::showMenu() { - if (!_activeChat || _menu) { + if (!_activeChat.key || _menu) { return; } _menu.create(parentWidget()); @@ -228,27 +228,31 @@ void TopBarWidget::showMenu() { })); _menuToggle->installEventFilter(_menu); const auto addAction = [&]( - const QString & text, + const QString &text, Fn callback) { return _menu->addAction(text, std::move(callback)); }; - if (const auto peer = _activeChat.peer()) { + if (const auto peer = _activeChat.key.peer()) { + using Source = Window::PeerMenuRequest::Source; + const auto source = (_activeChat.section == Section::Scheduled) + ? Source::ScheduledSection + : (_activeChat.section == Section::Replies) + ? Source::RepliesSection + : Source::History; Window::FillPeerMenu( _controller, - peer, - FilterId(), - addAction, - (_section == Section::Scheduled - ? Window::PeerMenuSource::ScheduledSection - : (_section == Section::Replies) - ? Window::PeerMenuSource::RepliesSection - : Window::PeerMenuSource::History)); - } else if (const auto folder = _activeChat.folder()) { + Window::PeerMenuRequest{ + .peer = peer, + .source = source, + .rootId = _activeChat.rootId, + .currentReplyToId = _activeChat.currentReplyToId, + }, + addAction); + } else if (const auto folder = _activeChat.key.folder()) { Window::FillFolderMenu( _controller, - folder, - addAction, - Window::PeerMenuSource::History); + Window::FolderMenuRequest{ folder }, + addAction); } else { Unexpected("Empty active chat in TopBarWidget::showMenu."); } @@ -265,13 +269,13 @@ void TopBarWidget::toggleInfoSection() { && (Core::App().settings().thirdSectionInfoEnabled() || Core::App().settings().tabbedReplacedWithInfo())) { _controller->closeThirdSection(); - } else if (_activeChat.peer()) { + } else if (_activeChat.key.peer()) { if (_controller->canShowThirdSection()) { Core::App().settings().setThirdSectionInfoEnabled(true); Core::App().saveSettingsDelayed(); if (Adaptive::ThreeColumn()) { _controller->showSection( - Info::Memento::Default(_activeChat.peer()), + Info::Memento::Default(_activeChat.key.peer()), Window::SectionShow().withThirdColumn()); } else { _controller->resizeForThirdSection(); @@ -325,7 +329,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { } void TopBarWidget::paintTopBar(Painter &p) { - if (!_activeChat) { + if (!_activeChat.key) { return; } auto nameleft = _leftTaken; @@ -333,18 +337,18 @@ void TopBarWidget::paintTopBar(Painter &p) { auto statustop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height; auto availableWidth = width() - _rightTaken - nameleft; - const auto history = _activeChat.history(); - const auto folder = _activeChat.folder(); + const auto history = _activeChat.key.history(); + const auto folder = _activeChat.key.folder(); if (folder || history->peer->sharedMediaInfo() - || (_section == Section::Scheduled) - || (_section == Section::Pinned)) { + || (_activeChat.section == Section::Scheduled) + || (_activeChat.section == Section::Pinned)) { // #TODO feed name emoji. - auto text = (_section == Section::Scheduled) + auto text = (_activeChat.section == Section::Scheduled) ? ((history && history->peer->isSelf()) ? tr::lng_reminder_messages(tr::now) : tr::lng_scheduled_messages(tr::now)) - : (_section == Section::Pinned) + : (_activeChat.section == Section::Pinned) ? _customTitleText : folder ? folder->chatListName() @@ -362,7 +366,7 @@ void TopBarWidget::paintTopBar(Painter &p) { (height() - st::historySavedFont->height) / 2, width(), text); - } else if (_section == Section::Replies) { + } else if (_activeChat.section == Section::Replies) { p.setPen(st::dialogsNameFg); p.setFont(st::semiboldFont); p.drawTextLeft( @@ -384,7 +388,7 @@ void TopBarWidget::paintTopBar(Painter &p) { p.setPen(st::historyStatusFg); p.drawTextLeft(nameleft, statustop, width(), _customTitleText); } - } else if (const auto history = _activeChat.history()) { + } else if (const auto history = _activeChat.key.history()) { const auto peer = history->peer; const auto &text = peer->topBarNameText(); const auto badgeStyle = Ui::PeerBadgeStyle{ @@ -483,29 +487,30 @@ void TopBarWidget::mousePressEvent(QMouseEvent *e) { } void TopBarWidget::infoClicked() { - if (!_activeChat) { + const auto key = _activeChat.key; + if (!key) { return; - } else if (_activeChat.folder()) { + } else if (key.folder()) { _controller->closeFolder(); //} else if (const auto feed = _activeChat.feed()) { // #feed // _controller->showSection(Info::Memento( // feed, // Info::Section(Info::Section::Type::Profile))); - } else if (_activeChat.peer()->isSelf()) { + } else if (key.peer()->isSelf()) { _controller->showSection(Info::Memento( - _activeChat.peer(), + key.peer(), Info::Section(Storage::SharedMediaType::Photo))); - } else if (_activeChat.peer()->isRepliesChat()) { + } else if (key.peer()->isRepliesChat()) { _controller->showSection(Info::Memento( - _activeChat.peer(), + key.peer(), Info::Section(Storage::SharedMediaType::Photo))); } else { - _controller->showPeerInfo(_activeChat.peer()); + _controller->showPeerInfo(key.peer()); } } void TopBarWidget::backClicked() { - if (_activeChat.folder()) { + if (_activeChat.key.folder()) { _controller->closeFolder(); } else { _controller->showBackFromStack(); @@ -513,14 +518,14 @@ void TopBarWidget::backClicked() { } void TopBarWidget::setActiveChat( - Dialogs::Key chat, - Section section, + ActiveChat activeChat, SendActionPainter *sendAction) { - if (_activeChat == chat && _section == section) { + if (_activeChat.key == activeChat.key + && _activeChat.section == activeChat.section) { + _activeChat = activeChat; return; } - _activeChat = chat; - _section = section; + _activeChat = activeChat; _sendAction = sendAction; _back->clearState(); update(); @@ -544,7 +549,7 @@ void TopBarWidget::setCustomTitle(const QString &title) { } void TopBarWidget::refreshInfoButton() { - if (const auto peer = _activeChat.peer()) { + if (const auto peer = _activeChat.key.peer()) { auto info = object_ptr( this, _controller, @@ -577,14 +582,14 @@ int TopBarWidget::countSelectedButtonsTop(float64 selectedShown) { } void TopBarWidget::updateSearchVisibility() { - const auto historyMode = (_section == Section::History); - const auto smallDialogsColumn = _activeChat.folder() + const auto historyMode = (_activeChat.section == Section::History); + const auto smallDialogsColumn = _activeChat.key.folder() && (width() < _back->width() + _search->width()); _search->setVisible(historyMode && !smallDialogsColumn); } void TopBarWidget::updateControlsGeometry() { - if (!_activeChat) { + if (!_activeChat.key) { return; } auto hasSelected = (_selectedCount > 0); @@ -621,7 +626,7 @@ void TopBarWidget::updateControlsGeometry() { if (_back->isHidden()) { _leftTaken = st::topBarArrowPadding.right(); } else { - const auto smallDialogsColumn = _activeChat.folder() + const auto smallDialogsColumn = _activeChat.key.folder() && (width() < _back->width() + _search->width()); _leftTaken = smallDialogsColumn ? (width() - _back->width()) / 2 : 0; _back->moveToLeft(_leftTaken, otherButtonsTop); @@ -666,7 +671,7 @@ void TopBarWidget::setAnimatingMode(bool enabled) { } void TopBarWidget::updateControlsVisibility() { - if (!_activeChat) { + if (!_activeChat.key) { return; } else if (_animatingMode) { hideChildren(); @@ -679,7 +684,7 @@ void TopBarWidget::updateControlsVisibility() { auto backVisible = Adaptive::OneColumn() || !_controller->content()->stackIsEmpty() - || _activeChat.folder(); + || _activeChat.key.folder(); _back->setVisible(backVisible); if (_info) { _info->setVisible(Adaptive::OneColumn()); @@ -687,21 +692,22 @@ void TopBarWidget::updateControlsVisibility() { if (_unreadBadge) { _unreadBadge->show(); } - const auto historyMode = (_section == Section::History); - const auto hasPollsMenu = _activeChat.peer() - && _activeChat.peer()->canSendPolls(); - const auto hasMenu = !_activeChat.folder() - && ((_section == Section::Scheduled || _section == Section::Replies) + const auto section = _activeChat.section; + const auto historyMode = (section == Section::History); + const auto hasPollsMenu = _activeChat.key.peer() + && _activeChat.key.peer()->canSendPolls(); + const auto hasMenu = !_activeChat.key.folder() + && ((section == Section::Scheduled || section == Section::Replies) ? hasPollsMenu : historyMode); updateSearchVisibility(); _menuToggle->setVisible(hasMenu); _infoToggle->setVisible(historyMode - && !_activeChat.folder() + && !_activeChat.key.folder() && !Adaptive::OneColumn() && _controller->canShowThirdSection()); const auto callsEnabled = [&] { - if (const auto peer = _activeChat.peer()) { + if (const auto peer = _activeChat.key.peer()) { if (const auto user = peer->asUser()) { return session().serverConfig().phoneCallsEnabled.current() && user->hasCalls(); @@ -719,7 +725,7 @@ void TopBarWidget::updateControlsVisibility() { void TopBarWidget::updateMembersShowArea() { const auto membersShowAreaNeeded = [&] { - const auto peer = _activeChat.peer(); + const auto peer = _activeChat.key.peer(); if ((_selectedCount > 0) || !peer) { return false; } else if (const auto chat = peer->asChat()) { @@ -805,7 +811,7 @@ void TopBarWidget::updateAdaptiveLayout() { } void TopBarWidget::refreshUnreadBadge() { - if (!Adaptive::OneColumn() && !_activeChat.folder()) { + if (!Adaptive::OneColumn() && !_activeChat.key.folder()) { _unreadBadge.destroy(); return; } else if (_unreadBadge) { @@ -834,8 +840,9 @@ void TopBarWidget::refreshUnreadBadge() { void TopBarWidget::updateUnreadBadge() { if (!_unreadBadge) return; - const auto muted = session().data().unreadBadgeMutedIgnoreOne(_activeChat); - const auto counter = session().data().unreadBadgeIgnoreOne(_activeChat); + const auto key = _activeChat.key; + const auto muted = session().data().unreadBadgeMutedIgnoreOne(key); + const auto counter = session().data().unreadBadgeIgnoreOne(key); const auto text = [&] { if (!counter) { return QString(); @@ -862,12 +869,15 @@ void TopBarWidget::updateInfoToggleActive() { } void TopBarWidget::updateOnlineDisplay() { - if (!_activeChat.peer()) return; + const auto peer = _activeChat.key.peer(); + if (!peer) { + return; + } QString text; const auto now = base::unixtime::now(); bool titlePeerTextOnline = false; - if (const auto user = _activeChat.peer()->asUser()) { + if (const auto user = peer->asUser()) { if (session().supportMode() && !session().supportHelper().infoCurrent(user).text.empty()) { text = QString::fromUtf8("\xe2\x9a\xa0\xef\xb8\x8f check info"); @@ -876,7 +886,7 @@ void TopBarWidget::updateOnlineDisplay() { text = Data::OnlineText(user, now); titlePeerTextOnline = Data::OnlineTextActive(user, now); } - } else if (const auto chat = _activeChat.peer()->asChat()) { + } else if (const auto chat = peer->asChat()) { if (!chat->amIn()) { text = tr::lng_chat_status_unaccessible(tr::now); } else if (chat->participants.empty()) { @@ -907,7 +917,7 @@ void TopBarWidget::updateOnlineDisplay() { text = tr::lng_group_status(tr::now); } } - } else if (const auto channel = _activeChat.peer()->asChannel()) { + } else if (const auto channel = peer->asChannel()) { if (channel->isMegagroup() && (channel->membersCount() > 0) && (channel->membersCount() @@ -954,7 +964,10 @@ void TopBarWidget::updateOnlineDisplay() { } void TopBarWidget::updateOnlineDisplayTimer() { - if (!_activeChat.peer()) return; + const auto peer = _activeChat.key.peer(); + if (!peer) { + return; + } const auto now = base::unixtime::now(); auto minTimeout = crl::time(86400); @@ -962,13 +975,13 @@ void TopBarWidget::updateOnlineDisplayTimer() { auto hisTimeout = Data::OnlineChangeTimeout(user, now); accumulate_min(minTimeout, hisTimeout); }; - if (const auto user = _activeChat.peer()->asUser()) { + if (const auto user = peer->asUser()) { handleUser(user); - } else if (auto chat = _activeChat.peer()->asChat()) { + } else if (const auto chat = peer->asChat()) { for (const auto user : chat->participants) { handleUser(user); } - } else if (_activeChat.peer()->isChannel()) { + } else if (peer->isChannel()) { } updateOnlineDisplayIn(minTimeout); } diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 770929d0e..bff509316 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -45,10 +45,17 @@ public: }; enum class Section { History, + Dialogs, // For folder view in dialogs list. Scheduled, Pinned, Replies, }; + struct ActiveChat { + Dialogs::Key key; + Section section = Section::History; + MsgId rootId = 0; + MsgId currentReplyToId = 0; + }; TopBarWidget( QWidget *parent, @@ -66,8 +73,7 @@ public: void setAnimatingMode(bool enabled); void setActiveChat( - Dialogs::Key chat, - Section section, + ActiveChat activeChat, SendActionPainter *sendAction); void setCustomTitle(const QString &title); @@ -131,8 +137,7 @@ private: void updateUnreadBadge(); const not_null _controller; - Dialogs::Key _activeChat; - Section _section = Section::History; + ActiveChat _activeChat; QString _customTitleText; int _selectedCount = 0; diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 4190ed4a8..023742cec 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -577,10 +577,11 @@ void WrapWidget::showTopBarMenu() { if (const auto peer = key().peer()) { Window::FillPeerMenu( _controller->parentController(), - peer, - FilterId(), - addAction, - Window::PeerMenuSource::Profile); + Window::PeerMenuRequest{ + .peer = peer, + .source = Window::PeerMenuRequest::Source::Profile, + }, + addAction); //} else if (const auto feed = key().feed()) { // #feed // Window::FillFeedMenu( // _controller->parentController(), diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e74d2118d..8c67fcfcc 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -819,17 +819,6 @@ crl::time MainWidget::highlightStartTime(not_null item) cons return _history->highlightStartTime(item); } -MsgId MainWidget::currentReplyToIdFor(not_null history) const { - if (_mainSection) { - return _mainSection->currentReplyToIdFor(history); - } else if (_history->history() == history) { - return _history->replyToId(); - } else if (const auto localDraft = history->localDraft()) { - return localDraft->msgId; - } - return 0; -} - void MainWidget::sendBotCommand( not_null peer, UserData *bot, diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index c2d0e6adc..cca639af3 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -175,8 +175,6 @@ public: // While HistoryInner is not HistoryView::ListWidget. crl::time highlightStartTime(not_null item) const; - MsgId currentReplyToIdFor(not_null history) const; - void sendBotCommand( not_null peer, UserData *bot, diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index 664fe9710..6d5f3b7fd 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -128,10 +128,6 @@ public: virtual bool replyToMessage(not_null item) { return false; } - [[nodiscard]] virtual MsgId currentReplyToIdFor( - not_null history) const { - return 0; - } // Create a memento of that section to store it in the history stack. // This method may modify the section ("take" heavy items). diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 90088b65e..fd25686f4 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -107,13 +107,13 @@ class Filler { public: Filler( not_null controller, - not_null peer, - FilterId filterId, - const PeerMenuCallback &addAction, - PeerMenuSource source); + PeerMenuRequest request, + const PeerMenuCallback &addAction); void fill(); private: + using Source = PeerMenuRequest::Source; + [[nodiscard]] bool showInfo(); [[nodiscard]] bool showHidePromotion(); [[nodiscard]] bool showToggleArchived(); @@ -132,10 +132,9 @@ private: void addPollAction(not_null peer); not_null _controller; + PeerMenuRequest _request; not_null _peer; - FilterId _filterId = 0; const PeerMenuCallback &_addAction; - PeerMenuSource _source; }; @@ -143,9 +142,8 @@ class FolderFiller { public: FolderFiller( not_null controller, - not_null folder, - const PeerMenuCallback &addAction, - PeerMenuSource source); + FolderMenuRequest request, + const PeerMenuCallback &addAction); void fill(); private: @@ -158,9 +156,9 @@ private: //void addUngroup(); not_null _controller; + FolderMenuRequest _request; not_null _folder; const PeerMenuCallback &_addAction; - PeerMenuSource _source; }; @@ -279,19 +277,16 @@ void TogglePinnedDialog( Filler::Filler( not_null controller, - not_null peer, - FilterId filterId, - const PeerMenuCallback &addAction, - PeerMenuSource source) + PeerMenuRequest request, + const PeerMenuCallback &addAction) : _controller(controller) -, _peer(peer) -, _filterId(filterId) -, _addAction(addAction) -, _source(source) { +, _request(request) +, _peer(request.peer) +, _addAction(addAction) { } bool Filler::showInfo() { - if (_source == PeerMenuSource::Profile + if (_request.source == Source::Profile || _peer->isSelf() || _peer->isRepliesChat()) { return false; @@ -307,7 +302,7 @@ bool Filler::showInfo() { } bool Filler::showHidePromotion() { - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { return false; } const auto history = _peer->owner().historyLoaded(_peer); @@ -317,7 +312,7 @@ bool Filler::showHidePromotion() { } bool Filler::showToggleArchived() { - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { return false; } const auto history = _peer->owner().historyLoaded(_peer); @@ -330,7 +325,7 @@ bool Filler::showToggleArchived() { } bool Filler::showTogglePin() { - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { return false; } const auto history = _peer->owner().historyLoaded(_peer); @@ -349,7 +344,7 @@ void Filler::addHidePromotion() { void Filler::addTogglePin() { const auto controller = _controller; - const auto filterId = _filterId; + const auto filterId = _request.filterId; const auto peer = _peer; const auto history = peer->owner().history(peer); const auto pinText = [=] { @@ -479,7 +474,7 @@ void Filler::addBlockUser(not_null user) { void Filler::addUserActions(not_null user) { const auto controller = _controller; const auto window = &_controller->window(); - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { if (user->session().supportMode()) { _addAction("Edit support info", [=] { user->session().supportHelper().editInfo(controller, user); @@ -527,13 +522,13 @@ void Filler::addUserActions(not_null user) { if (!user->isInaccessible() && user != user->session().user() && !user->isRepliesChat() - && _source != PeerMenuSource::ChatsList) { + && _request.source != Source::ChatsList) { addBlockUser(user); } } void Filler::addChatActions(not_null chat) { - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { const auto controller = _controller; if (EditPeerInfoBox::Available(chat)) { const auto text = tr::lng_manage_group_title(tr::now); @@ -573,7 +568,7 @@ void Filler::addChannelActions(not_null channel) { // [=] { ToggleChannelGrouping(channel, !grouped); }); // } //} - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { if (channel->isBroadcast()) { if (const auto chat = channel->linkedChat()) { _addAction(tr::lng_profile_view_discussion(tr::now), [=] { @@ -623,7 +618,7 @@ void Filler::addChannelActions(not_null channel) { text, [=] { channel->session().api().joinChannel(channel); }); } - if (_source != PeerMenuSource::ChatsList) { + if (_request.source != Source::ChatsList) { const auto needReport = !channel->amCreator() && (!isGroup || channel->isPublic()); if (needReport) { @@ -639,19 +634,26 @@ void Filler::addPollAction(not_null peer) { return; } const auto controller = _controller; - const auto source = (_source == PeerMenuSource::ScheduledSection) + const auto source = (_request.source == Source::ScheduledSection) ? Api::SendType::Scheduled : Api::SendType::Normal; const auto flag = PollData::Flags(); + const auto replyToId = _request.currentReplyToId; auto callback = [=] { - PeerMenuCreatePoll(controller, peer, flag, flag, source); + PeerMenuCreatePoll( + controller, + peer, + replyToId, + flag, + flag, + source); }; _addAction(tr::lng_polls_create(tr::now), std::move(callback)); } void Filler::fill() { - if (_source == PeerMenuSource::ScheduledSection - || _source == PeerMenuSource::RepliesSection) { + if (_request.source == Source::ScheduledSection + || _request.source == Source::RepliesSection) { addPollAction(_peer); return; } @@ -667,10 +669,10 @@ void Filler::fill() { if (showInfo()) { addInfo(); } - if (_source != PeerMenuSource::Profile && !_peer->isSelf()) { + if (_request.source != Source::Profile && !_peer->isSelf()) { PeerMenuAddMuteAction(_peer, _addAction); } - if (_source == PeerMenuSource::ChatsList) { + if (_request.source == Source::ChatsList) { //addSearch(); addToggleUnreadMark(); } @@ -686,19 +688,16 @@ void Filler::fill() { FolderFiller::FolderFiller( not_null controller, - not_null folder, - const PeerMenuCallback &addAction, - PeerMenuSource source) + FolderMenuRequest request, + const PeerMenuCallback &addAction) : _controller(controller) -, _folder(folder) -, _addAction(addAction) -, _source(source) { +, _request(request) +, _folder(request.folder) +, _addAction(addAction) { } void FolderFiller::fill() { - if (_source == PeerMenuSource::ChatsList) { - addTogglesForArchive(); - } + addTogglesForArchive(); } void FolderFiller::addTogglesForArchive() { @@ -838,6 +837,7 @@ void PeerMenuShareContactBox( void PeerMenuCreatePoll( not_null controller, not_null peer, + MsgId replyToId, PollData::Flags chosen, PollData::Flags disabled, Api::SendType sendType) { @@ -859,9 +859,7 @@ void PeerMenuCreatePoll( auto action = Api::SendAction(peer->owner().history(peer)); action.clearDraft = false; action.options = result.options; - if (const auto id = controller->content()->currentReplyToIdFor(action.history)) { - action.replyTo = id; - } + action.replyTo = replyToId; if (const auto localDraft = action.history->localDraft()) { action.clearDraft = localDraft->textWithTags.text.isEmpty(); } @@ -1314,20 +1312,17 @@ Fn DeleteAndLeaveHandler(not_null peer) { void FillPeerMenu( not_null controller, - not_null peer, - FilterId filterId, - const PeerMenuCallback &callback, - PeerMenuSource source) { - Filler filler(controller, peer, filterId, callback, source); + PeerMenuRequest request, + const PeerMenuCallback &callback) { + Filler filler(controller, request, callback); filler.fill(); } void FillFolderMenu( not_null controller, - not_null folder, - const PeerMenuCallback &callback, - PeerMenuSource source) { - FolderFiller filler(controller, folder, callback, source); + FolderMenuRequest request, + const PeerMenuCallback &callback) { + FolderFiller filler(controller, request, callback); filler.fill(); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index f5c9f1a2e..a7944da05 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -32,12 +32,24 @@ class Controller; class SessionController; class SessionNavigation; -enum class PeerMenuSource { - ChatsList, - History, - Profile, - ScheduledSection, - RepliesSection, +struct PeerMenuRequest { + enum class Source { + ChatsList, + History, + Profile, + ScheduledSection, + RepliesSection, + }; + + not_null peer; + Source source = Source::ChatsList; + FilterId filterId = 0; + MsgId rootId = 0; + MsgId currentReplyToId = 0; +}; + +struct FolderMenuRequest { + not_null folder; }; using PeerMenuCallback = Fn controller, - not_null peer, - FilterId filterId, - const PeerMenuCallback &addAction, - PeerMenuSource source); + PeerMenuRequest request, + const PeerMenuCallback &addAction); void FillFolderMenu( not_null controller, - not_null folder, - const PeerMenuCallback &addAction, - PeerMenuSource source); + FolderMenuRequest request, + const PeerMenuCallback &addAction); void PeerMenuAddMuteAction( not_null peer, @@ -80,6 +89,7 @@ void PeerMenuAddChannelMembers( void PeerMenuCreatePoll( not_null controller, not_null peer, + MsgId replyToId = 0, PollData::Flags chosen = PollData::Flags(), PollData::Flags disabled = PollData::Flags(), Api::SendType sendType = Api::SendType::Normal);