Added items for polls to context menu in sections.

Fixed #10055.
This commit is contained in:
23rd 2021-01-02 17:36:14 +03:00 committed by John Preston
parent d557e0f2b7
commit 0bdb38753b
4 changed files with 44 additions and 13 deletions

View File

@ -1751,18 +1751,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}
if (const auto media = item->media()) {
if (const auto poll = media->poll()) {
if (!poll->closed()) {
if (poll->voted() && !poll->quiz()) {
_menu->addAction(tr::lng_polls_retract(tr::now), [=] {
session->api().sendPollVotes(itemId, {});
});
}
if (item->canStopPoll()) {
_menu->addAction(tr::lng_polls_stop(tr::now), [=] {
HistoryView::StopPoll(session, itemId);
});
}
}
HistoryView::AddPollActions(
_menu,
poll,
item,
HistoryView::Context::History);
} else if (const auto contact = media->sharedContact()) {
const auto phone = contact->phoneNumber;
_menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] {

View File

@ -868,6 +868,9 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
const auto document = linkDocument
? linkDocument->document().get()
: nullptr;
const auto poll = item
? (item->media() ? item->media()->poll() : nullptr)
: nullptr;
const auto hasSelection = !request.selectedItems.empty()
|| !request.selectedText.empty();
@ -897,6 +900,8 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
// });
// AddToggleGroupingAction(result, linkPeer->peer());
// }
} else if (poll) {
AddPollActions(result, poll, item, list->elementContext());
} else if (!request.overSelection && view && !hasSelection) {
const auto owner = &view->data()->history()->owner();
const auto media = view->media();
@ -979,4 +984,30 @@ void StopPoll(not_null<Main::Session*> session, FullMsgId itemId) {
stop));
}
void AddPollActions(
not_null<Ui::PopupMenu*> menu,
not_null<PollData*> poll,
not_null<HistoryItem*> item,
Context context) {
if ((context != Context::History)
&& (context != Context::Replies)
&& (context != Context::Pinned)) {
return;
}
if (poll->closed()) {
return;
}
const auto itemId = item->fullId();
if (poll->voted() && !poll->quiz()) {
menu->addAction(tr::lng_polls_retract(tr::now), [=] {
poll->session().api().sendPollVotes(itemId, {});
});
}
if (item->canStopPoll()) {
menu->addAction(tr::lng_polls_stop(tr::now), [=] {
StopPoll(&poll->session(), itemId);
});
}
}
} // namespace HistoryView

View File

@ -49,5 +49,10 @@ void CopyPostLink(
FullMsgId itemId,
Context context);
void StopPoll(not_null<Main::Session*> session, FullMsgId itemId);
void AddPollActions(
not_null<Ui::PopupMenu*> menu,
not_null<PollData*> poll,
not_null<HistoryItem*> item,
Context context);
} // namespace

View File

@ -765,7 +765,9 @@ void Poll::draw(Painter &p, const QRect &r, TextSelection selection, crl::time m
: nullptr;
if (animation) {
animation->percent.update(progress, anim::linear);
animation->filling.update(progress, anim::linear);
animation->filling.update(
progress,
showVotes() ? anim::easeOutCirc : anim::linear);
animation->opacity.update(progress, anim::linear);
}
const auto height = paintAnswer(