mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Add new reaction menu to channel comments.
This commit is contained in:
parent
1363faddbf
commit
02daa2a04b
2 changed files with 61 additions and 34 deletions
|
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/media/history_view_sticker.h"
|
||||
#include "history/view/reactions/history_view_reactions_animation.h"
|
||||
#include "history/view/reactions/history_view_reactions_button.h"
|
||||
#include "history/view/reactions/history_view_reactions_selector.h"
|
||||
#include "history/view/history_view_context_menu.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/history_view_emoji_interactions.h"
|
||||
|
@ -359,36 +360,7 @@ ListWidget::ListWidget(
|
|||
_reactionsManager->chosen(
|
||||
) | rpl::start_with_next([=](ChosenReaction reaction) {
|
||||
_reactionsManager->updateButton({});
|
||||
|
||||
const auto item = session().data().message(reaction.context);
|
||||
if (!item) {
|
||||
return;
|
||||
} else if (Window::ShowReactPremiumError(
|
||||
_controller,
|
||||
item,
|
||||
reaction.id)) {
|
||||
if (_menu) {
|
||||
_menu->hideMenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
item->toggleReaction(
|
||||
reaction.id,
|
||||
HistoryItem::ReactionSource::Selector);
|
||||
if (!ranges::contains(item->chosenReactions(), reaction.id)) {
|
||||
return;
|
||||
} else if (const auto view = viewForItem(item)) {
|
||||
const auto geometry = reaction.localGeometry.isEmpty()
|
||||
? mapFromGlobal(reaction.globalGeometry)
|
||||
: reaction.localGeometry;
|
||||
if (const auto top = itemTop(view); top >= 0) {
|
||||
view->animateReaction({
|
||||
.id = reaction.id,
|
||||
.flyIcon = reaction.icon,
|
||||
.flyFrom = geometry.translated(0, -top),
|
||||
});
|
||||
}
|
||||
}
|
||||
reactionChosen(reaction);
|
||||
}, lifetime());
|
||||
|
||||
_reactionsManager->premiumPromoChosen(
|
||||
|
@ -2263,11 +2235,65 @@ void ListWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|||
_overState));
|
||||
|
||||
_menu = FillContextMenu(this, request);
|
||||
if (_menu && !_menu->empty()) {
|
||||
_menu->popup(e->globalPos());
|
||||
e->accept();
|
||||
} else if (_menu) {
|
||||
|
||||
using namespace HistoryView::Reactions;
|
||||
const auto desiredPosition = e->globalPos();
|
||||
const auto reactItem = (_overElement
|
||||
&& _overState.pointState != PointState::Outside)
|
||||
? _overElement->data().get()
|
||||
: nullptr;
|
||||
const auto attached = reactItem
|
||||
? AttachSelectorToMenu(
|
||||
_menu.get(),
|
||||
_controller,
|
||||
desiredPosition,
|
||||
reactItem,
|
||||
[=](ChosenReaction reaction) { reactionChosen(reaction); },
|
||||
[=](FullMsgId context) { ShowPremiumPreviewBox(
|
||||
_controller,
|
||||
PremiumPreview::InfiniteReactions); },
|
||||
_controller->cachedReactionIconFactory().createMethod())
|
||||
: AttachSelectorResult::Skipped;
|
||||
if (attached == AttachSelectorResult::Failed) {
|
||||
_menu = nullptr;
|
||||
return;
|
||||
} else if (attached == AttachSelectorResult::Attached) {
|
||||
_menu->popupPrepared();
|
||||
} else {
|
||||
_menu->popup(desiredPosition);
|
||||
}
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void ListWidget::reactionChosen(ChosenReaction reaction) {
|
||||
const auto item = session().data().message(reaction.context);
|
||||
if (!item) {
|
||||
return;
|
||||
} else if (Window::ShowReactPremiumError(
|
||||
_controller,
|
||||
item,
|
||||
reaction.id)) {
|
||||
if (_menu) {
|
||||
_menu->hideMenu();
|
||||
}
|
||||
return;
|
||||
}
|
||||
item->toggleReaction(
|
||||
reaction.id,
|
||||
HistoryItem::ReactionSource::Selector);
|
||||
if (!ranges::contains(item->chosenReactions(), reaction.id)) {
|
||||
return;
|
||||
} else if (const auto view = viewForItem(item)) {
|
||||
const auto geometry = reaction.localGeometry.isEmpty()
|
||||
? mapFromGlobal(reaction.globalGeometry)
|
||||
: reaction.localGeometry;
|
||||
if (const auto top = itemTop(view); top >= 0) {
|
||||
view->animateReaction({
|
||||
.id = reaction.id,
|
||||
.flyIcon = reaction.icon,
|
||||
.flyFrom = geometry.translated(0, -top),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -417,6 +417,7 @@ private:
|
|||
QPoint mapPointToItem(QPoint point, const Element *view) const;
|
||||
|
||||
void showContextMenu(QContextMenuEvent *e, bool showFromTouch = false);
|
||||
void reactionChosen(ChosenReaction reaction);
|
||||
|
||||
[[nodiscard]] int findItemIndexByY(int y) const;
|
||||
[[nodiscard]] not_null<Element*> findItemByY(int y) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue