mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Move unread mentions menu to chat_helpers/send_context_menu.
This commit is contained in:
parent
393173c1da
commit
474a6a71d9
4 changed files with 51 additions and 39 deletions
|
@ -14,6 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/view/history_view_schedule_box.h"
|
#include "history/view/history_view_schedule_box.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
|
#include "data/data_peer.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
|
@ -133,4 +136,45 @@ void SetupMenuAndShortcuts(
|
||||||
}, button->lifetime());
|
}, button->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetupUnreadMentionsMenu(
|
||||||
|
not_null<Ui::RpWidget*> button,
|
||||||
|
Fn<PeerData*()> currentPeer) {
|
||||||
|
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 peer = currentPeer();
|
||||||
|
if (!peer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state->menu = base::make_unique_q<Ui::PopupMenu>(button);
|
||||||
|
const auto text = tr::lng_context_mark_read_mentions_all(tr::now);
|
||||||
|
state->menu->addAction(text, [=] {
|
||||||
|
if (!state->sentForPeers.emplace(peer).second) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
state->menu->popup(QCursor::pos());
|
||||||
|
};
|
||||||
|
|
||||||
|
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||||
|
if (e->type() == QEvent::ContextMenu) {
|
||||||
|
showMenu();
|
||||||
|
return base::EventFilterResult::Cancel;
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace SendMenu
|
} // namespace SendMenu
|
||||||
|
|
|
@ -50,4 +50,8 @@ void SetupMenuAndShortcuts(
|
||||||
Fn<void()> silent,
|
Fn<void()> silent,
|
||||||
Fn<void()> schedule);
|
Fn<void()> schedule);
|
||||||
|
|
||||||
|
void SetupUnreadMentionsMenu(
|
||||||
|
not_null<Ui::RpWidget*> button,
|
||||||
|
Fn<PeerData*()> currentPeer);
|
||||||
|
|
||||||
} // namespace SendMenu
|
} // namespace SendMenu
|
||||||
|
|
|
@ -309,7 +309,9 @@ HistoryWidget::HistoryWidget(
|
||||||
|
|
||||||
_historyDown->installEventFilter(this);
|
_historyDown->installEventFilter(this);
|
||||||
_unreadMentions->installEventFilter(this);
|
_unreadMentions->installEventFilter(this);
|
||||||
setupUnreadMentionsButtonContextMenu(_unreadMentions.data());
|
SendMenu::SetupUnreadMentionsMenu(_unreadMentions.data(), [=] {
|
||||||
|
return _history ? _history->peer.get() : nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
InitMessageField(controller, _field);
|
InitMessageField(controller, _field);
|
||||||
|
|
||||||
|
@ -6965,42 +6967,6 @@ void HistoryWidget::synteticScrollToY(int y) {
|
||||||
_synteticScrollEvent = false;
|
_synteticScrollEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::setupUnreadMentionsButtonContextMenu(
|
|
||||||
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 = [=] {
|
|
||||||
state->menu = base::make_unique_q<Ui::PopupMenu>(button);
|
|
||||||
const auto text = tr::lng_context_mark_read_mentions_all(tr::now);
|
|
||||||
const auto peer = _history->peer;
|
|
||||||
state->menu->addAction(text, [=] {
|
|
||||||
if (!state->sentForPeers.emplace(peer).second) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
state->menu->popup(QCursor::pos());
|
|
||||||
};
|
|
||||||
|
|
||||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
|
||||||
if (e->type() == QEvent::ContextMenu) {
|
|
||||||
showMenu();
|
|
||||||
return base::EventFilterResult::Cancel;
|
|
||||||
}
|
|
||||||
return base::EventFilterResult::Continue;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
HistoryWidget::~HistoryWidget() {
|
HistoryWidget::~HistoryWidget() {
|
||||||
if (_history) {
|
if (_history) {
|
||||||
// Saving a draft on account switching.
|
// Saving a draft on account switching.
|
||||||
|
|
|
@ -597,8 +597,6 @@ private:
|
||||||
|
|
||||||
bool kbWasHidden() const;
|
bool kbWasHidden() const;
|
||||||
|
|
||||||
void setupUnreadMentionsButtonContextMenu(not_null<Ui::RpWidget*> button);
|
|
||||||
|
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
MsgId _replyToId = 0;
|
MsgId _replyToId = 0;
|
||||||
Ui::Text::String _replyToName;
|
Ui::Text::String _replyToName;
|
||||||
|
|
Loading…
Add table
Reference in a new issue