Show status duration menu only in status panel.

This commit is contained in:
John Preston 2022-09-02 21:12:10 +04:00
parent 49773dde72
commit 898edad09b
8 changed files with 81 additions and 81 deletions

View File

@ -796,26 +796,24 @@ void EmojiListWidget::fillRecentFrom(const std::vector<DocumentId> &list) {
} }
} }
void EmojiListWidget::fillContextMenu( base::unique_qptr<Ui::PopupMenu> EmojiListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) { SendMenu::Type type) {
if (v::is_null(_selected)) { if (_mode != Mode::EmojiStatus || v::is_null(_selected)) {
return; return nullptr;
} }
const auto over = std::get_if<OverEmoji>(&_selected); const auto over = std::get_if<OverEmoji>(&_selected);
if (!over) { if (!over) {
return; return nullptr;
} }
const auto section = over->section; const auto section = over->section;
const auto index = over->index; const auto index = over->index;
// Ignore the default status.
if (!index && (section == int(Section::Recent))) {
return;
}
const auto chosen = lookupCustomEmoji(index, section); const auto chosen = lookupCustomEmoji(index, section);
if (!chosen) { if (!chosen) {
return; return nullptr;
} }
auto menu = base::make_unique_q<Ui::PopupMenu>(
this,
st::defaultPopupMenu);
for (const auto &value : { 3600, 3600 * 8, 3600 * 24, 3600 * 24 * 7 }) { for (const auto &value : { 3600, 3600 * 8, 3600 * 24, 3600 * 24 * 7 }) {
const auto text = tr::lng_emoji_status_menu_duration_any( const auto text = tr::lng_emoji_status_menu_duration_any(
tr::now, tr::now,
@ -833,6 +831,7 @@ void EmojiListWidget::fillContextMenu(
menu->addAction( menu->addAction(
tr::lng_manage_messages_ttl_after_custom(tr::now), tr::lng_manage_messages_ttl_after_custom(tr::now),
crl::guard(this, [=] { selectCustom(chosen, options); })); crl::guard(this, [=] { selectCustom(chosen, options); }));
return menu;
} }
void EmojiListWidget::paintEvent(QPaintEvent *e) { void EmojiListWidget::paintEvent(QPaintEvent *e) {
@ -1094,8 +1093,7 @@ bool EmojiListWidget::checkPickerHide() {
DocumentData *EmojiListWidget::lookupCustomEmoji( DocumentData *EmojiListWidget::lookupCustomEmoji(
int index, int index,
int section) const { int section) const {
if (section == int(Section::Recent) if (section == int(Section::Recent) && index < _recent.size()) {
&& index < _recent.size()) {
const auto document = std::get_if<RecentEmojiDocument>( const auto document = std::get_if<RecentEmojiDocument>(
&_recent[index].id.data); &_recent[index].id.data);
const auto custom = document const auto custom = document

View File

@ -126,8 +126,7 @@ public:
float64 progress, float64 progress,
RectPart origin); RectPart origin);
void fillContextMenu( base::unique_qptr<Ui::PopupMenu> fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) override; SendMenu::Type type) override;
protected: protected:

View File

@ -376,13 +376,15 @@ void GifsListWidget::mousePressEvent(QMouseEvent *e) {
_previewTimer.callOnce(QApplication::startDragTime()); _previewTimer.callOnce(QApplication::startDragTime());
} }
void GifsListWidget::fillContextMenu( base::unique_qptr<Ui::PopupMenu> GifsListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) { SendMenu::Type type) {
if (_selected < 0 || _pressed >= 0) { if (_selected < 0 || _pressed >= 0) {
return; return nullptr;
} }
auto menu = base::make_unique_q<Ui::PopupMenu>(
this,
st::popupMenuWithIcons);
const auto send = [=, selected = _selected](Api::SendOptions options) { const auto send = [=, selected = _selected](Api::SendOptions options) {
selectInlineResult(selected, options, true); selectInlineResult(selected, options, true);
}; };
@ -405,7 +407,8 @@ void GifsListWidget::fillContextMenu(
}; };
AddGifAction(std::move(callback), _controller, document); AddGifAction(std::move(callback), _controller, document);
} }
}; }
return menu;
} }
void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) { void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) {

View File

@ -82,8 +82,7 @@ public:
void cancelled(); void cancelled();
rpl::producer<> cancelRequests() const; rpl::producer<> cancelRequests() const;
void fillContextMenu( base::unique_qptr<Ui::PopupMenu> fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) override; SendMenu::Type type) override;
~GifsListWidget(); ~GifsListWidget();

View File

