Support creating polls in RepliesSection.

This commit is contained in:
John Preston 2020-11-10 20:54:43 +03:00
parent a8564b166b
commit 10adbecb9c
7 changed files with 28 additions and 9 deletions

View File

@ -1398,6 +1398,11 @@ bool RepliesWidget::replyToMessage(not_null<HistoryItem*> item) {
return true;
}
MsgId RepliesWidget::currentReplyToIdFor(
not_null<History*> history) const {
return (_history == history) ? replyToId() : 0;
}
void RepliesWidget::saveState(not_null<RepliesMemento*> memento) {
memento->setReplies(_replies);
memento->setReplyReturns(_replyReturns);

View File

@ -88,6 +88,8 @@ public:
const Window::SectionShow &params,
MsgId messageId) override;
bool replyToMessage(not_null<HistoryItem*> item) override;
MsgId currentReplyToIdFor(
not_null<History*> history) const override;
void setInternalState(
const QRect &geometry,

View File

@ -238,9 +238,11 @@ void TopBarWidget::showMenu() {
peer,
FilterId(),
addAction,
(_section == Section::Scheduled)
(_section == Section::Scheduled
? Window::PeerMenuSource::ScheduledSection
: Window::PeerMenuSource::History);
: (_section == Section::Replies)
? Window::PeerMenuSource::RepliesSection
: Window::PeerMenuSource::History));
} else if (const auto folder = _activeChat.folder()) {
Window::FillFolderMenu(
_controller,
@ -686,12 +688,14 @@ void TopBarWidget::updateControlsVisibility() {
_unreadBadge->show();
}
const auto historyMode = (_section == Section::History);
const auto scheduledMode = (_section == Section::Scheduled);
const auto showInScheduledMode = (_activeChat.peer()
&& _activeChat.peer()->canSendPolls());
const auto hasPollsMenu = _activeChat.peer()
&& _activeChat.peer()->canSendPolls();
const auto hasMenu = !_activeChat.folder()
&& ((_section == Section::Scheduled || _section == Section::Replies)
? hasPollsMenu
: historyMode);
updateSearchVisibility();
_menuToggle->setVisible(!_activeChat.folder()
&& (scheduledMode ? showInScheduledMode : historyMode));
_menuToggle->setVisible(hasMenu);
_infoToggle->setVisible(historyMode
&& !_activeChat.folder()
&& !Adaptive::OneColumn()

View File

@ -820,7 +820,9 @@ crl::time MainWidget::highlightStartTime(not_null<const HistoryItem*> item) cons
}
MsgId MainWidget::currentReplyToIdFor(not_null<History*> history) const {
if (_history->history() == history) {
if (_mainSection) {
return _mainSection->currentReplyToIdFor(history);
} else if (_history->history() == history) {
return _history->replyToId();
} else if (const auto localDraft = history->localDraft()) {
return localDraft->msgId;

View File

@ -128,6 +128,10 @@ public:
virtual bool replyToMessage(not_null<HistoryItem*> item) {
return false;
}
[[nodiscard]] virtual MsgId currentReplyToIdFor(
not_null<History*> 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).

View File

@ -650,7 +650,8 @@ void Filler::addPollAction(not_null<PeerData*> peer) {
}
void Filler::fill() {
if (_source == PeerMenuSource::ScheduledSection) {
if (_source == PeerMenuSource::ScheduledSection
|| _source == PeerMenuSource::RepliesSection) {
addPollAction(_peer);
return;
}

View File

@ -37,6 +37,7 @@ enum class PeerMenuSource {
History,
Profile,
ScheduledSection,
RepliesSection,
};
using PeerMenuCallback = Fn<QAction*(