Added context menu to bar of pinned messages with bot button.

This commit is contained in:
23rd 2022-10-18 04:11:42 +03:00 committed by John Preston
parent 659a7622be
commit dc8b693f1d
3 changed files with 45 additions and 11 deletions

View File

@ -6351,6 +6351,20 @@ void HistoryWidget::setChooseReportMessagesDetails(
}
void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
const auto openSection = [=] {
const auto id = _pinnedTracker
? _pinnedTracker->currentMessageId()
: HistoryView::PinnedId();
if (!id.message) {
return;
}
controller()->showSection(
std::make_shared<HistoryView::PinnedMemento>(
_history,
((!_migrated || peerIsChannel(id.message.peer))
? id.message.msg
: (id.message.msg - ServerMaxMsgId))));
};
if (const auto replyMarkup = item ? item->inlineReplyMarkup() : nullptr) {
const auto &rows = replyMarkup->data.rows;
if ((rows.size() == 1) && (rows.front().size() == 1)) {
@ -6372,6 +6386,18 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
if (button->width() > st::historyPinnedBotButtonMaxWidth) {
button->setFullWidth(st::historyPinnedBotButtonMaxWidth);
}
struct State {
base::unique_qptr<Ui::PopupMenu> menu;
};
const auto state = button->lifetime().make_state<State>();
_pinnedBar->contextMenuRequested(
) | rpl::start_with_next([=, raw = button.data()] {
state->menu = base::make_unique_q<Ui::PopupMenu>(raw);
state->menu->addAction(
tr::lng_settings_events_pinned(tr::now),
openSection);
state->menu->popup(QCursor::pos());
}, button->lifetime());
_pinnedBar->setRightButton(std::move(button));
return;
}
@ -6386,15 +6412,7 @@ void HistoryWidget::refreshPinnedBarButton(bool many, HistoryItem *item) {
if (close) {
hidePinnedMessage();
} else {
const auto id = _pinnedTracker->currentMessageId();
if (id.message) {
controller()->showSection(
std::make_shared<HistoryView::PinnedMemento>(
_history,
((!_migrated || peerIsChannel(id.message.peer))
? id.message.msg
: (id.message.msg - ServerMaxMsgId))));
}
openSection();
}
}, button->lifetime());
_pinnedBar->setRightButton(std::move(button));

View File

@ -150,10 +150,12 @@ void PinnedBar::createControls() {
_bar->widget()->setCursor(style::cur_pointer);
_bar->widget()->events(
) | rpl::filter([=](not_null<QEvent*> event) {
return (event->type() == QEvent::MouseButtonPress);
return (event->type() == QEvent::MouseButtonPress)
&& (static_cast<QMouseEvent*>(event.get())->button()
== Qt::LeftButton);
}) | rpl::map([=] {
return _bar->widget()->events(
) | rpl::filter([=](not_null<QEvent*> event) {
) | rpl::filter([](not_null<QEvent*> event) {
return (event->type() == QEvent::MouseButtonRelease);
}) | rpl::take(1) | rpl::filter([=](not_null<QEvent*> event) {
return _bar->widget()->rect().contains(
@ -247,4 +249,16 @@ rpl::producer<> PinnedBar::barClicks() const {
return _barClicks.events();
}
rpl::producer<> PinnedBar::contextMenuRequested() const {
return _wrap.entity()->paintRequest(
) | rpl::filter([=] {
return _bar && _bar->widget();
}) | rpl::map([=] {
return _bar->widget()->events(
) | rpl::filter([](not_null<QEvent*> event) {
return (event->type() == QEvent::ContextMenu);
}) | rpl::to_empty;
}) | rpl::flatten_latest();
}
} // namespace Ui

View File

@ -41,6 +41,7 @@ public:
[[nodiscard]] int height() const;
[[nodiscard]] rpl::producer<int> heightValue() const;
[[nodiscard]] rpl::producer<> barClicks() const;
[[nodiscard]] rpl::producer<> contextMenuRequested() const;
[[nodiscard]] rpl::lifetime &lifetime() {
return _wrap.lifetime();
@ -63,6 +64,7 @@ private:
std::unique_ptr<Ui::PlainShadow> _shadow;
Fn<bool()> _customEmojiPaused;
rpl::event_stream<> _barClicks;
rpl::event_stream<> _contextMenuRequested;
Fn<QRect(QRect)> _shadowGeometryPostprocess;
bool _shouldBeShown = false;
bool _forceHidden = false;