@ -1542,65 +1542,71 @@ void StickersListWidget::showStickerSetBox(not_null<DocumentData*> document) {
} }
} }
void StickersListWidget::fillContextMenu( base::unique_qptr<Ui::PopupMenu> StickersListWidget::fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) { SendMenu::Type type) {
auto selected = _selected; auto selected = _selected;
auto &sets = shownSets(); auto &sets = shownSets();
if (v::is_null(selected) || !v::is_null(_pressed)) { if (v::is_null(selected) || !v::is_null(_pressed)) {
return; return nullptr;
} }
if (auto sticker = std::get_if<OverSticker>(&selected)) { const auto sticker = std::get_if<OverSticker>(&selected);
const auto section = sticker->section; if (!sticker) {
const auto index = sticker->index; return nullptr;
Assert(section >= 0 && section < sets.size()); }
auto &set = sets[section]; const auto section = sticker->section;
Assert(index >= 0 && index < set.stickers.size()); const auto index = sticker->index;
Assert(section >= 0 && section < sets.size());
auto &set = sets[section];
Assert(index >= 0 && index < set.stickers.size());
const auto document = set.stickers[sticker->index].document; auto menu = base::make_unique_q<Ui::PopupMenu>(
const auto send = [=](Api::SendOptions options) { this,
_chosen.fire({ st::popupMenuWithIcons);
.document = document,
.options = options,
.messageSendingFrom = options.scheduled
? Ui::MessageSendingAnimationFrom()
: messageSentAnimationInfo(section, index, document),
});
};
SendMenu::FillSendMenu(
menu,
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
const auto window = _controller; const auto document = set.stickers[sticker->index].document;
const auto toggleFavedSticker = [=] { const auto send = [=](Api::SendOptions options) {
Api::ToggleFavedSticker( _chosen.fire({
window, .document = document,
.options = options,
.messageSendingFrom = options.scheduled
? Ui::MessageSendingAnimationFrom()
: messageSentAnimationInfo(section, index, document),
});
};
SendMenu::FillSendMenu(
menu,
type,
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
const auto window = _controller;
const auto toggleFavedSticker = [=] {
Api::ToggleFavedSticker(
window,
document,
Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0));
};
const auto isFaved = document->owner().stickers().isFaved(document);
menu->addAction(
(isFaved
? tr::lng_faved_stickers_remove
: tr::lng_faved_stickers_add)(tr::now),
toggleFavedSticker,
isFaved ? &st::menuIconUnfave : &st::menuIconFave);
menu->addAction(tr::lng_context_pack_info(tr::now), [=] {
showStickerSetBox(document);
}, &st::menuIconStickers);
if (const auto id = set.id; id == Data::Stickers::RecentSetId) {
menu->addAction(tr::lng_recent_stickers_remove(tr::now), [=] {
Api::ToggleRecentSticker(
document, document,
Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0)); Data::FileOriginStickerSet(id, 0),
}; false);
const auto isFaved = document->owner().stickers().isFaved(document); }, &st::menuIconDelete);
menu->addAction(
(isFaved
? tr::lng_faved_stickers_remove
: tr::lng_faved_stickers_add)(tr::now),
toggleFavedSticker,
isFaved ? &st::menuIconUnfave : &st::menuIconFave);
menu->addAction(tr::lng_context_pack_info(tr::now), [=] {
showStickerSetBox(document);
}, &st::menuIconStickers);
if (const auto id = set.id; id == Data::Stickers::RecentSetId) {
menu->addAction(tr::lng_recent_stickers_remove(tr::now), [=] {
Api::ToggleRecentSticker(
document,
Data::FileOriginStickerSet(id, 0),
false);
}, &st::menuIconDelete);
}
} }
return menu;
} }
Ui::MessageSendingAnimationFrom StickersListWidget::messageSentAnimationInfo( Ui::MessageSendingAnimationFrom StickersListWidget::messageSentAnimationInfo(

View File

@ -91,8 +91,7 @@ public:
std::shared_ptr<Lottie::FrameRenderer> getLottieRenderer(); std::shared_ptr<Lottie::FrameRenderer> getLottieRenderer();
void fillContextMenu( base::unique_qptr<Ui::PopupMenu> fillContextMenu(
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) override; SendMenu::Type type) override;
bool mySetsEmpty() const; bool mySetsEmpty() const;

View File

@ -1145,12 +1145,8 @@ void TabbedSelector::scrollToY(int y) {
} }
void TabbedSelector::showMenuWithType(SendMenu::Type type) { void TabbedSelector::showMenuWithType(SendMenu::Type type) {
_menu = base::make_unique_q<Ui::PopupMenu>( _menu = currentTab()->widget()->fillContextMenu(type);
this, if (_menu && !_menu->empty()) {
st::popupMenuWithIcons);
currentTab()->widget()->fillContextMenu(_menu, type);
if (!_menu->empty()) {
_menu->popup(QCursor::pos()); _menu->popup(QCursor::pos());
} }
} }

View File

@ -328,9 +328,9 @@ public:
} }
virtual void beforeHiding() { virtual void beforeHiding() {
} }
virtual void fillContextMenu( [[nodiscard]] virtual base::unique_qptr<Ui::PopupMenu> fillContextMenu(
not_null<Ui::PopupMenu*> menu, SendMenu::Type type) {
SendMenu::Type type) { return nullptr;
} }
rpl::producer<int> scrollToRequests() const; rpl::producer<int> scrollToRequests() const;