Moved default send callbacks to separate functions.

This commit is contained in:
23rd 2020-08-09 14:50:32 +03:00 committed by John Preston
parent edceed28d7
commit 2ac425f350
5 changed files with 37 additions and 36 deletions

View File

@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h"
#include "window/window_session_controller.h"
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_schedule_box.h"
#include "app.h"
#include "storage/storage_account.h" // Account::writeSavedGifs
#include "styles/style_chat_helpers.h"
@ -376,20 +375,11 @@ void GifsListWidget::fillContextMenu(
const auto send = [=](Api::SendOptions options) {
selectInlineResult(row, column, options, true);
};
const auto silent = [=] { send({ .silent = true }); };
const auto schedule = [=] {
Ui::show(
HistoryView::PrepareScheduleBox(
this,
type,
[=](Api::SendOptions options) { send(options); }),
Ui::LayerOption::KeepOther);
};
FillSendMenu(
menu,
[&] { return type; },
silent,
schedule);
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
[&] {
const auto row = _selected / MatrixRowShift;

View File

@ -9,12 +9,33 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_common.h"
#include "base/event_filter.h"
#include "boxes/abstract_box.h"
#include "core/shortcuts.h"
#include "history/view/history_view_schedule_box.h"
#include "lang/lang_keys.h"
#include "ui/widgets/popup_menu.h"
#include <QtWidgets/QApplication>
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send) {
return [=] { send({ .silent = true }); };
}
Fn<void()> DefaultScheduleCallback(
not_null<Ui::RpWidget*> parent,
SendMenuType type,
Fn<void(Api::SendOptions)> send) {
const auto weak = Ui::MakeWeak(parent);
return [=] {
Ui::show(
HistoryView::PrepareScheduleBox(
weak,
type,
[=](Api::SendOptions options) { send(options); }),
Ui::LayerOption::KeepOther);
};
}
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<SendMenuType()> type,

View File

@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rp_widget.h"
namespace Api {
struct SendOptions;
} // namespace Api
namespace Ui {
class PopupMenu;
} // namespace Ui
@ -26,6 +30,12 @@ enum class FillMenuResult {
None,
};
Fn<void()> DefaultSilentCallback(Fn<void(Api::SendOptions)> send);
Fn<void()> DefaultScheduleCallback(
not_null<Ui::RpWidget*> parent,
SendMenuType type,
Fn<void(Api::SendOptions)> send);
FillMenuResult FillSendMenu(
not_null<Ui::PopupMenu*> menu,
Fn<SendMenuType()> type,

View File

@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lottie/lottie_animation.h"
#include "boxes/stickers_box.h"
#include "inline_bots/inline_bot_result.h"
#include "history/view/history_view_schedule_box.h"
#include "storage/storage_account.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
@ -2073,20 +2072,11 @@ void StickersListWidget::fillContextMenu(
.document = document,
.options = options });
};
const auto silent = [=] { send({ .silent = true }); };
const auto schedule = [=] {
checkHideWithBox(Ui::show(
HistoryView::PrepareScheduleBox(
this,
type,
[=](Api::SendOptions options) { send(options); }),
Ui::LayerOption::KeepOther).data());
};
FillSendMenu(
menu,
[&] { return type; },
silent,
schedule);
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
const auto toggleFavedSticker = [=] {
document->session().api().toggleFavedSticker(

View File

@ -34,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/labels.h"
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_schedule_box.h"
#include "facades.h"
#include "app.h"
#include "styles/style_chat_helpers.h"
@ -312,20 +311,11 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) {
const auto send = [=](Api::SendOptions options) {
selectInlineResult(row, column, options);
};
const auto silent = [=] { send({ .silent = true }); };
const auto schedule = [=] {
Ui::show(
HistoryView::PrepareScheduleBox(
this,
type,
[=](Api::SendOptions options) { send(options); }),
Ui::LayerOption::KeepOther);
};
FillSendMenu(
_menu,
[&] { return type; },
silent,
schedule);
DefaultSilentCallback(send),
DefaultScheduleCallback(this, type, send));
if (!_menu->actions().empty()) {
_menu->popup(QCursor::pos());