mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Finish 'Mark mentions as read' context menu.
This commit is contained in:
parent
badc27eda4
commit
393173c1da
1 changed files with 25 additions and 13 deletions
|
@ -309,6 +309,7 @@ HistoryWidget::HistoryWidget(
|
||||||
|
|
||||||
_historyDown->installEventFilter(this);
|
_historyDown->installEventFilter(this);
|
||||||
_unreadMentions->installEventFilter(this);
|
_unreadMentions->installEventFilter(this);
|
||||||
|
setupUnreadMentionsButtonContextMenu(_unreadMentions.data());
|
||||||
|
|
||||||
InitMessageField(controller, _field);
|
InitMessageField(controller, _field);
|
||||||
|
|
||||||
|
@ -6964,25 +6965,36 @@ void HistoryWidget::synteticScrollToY(int y) {
|
||||||
_synteticScrollEvent = false;
|
_synteticScrollEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::setupUnreadMentionsButtonContextMenu(not_null<Ui::RpWidget*> button) {
|
void HistoryWidget::setupUnreadMentionsButtonContextMenu(
|
||||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
not_null<Ui::RpWidget*> button) {
|
||||||
|
struct State {
|
||||||
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
|
base::flat_set<not_null<PeerData*>> sentForPeers;
|
||||||
|
};
|
||||||
|
const auto state = std::make_shared<State>();
|
||||||
const auto showMenu = [=] {
|
const auto showMenu = [=] {
|
||||||
*menu = base::make_unique_q<Ui::PopupMenu>(button);
|
state->menu = base::make_unique_q<Ui::PopupMenu>(button);
|
||||||
(*menu)->addAction(tr::lng_context_mark_read_mentions_all(tr::now), [=] {
|
const auto text = tr::lng_context_mark_read_mentions_all(tr::now);
|
||||||
if (_history) {
|
const auto peer = _history->peer;
|
||||||
// You must add checks for peer and peer->input validity here and everywhere else in code as well
|
state->menu->addAction(text, [=] {
|
||||||
// Store it somewhere in vector for each chat, if we don't have internet connection check if request already exists in vector,
|
if (!state->sentForPeers.emplace(peer).second) {
|
||||||
// you can either drop and replace or simply put it inside if
|
return;
|
||||||
// Delete this comments when you end
|
|
||||||
_history->session().api().request(MTPmessages_ReadMentions(_history->peer->input)).send();
|
|
||||||
}
|
}
|
||||||
|
peer->session().api().request(MTPmessages_ReadMentions(
|
||||||
|
peer->input
|
||||||
|
)).done([=](const MTPmessages_AffectedHistory &result) {
|
||||||
|
state->sentForPeers.remove(peer);
|
||||||
|
peer->session().api().applyAffectedHistory(peer, result);
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
state->sentForPeers.remove(peer);
|
||||||
|
}).send();
|
||||||
});
|
});
|
||||||
(*menu)->popup(QCursor::pos());
|
state->menu->popup(QCursor::pos());
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||||
if (e->type() == QEvent::ContextMenu && showMenu()) {
|
if (e->type() == QEvent::ContextMenu) {
|
||||||
|
showMenu();
|
||||||
return base::EventFilterResult::Cancel;
|
return base::EventFilterResult::Cancel;
|
||||||
}
|
}
|
||||||
return base::EventFilterResult::Continue;
|
return base::EventFilterResult::Continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue