2017-11-06 18:03:20 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-11-06 18:03:20 +00:00
|
|
|
*/
|
|
|
|
#include "window/window_peer_menu.h"
|
|
|
|
|
2022-12-02 00:40:16 +00:00
|
|
|
#include "menu/menu_check_item.h"
|
|
|
|
#include "boxes/share_box.h"
|
2023-05-02 09:33:19 +00:00
|
|
|
#include "chat_helpers/compose/compose_show.h"
|
2022-12-02 00:40:16 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
2021-11-24 04:25:05 +00:00
|
|
|
#include "api/api_chat_participants.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2022-11-01 09:00:17 +00:00
|
|
|
#include "base/random.h"
|
2022-02-01 15:19:47 +00:00
|
|
|
#include "base/options.h"
|
2022-03-30 19:57:36 +00:00
|
|
|
#include "base/unixtime.h"
|
2021-10-18 20:55:58 +00:00
|
|
|
#include "boxes/delete_messages_box.h"
|
2021-10-18 21:12:11 +00:00
|
|
|
#include "boxes/max_invite_box.h"
|
2022-04-05 20:51:42 +00:00
|
|
|
#include "boxes/choose_filter_box.h"
|
2018-12-20 16:02:44 +00:00
|
|
|
#include "boxes/create_poll_box.h"
|
2021-10-18 20:37:25 +00:00
|
|
|
#include "boxes/pin_messages_box.h"
|
2022-05-06 15:13:25 +00:00
|
|
|
#include "boxes/premium_limits_box.h"
|
2022-04-17 10:30:08 +00:00
|
|
|
#include "boxes/report_messages_box.h"
|
2022-03-23 14:22:09 +00:00
|
|
|
#include "boxes/peers/add_bot_to_chat_box.h"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/add_participants_box.h"
|
2022-09-27 12:05:47 +00:00
|
|
|
#include "boxes/peers/edit_forum_topic_box.h"
|
2019-06-12 14:13:49 +00:00
|
|
|
#include "boxes/peers/edit_contact_box.h"
|
2022-10-28 13:21:11 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2023-05-24 15:36:58 +00:00
|
|
|
#include "inline_bots/bot_attach_web_view.h" // InlineBots::PeerType.
|
2021-02-15 17:37:22 +00:00
|
|
|
#include "ui/boxes/report_box.h"
|
2017-12-06 10:13:38 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2022-03-30 19:57:36 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2022-11-01 15:23:52 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
|
|
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2023-02-03 15:32:25 +00:00
|
|
|
#include "ui/delayed_activation.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2022-03-28 18:11:37 +00:00
|
|
|
#include "menu/menu_mute.h"
|
2022-03-28 23:53:25 +00:00
|
|
|
#include "menu/menu_ttl_validator.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2021-08-01 22:57:36 +00:00
|
|
|
#include "api/api_blocked_peers.h"
|
2020-03-17 14:52:01 +00:00
|
|
|
#include "api/api_chat_filters.h"
|
2021-10-20 19:56:10 +00:00
|
|
|
#include "api/api_polls.h"
|
2020-09-25 12:31:36 +00:00
|
|
|
#include "api/api_updates.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2022-12-14 12:15:46 +00:00
|
|
|
#include "history/history_item_helpers.h" // GetErrorTextForSending.
|
2021-02-15 17:37:22 +00:00
|
|
|
#include "history/view/history_view_context_menu.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "window/window_controller.h"
|
2023-08-11 14:20:38 +00:00
|
|
|
#include "settings/settings_advanced.h"
|
2018-11-20 15:36:36 +00:00
|
|
|
#include "support/support_helper.h"
|
2018-02-16 15:46:24 +00:00
|
|
|
#include "info/info_controller.h"
|
2023-10-11 21:53:16 +00:00
|
|
|
#include "info/info_memento.h"
|
2023-10-21 20:55:17 +00:00
|
|
|
#include "info/boosts/info_boosts_widget.h"
|
2018-04-09 17:48:29 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2023-10-02 15:36:25 +00:00
|
|
|
#include "info/statistics/info_statistics_widget.h"
|
2023-09-05 07:07:32 +00:00
|
|
|
#include "info/stories/info_stories_widget.h"
|
2022-04-01 10:18:07 +00:00
|
|
|
#include "data/notify/data_notify_settings.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2018-12-22 21:31:12 +00:00
|
|
|
#include "data/data_poll.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
2022-10-14 13:25:05 +00:00
|
|
|
#include "data/data_forum.h"
|
2022-09-27 12:05:47 +00:00
|
|
|
#include "data/data_forum_topic.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-08-09 17:58:58 +00:00
|
|
|
#include "data/data_scheduled_messages.h"
|
2020-02-19 15:35:26 +00:00
|
|
|
#include "data/data_histories.h"
|
2020-03-17 14:52:01 +00:00
|
|
|
#include "data/data_chat_filters.h"
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2020-06-25 07:14:05 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "export/export_manager.h"
|
2019-03-17 10:06:00 +00:00
|
|
|
#include "boxes/peers/edit_peer_info_box.h"
|
2023-02-03 15:32:25 +00:00
|
|
|
#include "styles/style_chat.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-04-18 08:28:43 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_window.h" // st::windowMinWidth
|
2021-12-09 17:56:24 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
#include <QAction>
|
2022-12-06 19:11:11 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
2019-09-04 07:19:15 +00:00
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
namespace Window {
|
2022-10-14 13:25:05 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-10-26 09:30:10 +00:00
|
|
|
constexpr auto kTopicsSearchMinCount = 1;
|
2022-10-14 13:25:05 +00:00
|
|
|
|
2022-11-01 09:00:17 +00:00
|
|
|
void ShareBotGame(
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
not_null<Data::Thread*> thread,
|
|
|
|
const QString &shortName) {
|
|
|
|
auto &histories = thread->owner().histories();
|
|
|
|
const auto history = thread->owningHistory();
|
|
|
|
const auto randomId = base::RandomValue<uint64>();
|
|
|
|
const auto replyTo = thread->topicRootId();
|
|
|
|
const auto topicRootId = replyTo;
|
|
|
|
auto flags = MTPmessages_SendMedia::Flags(0);
|
|
|
|
if (replyTo) {
|
2023-05-25 09:32:13 +00:00
|
|
|
flags |= MTPmessages_SendMedia::Flag::f_reply_to;
|
2022-11-01 09:00:17 +00:00
|
|
|
}
|
|
|
|
histories.sendPreparedMessage(
|
|
|
|
history,
|
2023-10-10 06:49:22 +00:00
|
|
|
FullReplyTo{
|
|
|
|
.messageId = { replyTo ? history->peer->id : 0, replyTo },
|
|
|
|
.topicRootId = topicRootId,
|
|
|
|
},
|
2022-11-01 09:00:17 +00:00
|
|
|
randomId,
|
|
|
|
Data::Histories::PrepareMessage<MTPmessages_SendMedia>(
|
|
|
|
MTP_flags(flags),
|
|
|
|
history->peer->input,
|
|
|
|
Data::Histories::ReplyToPlaceholder(),
|
|
|
|
MTP_inputMediaGame(
|
|
|
|
MTP_inputGameShortName(
|
|
|
|
bot->inputUser,
|
|
|
|
MTP_string(shortName))),
|
|
|
|
MTP_string(),
|
|
|
|
MTP_long(randomId),
|
|
|
|
MTPReplyMarkup(),
|
|
|
|
MTPVector<MTPMessageEntity>(),
|
|
|
|
MTP_int(0), // schedule_date
|
|
|
|
MTPInputPeer() // send_as
|
|
|
|
), [=](const MTPUpdates &, const MTP::Response &) {
|
|
|
|
}, [=](const MTP::Error &error, const MTP::Response &) {
|
|
|
|
history->session().api().sendMessageFail(error, history->peer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
} // namespace
|
2022-02-01 15:19:47 +00:00
|
|
|
|
|
|
|
const char kOptionViewProfileInChatsListContextMenu[] =
|
|
|
|
"view-profile-in-chats-list-context-menu";
|
|
|
|
|
2017-11-07 13:13:41 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-06-24 09:14:19 +00:00
|
|
|
constexpr auto kArchivedToastDuration = crl::time(5000);
|
2022-02-21 01:17:19 +00:00
|
|
|
constexpr auto kMaxUnreadWithoutConfirmation = 1000;
|
2019-04-25 09:20:20 +00:00
|
|
|
|
2022-02-01 15:19:47 +00:00
|
|
|
base::options::toggle ViewProfileInChatsListContextMenu({
|
|
|
|
.id = kOptionViewProfileInChatsListContextMenu,
|
|
|
|
.name = "Add \"View Profile\"",
|
|
|
|
.description = "Add \"View Profile\" to context menu in chats list",
|
|
|
|
});
|
|
|
|
|
2020-09-30 11:59:54 +00:00
|
|
|
void SetActionText(not_null<QAction*> action, rpl::producer<QString> &&text) {
|
|
|
|
const auto lifetime = Ui::CreateChild<rpl::lifetime>(action.get());
|
|
|
|
std::move(
|
|
|
|
text
|
|
|
|
) | rpl::start_with_next([=](const QString &actionText) {
|
|
|
|
action->setText(actionText);
|
|
|
|
}, *lifetime);
|
|
|
|
}
|
|
|
|
|
2020-09-17 14:56:01 +00:00
|
|
|
void MarkAsReadChatList(not_null<Dialogs::MainList*> list) {
|
2020-09-25 17:22:43 +00:00
|
|
|
auto mark = std::vector<not_null<History*>>();
|
2020-09-17 14:56:01 +00:00
|
|
|
for (const auto &row : list->indexed()->all()) {
|
|
|
|
if (const auto history = row->history()) {
|
2020-09-25 17:22:43 +00:00
|
|
|
mark.push_back(history);
|
2020-09-17 14:56:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-14 13:25:05 +00:00
|
|
|
ranges::for_each(mark, MarkAsReadThread);
|
2020-09-17 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 18:11:37 +00:00
|
|
|
void PeerMenuAddMuteSubmenuAction(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2022-10-13 17:34:04 +00:00
|
|
|
not_null<Data::Thread*> thread,
|
2022-03-28 18:11:37 +00:00
|
|
|
const PeerMenuCallback &addAction) {
|
2022-10-13 17:34:04 +00:00
|
|
|
const auto notifySettings = &thread->owner().notifySettings();
|
|
|
|
notifySettings->request(thread);
|
2022-10-19 10:59:37 +00:00
|
|
|
const auto weak = base::make_weak(thread);
|
2022-10-13 17:34:04 +00:00
|
|
|
const auto with = [=](Fn<void(not_null<Data::Thread*>)> callback) {
|
|
|
|
return [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
callback(strong);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const auto isMuted = notifySettings->isMuted(thread);
|
2022-03-28 18:11:37 +00:00
|
|
|
if (isMuted) {
|
2022-03-30 21:34:21 +00:00
|
|
|
const auto text = tr::lng_context_unmute(tr::now)
|
2022-03-30 19:57:36 +00:00
|
|
|
+ '\t'
|
2022-10-13 17:34:04 +00:00
|
|
|
+ Ui::FormatMuteForTiny(thread->notify().muteUntil().value_or(0)
|
2022-03-30 19:57:36 +00:00
|
|
|
- base::unixtime::now());
|
2022-10-13 17:34:04 +00:00
|
|
|
addAction(text, with([=](not_null<Data::Thread*> thread) {
|
|
|
|
notifySettings->update(thread, { .unmute = true });
|
|
|
|
}), &st::menuIconUnmute);
|
2022-03-28 18:11:37 +00:00
|
|
|
} else {
|
2023-05-02 09:33:19 +00:00
|
|
|
const auto show = controller->uiShow();
|
2022-03-28 18:11:37 +00:00
|
|
|
addAction(PeerMenuCallback::Args{
|
2022-03-30 21:34:21 +00:00
|
|
|
.text = tr::lng_context_mute(tr::now),
|
2022-03-28 18:11:37 +00:00
|
|
|
.handler = nullptr,
|
2022-10-13 17:34:04 +00:00
|
|
|
.icon = (notifySettings->sound(thread).none
|
2022-03-28 18:11:37 +00:00
|
|
|
? &st::menuIconSilent
|
2022-10-13 17:34:04 +00:00
|
|
|
: &st::menuIconMute),
|
2022-11-01 15:23:52 +00:00
|
|
|
.fillSubmenu = [&](not_null<Ui::PopupMenu*> menu) {
|
|
|
|
MuteMenu::FillMuteMenu(menu, thread, show);
|
2022-03-28 18:11:37 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-01 04:46:31 +00:00
|
|
|
void ForwardToSelf(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Main::SessionShow> show,
|
2022-11-01 04:46:31 +00:00
|
|
|
const Data::ForwardDraft &draft) {
|
2023-05-02 09:33:19 +00:00
|
|
|
const auto session = &show->session();
|
2022-11-01 04:46:31 +00:00
|
|
|
const auto history = session->data().history(session->user());
|
|
|
|
auto resolved = history->resolveForwardDraft(draft);
|
|
|
|
if (!resolved.items.empty()) {
|
|
|
|
auto action = Api::SendAction(history);
|
|
|
|
action.clearDraft = false;
|
|
|
|
action.generateLocal = false;
|
|
|
|
session->api().forwardMessages(
|
|
|
|
std::move(resolved),
|
|
|
|
action,
|
2023-05-02 09:33:19 +00:00
|
|
|
[=] { show->showToast(tr::lng_share_done(tr::now)); });
|
2022-11-01 04:46:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
class Filler {
|
|
|
|
public:
|
|
|
|
Filler(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState request,
|
2020-11-11 20:47:40 +00:00
|
|
|
const PeerMenuCallback &addAction);
|
2017-11-06 18:03:20 +00:00
|
|
|
void fill();
|
|
|
|
|
|
|
|
private:
|
2020-11-12 15:46:17 +00:00
|
|
|
using Section = Dialogs::EntryState::Section;
|
2020-11-11 20:47:40 +00:00
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void fillChatsListActions();
|
|
|
|
void fillHistoryActions();
|
|
|
|
void fillProfileActions();
|
|
|
|
void fillRepliesActions();
|
|
|
|
void fillScheduledActions();
|
|
|
|
void fillArchiveActions();
|
2022-10-14 13:25:05 +00:00
|
|
|
void fillContextMenuActions();
|
2022-01-03 15:16:19 +00:00
|
|
|
|
2020-04-29 10:42:24 +00:00
|
|
|
void addHidePromotion();
|
2019-05-01 13:10:11 +00:00
|
|
|
void addTogglePin();
|
2022-03-28 18:11:37 +00:00
|
|
|
void addToggleMuteSubmenu(bool addSeparator);
|
2022-01-03 15:16:19 +00:00
|
|
|
void addSupportInfo();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addInfo();
|
2023-09-05 07:07:32 +00:00
|
|
|
void addStoryArchive();
|
2023-02-03 15:32:25 +00:00
|
|
|
void addNewWindow();
|
2022-04-05 20:51:42 +00:00
|
|
|
void addToggleFolder();
|
2018-06-26 18:03:45 +00:00
|
|
|
void addToggleUnreadMark();
|
2019-04-18 08:28:43 +00:00
|
|
|
void addToggleArchive();
|
2022-01-03 15:16:19 +00:00
|
|
|
void addClearHistory();
|
|
|
|
void addDeleteChat();
|
|
|
|
void addLeaveChat();
|
2022-10-14 13:25:05 +00:00
|
|
|
void addJoinChat();
|
2022-12-06 19:11:11 +00:00
|
|
|
void addTopicLink();
|
2022-09-27 12:05:47 +00:00
|
|
|
void addManageTopic();
|
2022-01-03 15:16:19 +00:00
|
|
|
void addManageChat();
|
|
|
|
void addCreatePoll();
|
|
|
|
void addThemeEdit();
|
|
|
|
void addBlockUser();
|
|
|
|
void addViewDiscussion();
|
2022-10-18 15:39:41 +00:00
|
|
|
void addToggleTopicClosed();
|
2022-01-03 15:16:19 +00:00
|
|
|
void addExportChat();
|
2023-01-30 14:47:03 +00:00
|
|
|
void addTranslate();
|
2022-01-03 15:16:19 +00:00
|
|
|
void addReport();
|
|
|
|
void addNewContact();
|
|
|
|
void addShareContact();
|
|
|
|
void addEditContact();
|
|
|
|
void addBotToGroup();
|
|
|
|
void addNewMembers();
|
|
|
|
void addDeleteContact();
|
2022-03-28 23:53:25 +00:00
|
|
|
void addTTLSubmenu(bool addSeparator);
|
2022-07-03 14:56:12 +00:00
|
|
|
void addGiftPremium();
|
2022-10-14 13:25:05 +00:00
|
|
|
void addCreateTopic();
|
2022-10-18 12:37:51 +00:00
|
|
|
void addViewAsMessages();
|
2022-10-14 13:25:05 +00:00
|
|
|
void addSearchTopics();
|
2022-10-18 15:39:41 +00:00
|
|
|
void addDeleteTopic();
|
2022-11-01 15:23:52 +00:00
|
|
|
void addVideoChat();
|
2023-04-26 18:49:51 +00:00
|
|
|
void addViewStatistics();
|
2022-01-03 15:16:19 +00:00
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> _controller;
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState _request;
|
2022-10-13 17:34:04 +00:00
|
|
|
Data::Thread *_thread = nullptr;
|
2022-10-14 13:25:05 +00:00
|
|
|
Data::ForumTopic *_topic = nullptr;
|
2020-11-12 15:46:17 +00:00
|
|
|
PeerData *_peer = nullptr;
|
|
|
|
Data::Folder *_folder = nullptr;
|
2019-05-03 10:55:44 +00:00
|
|
|
const PeerMenuCallback &_addAction;
|
2018-01-05 15:57:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
History *FindWastedPin(not_null<Data::Session*> data, Data::Folder *folder) {
|
2022-11-08 13:57:54 +00:00
|
|
|
const auto &order = data->pinnedChatsOrder(folder);
|
2019-04-18 08:28:43 +00:00
|
|
|
for (const auto &pinned : order) {
|
2018-01-04 19:54:35 +00:00
|
|
|
if (const auto history = pinned.history()) {
|
|
|
|
if (history->peer->isChat()
|
|
|
|
&& history->peer->asChat()->isDeactivated()
|
2019-04-22 14:22:39 +00:00
|
|
|
&& !history->inChatList()) {
|
2018-01-04 19:54:35 +00:00
|
|
|
return history;
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
void AddChatMembers(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChatData*> chat) {
|
|
|
|
AddParticipantsBoxController::Start(navigation, chat);
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 01:17:19 +00:00
|
|
|
bool PinnedLimitReached(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2022-11-08 13:57:54 +00:00
|
|
|
not_null<Data::Thread*> thread) {
|
|
|
|
const auto owner = &thread->owner();
|
|
|
|
if (owner->pinnedCanPin(thread)) {
|
2018-01-05 15:57:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Some old chat, that was converted, maybe is still pinned.
|
2022-11-08 13:57:54 +00:00
|
|
|
const auto history = thread->asHistory();
|
|
|
|
if (!history) {
|
2022-11-08 14:49:53 +00:00
|
|
|
controller->show(Box(ForumPinsLimitBox, thread->asTopic()->forum()));
|
2022-11-08 13:57:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto folder = history->folder();
|
|
|
|
const auto wasted = FindWastedPin(owner, folder);
|
2020-03-17 13:04:30 +00:00
|
|
|
if (wasted) {
|
|
|
|
owner->setChatPinned(wasted, FilterId(), false);
|
2022-03-14 07:11:14 +00:00
|
|
|
owner->setChatPinned(history, FilterId(), true);
|
|
|
|
history->session().api().savePinnedOrder(folder);
|
2022-05-09 13:09:46 +00:00
|
|
|
} else if (folder) {
|
|
|
|
controller->show(Box(FolderPinsLimitBox, &history->session()));
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
2022-05-09 13:09:46 +00:00
|
|
|
controller->show(Box(PinsLimitBox, &history->session()));
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-08 13:57:54 +00:00
|
|
|
bool PinnedLimitReached(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<History*> history,
|
|
|
|
FilterId filterId) {
|
|
|
|
const auto owner = &history->owner();
|
|
|
|
if (owner->pinnedCanPin(filterId, history)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
controller->show(
|
|
|
|
Box(FilterPinsLimitBox, &history->session(), filterId));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-19 08:19:11 +00:00
|
|
|
void TogglePinnedThread(
|
2020-06-11 16:33:15 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-10-19 08:19:11 +00:00
|
|
|
not_null<Data::Thread*> thread) {
|
|
|
|
if (!thread->folderKnown()) {
|
2019-04-19 08:47:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-19 08:19:11 +00:00
|
|
|
const auto owner = &thread->owner();
|
2022-11-08 14:49:53 +00:00
|
|
|
const auto isPinned = !thread->isPinnedDialog(FilterId());
|
|
|
|
if (isPinned && PinnedLimitReached(controller, thread)) {
|
|
|
|
return;
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 08:19:11 +00:00
|
|
|
owner->setChatPinned(thread, FilterId(), isPinned);
|
|
|
|
if (const auto history = thread->asHistory()) {
|
|
|
|
const auto flags = isPinned
|
|
|
|
? MTPmessages_ToggleDialogPin::Flag::f_pinned
|
|
|
|
: MTPmessages_ToggleDialogPin::Flag(0);
|
|
|
|
owner->session().api().request(MTPmessages_ToggleDialogPin(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_inputDialogPeer(history->peer->input)
|
|
|
|
)).done([=] {
|
|
|
|
owner->notifyPinnedDialogsOrderUpdated();
|
|
|
|
}).send();
|
|
|
|
if (isPinned) {
|
|
|
|
controller->content()->dialogsToUp();
|
|
|
|
}
|
|
|
|
} else if (const auto topic = thread->asTopic()) {
|
|
|
|
owner->session().api().request(MTPchannels_UpdatePinnedForumTopic(
|
|
|
|
topic->channel()->inputChannel,
|
|
|
|
MTP_int(topic->rootId()),
|
|
|
|
MTP_bool(isPinned)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
owner->session().api().applyUpdates(result);
|
|
|
|
}).send();
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 08:19:11 +00:00
|
|
|
void TogglePinnedThread(
|
2020-06-11 16:33:15 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-10-19 08:19:11 +00:00
|
|
|
not_null<Data::Thread*> thread,
|
2020-06-11 16:33:15 +00:00
|
|
|
FilterId filterId) {
|
2020-03-17 13:04:30 +00:00
|
|
|
if (!filterId) {
|
2022-10-19 08:19:11 +00:00
|
|
|
return TogglePinnedThread(controller, thread);
|
|
|
|
}
|
|
|
|
const auto history = thread->asHistory();
|
|
|
|
if (!history) {
|
|
|
|
return;
|
2020-03-17 13:04:30 +00:00
|
|
|
}
|
2022-03-14 07:11:14 +00:00
|
|
|
const auto owner = &history->owner();
|
2020-04-29 17:40:09 +00:00
|
|
|
|
|
|
|
// This can happen when you remove this filter from another client.
|
|
|
|
if (!ranges::contains(
|
2022-06-14 09:48:25 +00:00
|
|
|
(&owner->session())->data().chatsFilters().list(),
|
|
|
|
filterId,
|
|
|
|
&Data::ChatFilter::id)) {
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->showToast(tr::lng_cant_do_this(tr::now));
|
2020-04-29 17:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-14 07:11:14 +00:00
|
|
|
const auto isPinned = !history->isPinnedDialog(filterId);
|
|
|
|
if (isPinned && PinnedLimitReached(controller, history, filterId)) {
|
2020-03-17 13:04:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-14 07:11:14 +00:00
|
|
|
owner->setChatPinned(history, filterId, isPinned);
|
2020-03-17 14:52:01 +00:00
|
|
|
Api::SaveNewFilterPinned(&owner->session(), filterId);
|
2020-03-17 13:04:30 +00:00
|
|
|
if (isPinned) {
|
2020-06-11 16:33:15 +00:00
|
|
|
controller->content()->dialogsToUp();
|
2020-03-17 13:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
Filler::Filler(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState request,
|
2020-11-11 20:47:40 +00:00
|
|
|
const PeerMenuCallback &addAction)
|
2017-11-07 11:53:05 +00:00
|
|
|
: _controller(controller)
|
2020-11-11 20:47:40 +00:00
|
|
|
, _request(request)
|
2022-10-13 17:34:04 +00:00
|
|
|
, _thread(request.key.thread())
|
2022-10-14 13:25:05 +00:00
|
|
|
, _topic(request.key.topic())
|
2020-11-12 15:46:17 +00:00
|
|
|
, _peer(request.key.peer())
|
|
|
|
, _folder(request.key.folder())
|
2020-11-11 20:47:40 +00:00
|
|
|
, _addAction(addAction) {
|
2017-11-07 15:12:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addHidePromotion() {
|
2022-09-27 12:05:47 +00:00
|
|
|
const auto history = _request.key.history();
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_topic
|
|
|
|
|| !history
|
2022-01-03 15:16:19 +00:00
|
|
|
|| !history->useTopPromotion()
|
|
|
|
|| history->topPromotionType().isEmpty()) {
|
|
|
|
return;
|
2019-05-01 13:10:11 +00:00
|
|
|
}
|
2020-04-29 10:42:24 +00:00
|
|
|
_addAction(tr::lng_context_hide_psa(tr::now), [=] {
|
|
|
|
history->cacheTopPromotion(false, QString(), QString());
|
|
|
|
history->session().api().request(MTPhelp_HidePromoData(
|
|
|
|
history->peer->input
|
|
|
|
)).send();
|
2021-12-09 17:56:24 +00:00
|
|
|
}, &st::menuIconRemove);
|
2020-04-29 10:42:24 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 15:39:41 +00:00
|
|
|
void Filler::addToggleTopicClosed() {
|
|
|
|
if (!_topic || !_topic->canToggleClosed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto closed = _topic->closed();
|
|
|
|
const auto weak = base::make_weak(_topic);
|
2022-10-21 12:32:23 +00:00
|
|
|
_addAction(closed ? tr::lng_forum_topic_reopen(tr::now) : tr::lng_forum_topic_close(tr::now), [=] {
|
2022-10-18 15:39:41 +00:00
|
|
|
if (const auto topic = weak.get()) {
|
|
|
|
topic->setClosedAndSave(!closed);
|
|
|
|
}
|
|
|
|
}, closed ? &st::menuIconRestartBot : &st::menuIconBlock);
|
|
|
|
}
|
|
|
|
|
2019-05-01 13:10:11 +00:00
|
|
|
void Filler::addTogglePin() {
|
2022-10-19 08:19:11 +00:00
|
|
|
if (!_peer || (_topic && !_topic->canTogglePinned())) {
|
2022-09-27 12:05:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-17 14:00:20 +00:00
|
|
|
const auto controller = _controller;
|
2020-11-11 20:47:40 +00:00
|
|
|
const auto filterId = _request.filterId;
|
2022-10-19 08:19:11 +00:00
|
|
|
const auto thread = _request.key.thread();
|
|
|
|
if (!thread || thread->fixedOnTopIndex()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto pinText = [=] {
|
2022-10-19 08:19:11 +00:00
|
|
|
return thread->isPinnedDialog(filterId)
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_unpin_from_top(tr::now)
|
|
|
|
: tr::lng_context_pin_to_top(tr::now);
|
2017-11-06 18:03:20 +00:00
|
|
|
};
|
2022-10-19 08:19:11 +00:00
|
|
|
const auto weak = base::make_weak(thread);
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto pinToggle = [=] {
|
2022-10-19 08:19:11 +00:00
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
TogglePinnedThread(controller, strong, filterId);
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
};
|
2022-11-02 04:51:03 +00:00
|
|
|
_addAction(
|
2021-12-09 17:56:24 +00:00
|
|
|
pinText(),
|
|
|
|
pinToggle,
|
2022-10-19 08:19:11 +00:00
|
|
|
(thread->isPinnedDialog(filterId)
|
2021-12-09 17:56:24 +00:00
|
|
|
? &st::menuIconUnpin
|
2021-12-10 12:10:14 +00:00
|
|
|
: &st::menuIconPin));
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 18:11:37 +00:00
|
|
|
void Filler::addToggleMuteSubmenu(bool addSeparator) {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (_thread->peer()->isSelf()) {
|
2022-03-28 18:11:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-13 17:34:04 +00:00
|
|
|
PeerMenuAddMuteSubmenuAction(_controller, _thread, _addAction);
|
2022-03-28 18:11:37 +00:00
|
|
|
if (addSeparator) {
|
|
|
|
_addAction(PeerMenuCallback::Args{ .isSeparator = true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addSupportInfo() {
|
|
|
|
if (!_peer->session().supportMode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction("Edit support info", [=] {
|
|
|
|
user->session().supportHelper().editInfo(controller, user);
|
|
|
|
}, &st::menuIconEdit);
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::addInfo() {
|
2022-09-27 12:05:47 +00:00
|
|
|
if (_peer && (_peer->isSelf() || _peer->isRepliesChat())) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
} else if (_controller->adaptive().isThreeColumn()) {
|
2022-10-13 17:34:04 +00:00
|
|
|
const auto thread = _controller->activeChatCurrent().thread();
|
|
|
|
if (thread && thread == _thread) {
|
2022-08-16 04:41:32 +00:00
|
|
|
if (Core::App().settings().thirdSectionInfoEnabled()
|
|
|
|
|| Core::App().settings().tabbedReplacedWithInfo()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
2022-10-13 17:34:04 +00:00
|
|
|
} else if (!_thread) {
|
|
|
|
return;
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto controller = _controller;
|
2022-10-13 17:34:04 +00:00
|
|
|
const auto weak = base::make_weak(_thread);
|
|
|
|
const auto text = _thread->asTopic()
|
2022-10-14 13:25:05 +00:00
|
|
|
? tr::lng_context_view_topic(tr::now)
|
2022-10-13 17:34:04 +00:00
|
|
|
: (_peer->isChat() || _peer->isMegagroup())
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_view_group(tr::now)
|
2022-10-13 17:34:04 +00:00
|
|
|
: _peer->isUser()
|
|
|
|
? tr::lng_context_view_profile(tr::now)
|
|
|
|
: tr::lng_context_view_channel(tr::now);
|
2019-06-19 15:09:03 +00:00
|
|
|
_addAction(text, [=] {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
controller->showPeerInfo(strong);
|
|
|
|
}
|
|
|
|
}, _peer->isUser() ? &st::menuIconProfile : &st::menuIconInfo);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 07:07:32 +00:00
|
|
|
void Filler::addStoryArchive() {
|
|
|
|
const auto channel = _peer ? _peer->asChannel() : nullptr;
|
|
|
|
if (!channel || !channel->canEditStories()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
|
|
|
const auto weak = base::make_weak(_thread);
|
|
|
|
_addAction(tr::lng_stories_archive_button(tr::now), [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
controller->showSection(Info::Stories::Make(
|
|
|
|
channel,
|
|
|
|
Info::Stories::Tab::Archive));
|
|
|
|
}
|
|
|
|
}, &st::menuIconStoriesArchiveSection);
|
|
|
|
}
|
|
|
|
|
2022-04-05 20:51:42 +00:00
|
|
|
void Filler::addToggleFolder() {
|
2022-05-09 13:09:46 +00:00
|
|
|
const auto controller = _controller;
|
2022-04-05 20:51:42 +00:00
|
|
|
const auto history = _request.key.history();
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_topic || !history || !history->owner().chatsFilters().has()) {
|
2022-04-05 20:51:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-10 10:49:14 +00:00
|
|
|
_addAction(PeerMenuCallback::Args{
|
|
|
|
.text = tr::lng_filters_menu_add(tr::now),
|
|
|
|
.handler = nullptr,
|
|
|
|
.icon = &st::menuIconAddToFolder,
|
2022-11-01 15:23:52 +00:00
|
|
|
.fillSubmenu = [&](not_null<Ui::PopupMenu*> menu) {
|
2022-05-09 13:09:46 +00:00
|
|
|
FillChooseFilterMenu(controller, menu, history);
|
2022-04-10 10:49:14 +00:00
|
|
|
},
|
|
|
|
});
|
2022-04-05 20:51:42 +00:00
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2018-06-26 18:03:45 +00:00
|
|
|
void Filler::addToggleUnreadMark() {
|
|
|
|
const auto peer = _peer;
|
2022-10-14 13:25:05 +00:00
|
|
|
const auto history = _request.key.history();
|
|
|
|
if (!_thread) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto unread = IsUnreadThread(_thread);
|
2022-10-21 13:12:46 +00:00
|
|
|
if ((_thread->asTopic() || peer->isForum()) && !unread) {
|
2022-10-14 13:25:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto weak = base::make_weak(_thread);
|
|
|
|
const auto label = unread
|
|
|
|
? tr::lng_context_mark_read(tr::now)
|
|
|
|
: tr::lng_context_mark_unread(tr::now);
|
|
|
|
_addAction(label, [=] {
|
|
|
|
const auto thread = weak.get();
|
|
|
|
if (!thread) {
|
|
|
|
return;
|
2018-06-26 18:03:45 +00:00
|
|
|
}
|
2022-10-14 13:25:05 +00:00
|
|
|
if (unread) {
|
|
|
|
MarkAsReadThread(thread);
|
|
|
|
} else if (history) {
|
|
|
|
peer->owner().histories().changeDialogUnreadMark(history, true);
|
|
|
|
}
|
|
|
|
}, (unread ? &st::menuIconMarkRead : &st::menuIconMarkUnread));
|
2018-06-26 18:03:45 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 15:32:25 +00:00
|
|
|
void Filler::addNewWindow() {
|
|
|
|
const auto history = _request.key.history();
|
|
|
|
if (!_peer
|
|
|
|
|| _topic
|
|
|
|
|| _peer->isForum()
|
|
|
|
|| (history
|
|
|
|
&& history->useTopPromotion()
|
|
|
|
&& !history->topPromotionType().isEmpty())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(tr::lng_context_new_window(tr::now), [=] {
|
|
|
|
Ui::PreventDelayedActivation();
|
|
|
|
controller->showInNewWindow(peer);
|
|
|
|
}, &st::menuIconNewWindow);
|
|
|
|
AddSeparatorAndShiftUp(_addAction);
|
|
|
|
}
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
void Filler::addToggleArchive() {
|
2022-10-14 13:25:05 +00:00
|
|
|
if (!_peer || _topic) {
|
2022-09-27 12:05:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-18 08:28:43 +00:00
|
|
|
const auto peer = _peer;
|
2022-10-14 13:25:05 +00:00
|
|
|
const auto history = _request.key.history();
|
2022-01-03 15:16:19 +00:00
|
|
|
if (history && history->useTopPromotion()) {
|
|
|
|
return;
|
|
|
|
} else if (peer->isNotificationsUser() || peer->isSelf()) {
|
|
|
|
if (!history || !history->folder()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:23:08 +00:00
|
|
|
const auto isArchived = [=] {
|
2020-06-12 12:12:34 +00:00
|
|
|
return (history->folder() != nullptr);
|
2020-04-29 15:23:08 +00:00
|
|
|
};
|
2020-09-30 11:59:54 +00:00
|
|
|
const auto label = [=] {
|
|
|
|
return isArchived()
|
|
|
|
? tr::lng_archived_remove(tr::now)
|
|
|
|
: tr::lng_archived_add(tr::now);
|
|
|
|
};
|
2019-04-18 08:28:43 +00:00
|
|
|
const auto toggle = [=] {
|
2020-06-12 12:12:34 +00:00
|
|
|
ToggleHistoryArchived(history, !isArchived());
|
2019-04-18 08:28:43 +00:00
|
|
|
};
|
2021-12-09 17:56:24 +00:00
|
|
|
const auto archiveAction = _addAction(
|
|
|
|
label(),
|
2021-12-10 12:10:14 +00:00
|
|
|
toggle,
|
2021-12-09 17:56:24 +00:00
|
|
|
isArchived() ? &st::menuIconUnarchive : &st::menuIconArchive);
|
2020-04-29 15:23:08 +00:00
|
|
|
|
2020-09-30 11:59:54 +00:00
|
|
|
auto actionText = history->session().changes().historyUpdates(
|
2020-06-12 12:12:34 +00:00
|
|
|
history,
|
|
|
|
Data::HistoryUpdate::Flag::Folder
|
2020-09-30 11:59:54 +00:00
|
|
|
) | rpl::map(label);
|
|
|
|
SetActionText(archiveAction, std::move(actionText));
|
2019-04-18 08:28:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addClearHistory() {
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_topic) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto channel = _peer->asChannel();
|
|
|
|
const auto isGroup = _peer->isChat() || _peer->isMegagroup();
|
|
|
|
if (channel) {
|
|
|
|
if (!channel->amIn()) {
|
|
|
|
return;
|
|
|
|
} else if (!channel->canDeleteMessages()
|
2022-10-25 08:16:56 +00:00
|
|
|
&& (!isGroup || channel->isPublic() || channel->isForum())) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_addAction(
|
|
|
|
tr::lng_profile_clear_history(tr::now),
|
2022-02-21 01:17:19 +00:00
|
|
|
ClearHistoryHandler(_controller, _peer),
|
2022-01-03 15:16:19 +00:00
|
|
|
&st::menuIconClear);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addDeleteChat() {
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_topic || _peer->isChannel()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-04 14:15:45 +00:00
|
|
|
_addAction({
|
|
|
|
.text = (_peer->isUser()
|
2022-01-03 15:16:19 +00:00
|
|
|
? tr::lng_profile_delete_conversation(tr::now)
|
|
|
|
: tr::lng_profile_clear_and_exit(tr::now)),
|
2022-04-04 14:15:45 +00:00
|
|
|
.handler = DeleteAndLeaveHandler(_controller, _peer),
|
|
|
|
.icon = &st::menuIconDeleteAttention,
|
|
|
|
.isAttention = true,
|
|
|
|
});
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addLeaveChat() {
|
|
|
|
const auto channel = _peer->asChannel();
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_topic || !channel || !channel->amIn()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-04 14:15:45 +00:00
|
|
|
_addAction({
|
|
|
|
.text = (_peer->isMegagroup()
|
2022-01-03 15:16:19 +00:00
|
|
|
? tr::lng_profile_leave_group(tr::now)
|
|
|
|
: tr::lng_profile_leave_channel(tr::now)),
|
2022-04-04 14:15:45 +00:00
|
|
|
.handler = DeleteAndLeaveHandler(_controller, _peer),
|
|
|
|
.icon = &st::menuIconLeaveAttention,
|
|
|
|
.isAttention = true,
|
|
|
|
});
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void Filler::addJoinChat() {
|
|
|
|
const auto channel = _peer->asChannel();
|
|
|
|
if (_topic || !channel || channel->amIn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto label = _peer->isMegagroup()
|
|
|
|
? tr::lng_profile_join_group(tr::now)
|
|
|
|
: tr::lng_profile_join_channel(tr::now);
|
|
|
|
_addAction(label, [=] {
|
|
|
|
channel->session().api().joinChannel(channel);
|
|
|
|
}, &st::menuIconAddToFolder);
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addBlockUser() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user
|
|
|
|
|| user->isInaccessible()
|
|
|
|
|| user->isSelf()
|
|
|
|
|| user->isRepliesChat()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-03 15:24:51 +00:00
|
|
|
const auto window = &_controller->window();
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto blockText = [](not_null<UserData*> user) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return user->isBlocked()
|
2019-03-12 10:36:33 +00:00
|
|
|
? ((user->isBot() && !user->isSupport())
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_profile_restart_bot(tr::now)
|
|
|
|
: tr::lng_profile_unblock_user(tr::now))
|
2019-03-12 10:36:33 +00:00
|
|
|
: ((user->isBot() && !user->isSupport())
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_profile_block_bot(tr::now)
|
|
|
|
: tr::lng_profile_block_user(tr::now));
|
2017-11-06 18:03:20 +00:00
|
|
|
};
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto blockAction = _addAction(blockText(user), [=] {
|
2018-12-04 11:46:07 +00:00
|
|
|
if (user->isBlocked()) {
|
2019-07-04 14:02:22 +00:00
|
|
|
PeerMenuUnblockUserWithBotRestart(user);
|
2019-06-12 13:26:04 +00:00
|
|
|
} else if (user->isBot()) {
|
2021-08-01 22:57:36 +00:00
|
|
|
user->session().api().blockedPeers().block(user);
|
2017-11-06 18:03:20 +00:00
|
|
|
} else {
|
2020-09-21 16:56:38 +00:00
|
|
|
window->show(Box(
|
|
|
|
PeerMenuBlockUserBox,
|
|
|
|
window,
|
|
|
|
user,
|
|
|
|
v::null,
|
|
|
|
v::null));
|
2021-12-10 12:10:14 +00:00
|
|
|
}
|
2021-12-09 17:56:24 +00:00
|
|
|
}, (!user->isBlocked()
|
|
|
|
? &st::menuIconBlock
|
|
|
|
: user->isBot()
|
|
|
|
? &st::menuIconRestartBot
|
|
|
|
: &st::menuIconUnblock));
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2020-09-30 11:59:54 +00:00
|
|
|
auto actionText = _peer->session().changes().peerUpdates(
|
2017-11-06 18:03:20 +00:00
|
|
|
_peer,
|
2020-06-12 12:12:34 +00:00
|
|
|
Data::PeerUpdate::Flag::IsBlocked
|
2020-09-30 11:59:54 +00:00
|
|
|
) | rpl::map([=] { return blockText(user); });
|
|
|
|
SetActionText(blockAction, std::move(actionText));
|
2017-11-06 18:03:20 +00:00
|
|
|
|
|
|
|
if (user->blockStatus() == UserData::BlockStatus::Unknown) {
|
2019-07-24 11:13:51 +00:00
|
|
|
user->session().api().requestFullPeer(user);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addViewDiscussion() {
|
|
|
|
const auto channel = _peer->asBroadcast();
|
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto chat = channel->linkedChat();
|
|
|
|
if (!chat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto navigation = _controller;
|
|
|
|
_addAction(tr::lng_profile_view_discussion(tr::now), [=] {
|
|
|
|
if (channel->invitePeekExpires()) {
|
2023-05-02 09:33:19 +00:00
|
|
|
navigation->showToast(tr::lng_channel_invite_private(tr::now));
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
2019-03-21 18:14:48 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
navigation->showPeerHistory(
|
|
|
|
chat,
|
|
|
|
Window::SectionShow::Way::Forward);
|
|
|
|
}, &st::menuIconDiscussion);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addExportChat() {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (_thread->asTopic() || !_peer->canExportChatHistory()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto peer = _peer;
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2022-01-03 15:16:19 +00:00
|
|
|
tr::lng_profile_export_chat(tr::now),
|
|
|
|
[=] { PeerMenuExportChat(peer); },
|
|
|
|
&st::menuIconExport);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-30 14:47:03 +00:00
|
|
|
void Filler::addTranslate() {
|
|
|
|
if (_peer->translationFlag() != PeerData::TranslationFlag::Disabled
|
|
|
|
|| !_peer->session().premium()
|
|
|
|
|| !Core::App().settings().translateChatEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
|
|
|
if (!history
|
|
|
|
|| !history->translateOfferedFrom()
|
|
|
|
|| history->translatedTo()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_addAction(tr::lng_context_translate(tr::now), [=] {
|
|
|
|
history->peer->saveTranslationDisabled(false);
|
|
|
|
}, &st::menuIconTranslate);
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addReport() {
|
|
|
|
const auto chat = _peer->asChat();
|
|
|
|
const auto channel = _peer->asChannel();
|
2022-12-05 05:03:31 +00:00
|
|
|
if (_topic
|
|
|
|
|| ((!chat || chat->amCreator())
|
|
|
|
&& (!channel || channel->amCreator()))) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto peer = _peer;
|
2021-06-24 13:25:10 +00:00
|
|
|
const auto navigation = _controller;
|
2022-01-03 15:16:19 +00:00
|
|
|
_addAction(tr::lng_profile_report(tr::now), [=] {
|
2022-04-17 10:30:08 +00:00
|
|
|
ShowReportPeerBox(navigation, peer);
|
2022-01-03 15:16:19 +00:00
|
|
|
}, &st::menuIconReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addNewContact() {
|
|
|
|
const auto user = _peer->asUser();
|
2022-04-15 10:59:44 +00:00
|
|
|
if (!user
|
|
|
|
|| user->isContact()
|
|
|
|
|| user->isSelf()
|
|
|
|
|| user->isInaccessible()
|
|
|
|
|| user->isBot()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto controller = _controller;
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2022-01-03 15:16:19 +00:00
|
|
|
tr::lng_info_add_as_contact(tr::now),
|
|
|
|
[=] { controller->show(Box(EditContactBox, controller, user)); },
|
|
|
|
&st::menuIconInvite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addShareContact() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user || !user->canShareThisContact()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2022-01-03 15:16:19 +00:00
|
|
|
tr::lng_info_share_contact(tr::now),
|
|
|
|
[=] { PeerMenuShareContactBox(controller, user); },
|
|
|
|
&st::menuIconShare);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addEditContact() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user || !user->isContact() || user->isSelf()) {
|
|
|
|
return;
|
2021-06-24 13:25:10 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(
|
|
|
|
tr::lng_info_edit_contact(tr::now),
|
|
|
|
[=] { controller->show(Box(EditContactBox, controller, user)); },
|
|
|
|
&st::menuIconEdit);
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addBotToGroup() {
|
|
|
|
const auto user = _peer->asUser();
|
2022-03-23 10:15:52 +00:00
|
|
|
if (!user) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2022-03-23 10:15:52 +00:00
|
|
|
[[maybe_unused]] const auto lifetime = Info::Profile::InviteToChatButton(
|
|
|
|
user
|
|
|
|
) | rpl::take(1) | rpl::start_with_next([=](QString label) {
|
|
|
|
if (!label.isEmpty()) {
|
2022-06-09 05:19:11 +00:00
|
|
|
const auto controller = _controller;
|
2022-03-23 10:15:52 +00:00
|
|
|
_addAction(
|
|
|
|
label,
|
2022-06-09 05:19:11 +00:00
|
|
|
[=] { AddBotToGroupBoxController::Start(controller, user); },
|
2022-03-23 10:15:52 +00:00
|
|
|
&st::menuIconInvite);
|
|
|
|
}
|
|
|
|
});
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addNewMembers() {
|
|
|
|
const auto chat = _peer->asChat();
|
|
|
|
const auto channel = _peer->asChannel();
|
|
|
|
if ((!chat || !chat->canAddMembers())
|
|
|
|
&& (!channel || !channel->canAddMembers())) {
|
|
|
|
return;
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto navigation = _controller;
|
|
|
|
const auto callback = chat
|
|
|
|
? Fn<void()>([=] { AddChatMembers(navigation, chat); })
|
|
|
|
: [=] { PeerMenuAddChannelMembers(navigation, channel); };
|
|
|
|
_addAction(
|
|
|
|
((chat || channel->isMegagroup())
|
|
|
|
? tr::lng_channel_add_members(tr::now)
|
|
|
|
: tr::lng_channel_add_users(tr::now)),
|
|
|
|
callback,
|
|
|
|
&st::menuIconInvite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addDeleteContact() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user || !user->isContact() || user->isSelf()) {
|
|
|
|
return;
|
2017-11-07 11:53:05 +00:00
|
|
|
}
|
2022-03-06 10:44:00 +00:00
|
|
|
const auto controller = _controller;
|
2022-04-04 14:15:45 +00:00
|
|
|
_addAction({
|
|
|
|
.text = tr::lng_info_delete_contact(tr::now),
|
|
|
|
.handler = [=] { PeerMenuDeleteContact(controller, user); },
|
|
|
|
.icon = &st::menuIconDeleteAttention,
|
|
|
|
.isAttention = true,
|
|
|
|
});
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 15:39:41 +00:00
|
|
|
void Filler::addDeleteTopic() {
|
2022-10-19 10:59:37 +00:00
|
|
|
if (!_topic || !_topic->canDelete()) {
|
2022-10-18 15:39:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-19 10:59:37 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
const auto weak = base::make_weak(_topic);
|
|
|
|
const auto callback = [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
PeerMenuDeleteTopicWithConfirmation(controller, strong);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
_addAction({
|
|
|
|
.text = tr::lng_forum_topic_delete(tr::now),
|
|
|
|
.handler = callback,
|
|
|
|
.icon = &st::menuIconDeleteAttention,
|
|
|
|
.isAttention = true,
|
|
|
|
});
|
2022-10-18 15:39:41 +00:00
|
|
|
}
|
|
|
|
|
2022-12-06 19:11:11 +00:00
|
|
|
void Filler::addTopicLink() {
|
|
|
|
if (!_topic || _topic->creating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto channel = _topic->channel();
|
|
|
|
const auto id = _topic->rootId();
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(tr::lng_context_copy_topic_link(tr::now), [=] {
|
|
|
|
const auto base = channel->hasUsername()
|
|
|
|
? channel->username()
|
|
|
|
: "c/" + QString::number(peerToChannel(channel->id).bare);
|
|
|
|
const auto query = base + '/' + QString::number(id.bare);
|
|
|
|
const auto link = channel->session().createInternalLinkFull(query);
|
|
|
|
QGuiApplication::clipboard()->setText(link);
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->showToast(channel->hasUsername()
|
|
|
|
? tr::lng_channel_public_link_copied(tr::now)
|
|
|
|
: tr::lng_context_about_private_link(tr::now));
|
2022-12-06 19:11:11 +00:00
|
|
|
}, &st::menuIconCopy);
|
|
|
|
}
|
|
|
|
|
2022-09-27 12:05:47 +00:00
|
|
|
void Filler::addManageTopic() {
|
2022-10-18 15:39:41 +00:00
|
|
|
if (!_topic || !_topic->canEdit()) {
|
2022-09-27 12:05:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-18 15:39:41 +00:00
|
|
|
const auto history = _topic->history();
|
|
|
|
const auto rootId = _topic->rootId();
|
2022-09-27 12:05:47 +00:00
|
|
|
const auto navigation = _controller;
|
2022-10-14 13:25:05 +00:00
|
|
|
_addAction(tr::lng_forum_topic_edit(tr::now), [=] {
|
2022-10-13 17:34:04 +00:00
|
|
|
navigation->show(
|
|
|
|
Box(EditForumTopicBox, navigation, history, rootId));
|
2022-09-27 12:05:47 +00:00
|
|
|
}, &st::menuIconEdit);
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addManageChat() {
|
|
|
|
if (!EditPeerInfoBox::Available(_peer)) {
|
2020-08-03 09:02:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
const auto peer = _peer;
|
|
|
|
const auto navigation = _controller;
|
2023-04-09 17:36:39 +00:00
|
|
|
const auto text = peer->isUser()
|
|
|
|
? tr::lng_manage_bot_title(tr::now)
|
|
|
|
: (peer->isChat() || peer->isMegagroup())
|
2022-01-03 15:16:19 +00:00
|
|
|
? tr::lng_manage_group_title(tr::now)
|
|
|
|
: tr::lng_manage_channel_title(tr::now);
|
|
|
|
_addAction(text, [=] {
|
|
|
|
navigation->showEditPeerBox(peer);
|
|
|
|
}, &st::menuIconManage);
|
|
|
|
}
|
|
|
|
|
2023-04-26 18:49:51 +00:00
|
|
|
void Filler::addViewStatistics() {
|
|
|
|
if (const auto channel = _peer->asChannel()) {
|
|
|
|
if (channel->flags() & ChannelDataFlag::CanGetStatistics) {
|
2023-10-02 15:36:25 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
const auto weak = base::make_weak(_thread);
|
2023-04-26 19:06:54 +00:00
|
|
|
const auto peer = _peer;
|
2023-04-26 18:49:51 +00:00
|
|
|
_addAction(tr::lng_stats_title(tr::now), [=] {
|
2023-10-02 15:36:25 +00:00
|
|
|
if (const auto strong = weak.get()) {
|
2023-10-08 20:17:45 +00:00
|
|
|
controller->showSection(Info::Statistics::Make(peer, {}));
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
2023-10-06 12:46:31 +00:00
|
|
|
}, &st::menuIconStats);
|
2023-10-21 20:55:17 +00:00
|
|
|
if (!channel->isMegagroup()) {
|
|
|
|
_addAction(tr::lng_boosts_title(tr::now), [=] {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
controller->showSection(Info::Boosts::Make(peer));
|
|
|
|
}
|
|
|
|
}, &st::menuIconBoosts);
|
|
|
|
}
|
2023-04-26 18:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addCreatePoll() {
|
2023-01-10 18:56:20 +00:00
|
|
|
const auto can = _topic
|
2023-02-07 12:28:59 +00:00
|
|
|
? Data::CanSend(_topic, ChatRestriction::SendPolls)
|
|
|
|
: _peer->canCreatePolls();
|
2023-01-10 18:56:20 +00:00
|
|
|
if (!can) {
|
2022-01-03 15:16:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto peer = _peer;
|
2020-08-03 09:02:41 +00:00
|
|
|
const auto controller = _controller;
|
2020-11-12 15:46:17 +00:00
|
|
|
const auto source = (_request.section == Section::Scheduled)
|
2020-08-03 09:02:41 +00:00
|
|
|
? Api::SendType::Scheduled
|
|
|
|
: Api::SendType::Normal;
|
2020-11-20 17:04:50 +00:00
|
|
|
const auto sendMenuType = (_request.section == Section::Scheduled)
|
|
|
|
? SendMenu::Type::Disabled
|
|
|
|
: (_request.section == Section::Replies)
|
|
|
|
? SendMenu::Type::SilentOnly
|
|
|
|
: SendMenu::Type::Scheduled;
|
2020-08-03 09:02:41 +00:00
|
|
|
const auto flag = PollData::Flags();
|
2023-10-10 06:49:22 +00:00
|
|
|
const auto replyTo = _request.currentReplyTo;
|
2020-08-03 09:02:41 +00:00
|
|
|
auto callback = [=] {
|
2020-11-11 20:47:40 +00:00
|
|
|
PeerMenuCreatePoll(
|
|
|
|
controller,
|
|
|
|
peer,
|
2023-10-10 06:49:22 +00:00
|
|
|
replyTo,
|
2020-11-11 20:47:40 +00:00
|
|
|
flag,
|
|
|
|
flag,
|
2020-11-20 17:04:50 +00:00
|
|
|
source,
|
|
|
|
sendMenuType);
|
2020-08-03 09:02:41 +00:00
|
|
|
};
|
2021-12-09 17:56:24 +00:00
|
|
|
_addAction(
|
|
|
|
tr::lng_polls_create(tr::now),
|
|
|
|
std::move(callback),
|
|
|
|
&st::menuIconCreatePoll);
|
2020-08-03 09:02:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::addThemeEdit() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user || user->isBot()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(
|
2023-04-19 09:33:07 +00:00
|
|
|
tr::lng_chat_theme_wallpaper(tr::now),
|
2022-01-03 15:16:19 +00:00
|
|
|
[=] { controller->toggleChooseChatTheme(user); },
|
|
|
|
&st::menuIconChangeColors);
|
|
|
|
}
|
|
|
|
|
2022-03-28 23:53:25 +00:00
|
|
|
void Filler::addTTLSubmenu(bool addSeparator) {
|
2022-10-13 17:34:04 +00:00
|
|
|
if (_thread->asTopic()) {
|
2022-09-27 12:05:47 +00:00
|
|
|
return; // #TODO later forum
|
|
|
|
}
|
2022-03-28 23:53:25 +00:00
|
|
|
const auto validator = TTLMenu::TTLValidator(
|
2023-05-02 09:33:19 +00:00
|
|
|
_controller->uiShow(),
|
2022-03-28 23:53:25 +00:00
|
|
|
_peer);
|
|
|
|
if (!validator.can()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-03-31 21:32:03 +00:00
|
|
|
const auto text = tr::lng_manage_messages_ttl_menu(tr::now)
|
|
|
|
+ (_peer->messagesTTL()
|
|
|
|
? ('\t' + Ui::FormatTTLTiny(_peer->messagesTTL()))
|
|
|
|
: QString());
|
|
|
|
_addAction(text, [=] { validator.showBox(); }, validator.icon());
|
2022-03-28 23:53:25 +00:00
|
|
|
if (addSeparator) {
|
|
|
|
_addAction(PeerMenuCallback::Args{ .isSeparator = true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-03 14:56:12 +00:00
|
|
|
void Filler::addGiftPremium() {
|
|
|
|
const auto user = _peer->asUser();
|
|
|
|
if (!user
|
|
|
|
|| user->isInaccessible()
|
|
|
|
|| user->isSelf()
|
|
|
|
|| user->isBot()
|
|
|
|
|| user->isNotificationsUser()
|
|
|
|
|| !user->canReceiveGifts()
|
|
|
|
|| user->isRepliesChat()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto navigation = _controller;
|
|
|
|
_addAction(tr::lng_profile_gift_premium(tr::now), [=] {
|
|
|
|
navigation->showGiftPremiumBox(user);
|
|
|
|
}, &st::menuIconGiftPremium);
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::fill() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_folder) {
|
2022-01-03 15:16:19 +00:00
|
|
|
fillArchiveActions();
|
2020-11-12 15:46:17 +00:00
|
|
|
return;
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
switch (_request.section) {
|
|
|
|
case Section::ChatsList: fillChatsListActions(); break;
|
|
|
|
case Section::History: fillHistoryActions(); break;
|
|
|
|
case Section::Profile: fillProfileActions(); break;
|
|
|
|
case Section::Replies: fillRepliesActions(); break;
|
|
|
|
case Section::Scheduled: fillScheduledActions(); break;
|
2022-10-14 13:25:05 +00:00
|
|
|
case Section::ContextMenu: fillContextMenuActions(); break;
|
2022-01-03 15:16:19 +00:00
|
|
|
default: Unexpected("_request.section in Filler::fill.");
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void Filler::addCreateTopic() {
|
|
|
|
if (!_peer || !_peer->canCreateTopics()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(tr::lng_forum_create_topic(tr::now), [=] {
|
|
|
|
if (const auto forum = peer->forum()) {
|
|
|
|
controller->show(Box(
|
|
|
|
NewForumTopicBox,
|
|
|
|
controller,
|
|
|
|
forum->history()));
|
|
|
|
}
|
|
|
|
}, &st::menuIconDiscussion);
|
2022-11-01 14:22:15 +00:00
|
|
|
_addAction(PeerMenuCallback::Args{ .isSeparator = true });
|
2022-10-14 13:25:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 12:37:51 +00:00
|
|
|
void Filler::addViewAsMessages() {
|
|
|
|
if (!_peer || !_peer->isForum()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto peer = _peer;
|
|
|
|
const auto controller = _controller;
|
|
|
|
_addAction(tr::lng_forum_view_as_messages(tr::now), [=] {
|
|
|
|
controller->showPeerHistory(peer->id);
|
|
|
|
}, &st::menuIconViewReplies);
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void Filler::addSearchTopics() {
|
2022-10-26 09:30:10 +00:00
|
|
|
const auto forum = _peer ? _peer->forum() : nullptr;
|
|
|
|
if (!forum) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto history = forum->history();
|
|
|
|
const auto controller = _controller;
|
2022-10-14 13:25:05 +00:00
|
|
|
_addAction(tr::lng_dlg_filter(tr::now), [=] {
|
2022-10-26 09:30:10 +00:00
|
|
|
controller->content()->searchInChat(history);
|
2022-10-14 13:25:05 +00:00
|
|
|
}, &st::menuIconSearch);
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::fillChatsListActions() {
|
2022-10-14 13:25:05 +00:00
|
|
|
if (!_peer || !_peer->isForum()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-01 14:22:15 +00:00
|
|
|
addCreateTopic();
|
2022-10-14 13:25:05 +00:00
|
|
|
addInfo();
|
2022-11-01 14:22:15 +00:00
|
|
|
addViewAsMessages();
|
2022-10-14 13:25:05 +00:00
|
|
|
const auto &all = _peer->forum()->topicsList()->indexed()->all();
|
|
|
|
if (all.size() > kTopicsSearchMinCount) {
|
|
|
|
addSearchTopics();
|
|
|
|
}
|
2022-11-01 15:23:52 +00:00
|
|
|
addManageChat();
|
|
|
|
addNewMembers();
|
|
|
|
addVideoChat();
|
2022-11-01 14:22:15 +00:00
|
|
|
_addAction(PeerMenuCallback::Args{ .isSeparator = true });
|
2022-12-05 05:03:31 +00:00
|
|
|
addReport();
|
2022-10-14 13:25:05 +00:00
|
|
|
if (_peer->asChannel()->amIn()) {
|
|
|
|
addLeaveChat();
|
|
|
|
} else {
|
|
|
|
addJoinChat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-01 15:23:52 +00:00
|
|
|
void Filler::addVideoChat() {
|
|
|
|
auto test = Ui::PopupMenu(nullptr);
|
|
|
|
FillVideoChatMenu(
|
|
|
|
_controller,
|
|
|
|
_request,
|
|
|
|
Ui::Menu::CreateAddActionCallback(&test));
|
|
|
|
if (test.actions().size() < 2) {
|
|
|
|
FillVideoChatMenu(_controller, _request, _addAction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_addAction(PeerMenuCallback::Args{
|
|
|
|
.text = tr::lng_menu_start_group_call_options(tr::now),
|
|
|
|
.handler = nullptr,
|
|
|
|
.icon = &st::menuIconVideoChat,
|
|
|
|
.fillSubmenu = [&](not_null<Ui::PopupMenu*> menu) {
|
|
|
|
FillVideoChatMenu(
|
|
|
|
_controller,
|
|
|
|
_request,
|
|
|
|
Ui::Menu::CreateAddActionCallback(menu));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-14 13:25:05 +00:00
|
|
|
void Filler::fillContextMenuActions() {
|
2023-02-03 15:32:25 +00:00
|
|
|
addNewWindow();
|
2022-01-03 15:16:19 +00:00
|
|
|
addHidePromotion();
|
|
|
|
addToggleArchive();
|
|
|
|
addTogglePin();
|
2022-02-01 15:19:47 +00:00
|
|
|
if (ViewProfileInChatsListContextMenu.value()) {
|
|
|
|
addInfo();
|
|
|
|
}
|
2022-03-28 18:11:37 +00:00
|
|
|
addToggleMuteSubmenu(false);
|
2022-01-03 15:16:19 +00:00
|
|
|
addToggleUnreadMark();
|
2022-10-18 15:39:41 +00:00
|
|
|
addToggleTopicClosed();
|
2022-04-05 20:51:42 +00:00
|
|
|
addToggleFolder();
|
2018-02-13 16:11:00 +00:00
|
|
|
if (const auto user = _peer->asUser()) {
|
2022-01-03 15:16:19 +00:00
|
|
|
if (!user->isContact()) {
|
|
|
|
addBlockUser();
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
addClearHistory();
|
|
|
|
addDeleteChat();
|
|
|
|
addLeaveChat();
|
2022-10-18 15:39:41 +00:00
|
|
|
addDeleteTopic();
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::fillHistoryActions() {
|
2022-03-28 18:11:37 +00:00
|
|
|
addToggleMuteSubmenu(true);
|
2022-01-03 15:16:19 +00:00
|
|
|
addInfo();
|
2023-09-05 07:07:32 +00:00
|
|
|
addStoryArchive();
|
2022-01-03 15:16:19 +00:00
|
|
|
addSupportInfo();
|
|
|
|
addManageChat();
|
|
|
|
addCreatePoll();
|
|
|
|
addThemeEdit();
|
|
|
|
addViewDiscussion();
|
|
|
|
addExportChat();
|
2023-01-30 14:47:03 +00:00
|
|
|
addTranslate();
|
2022-01-03 15:16:19 +00:00
|
|
|
addReport();
|
|
|
|
addClearHistory();
|
|
|
|
addDeleteChat();
|
|
|
|
addLeaveChat();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::fillProfileActions() {
|
2022-03-28 23:53:25 +00:00
|
|
|
addTTLSubmenu(true);
|
2022-03-31 21:32:03 +00:00
|
|
|
addSupportInfo();
|
2022-01-03 15:16:19 +00:00
|
|
|
addNewContact();
|
|
|
|
addShareContact();
|
|
|
|
addEditContact();
|
2022-07-03 14:56:12 +00:00
|
|
|
addGiftPremium();
|
2022-01-03 15:16:19 +00:00
|
|
|
addBotToGroup();
|
|
|
|
addNewMembers();
|
2023-04-26 18:49:51 +00:00
|
|
|
addViewStatistics();
|
2023-09-05 14:17:19 +00:00
|
|
|
addStoryArchive();
|
2022-01-03 15:16:19 +00:00
|
|
|
addManageChat();
|
2022-12-06 19:11:11 +00:00
|
|
|
addTopicLink();
|
|
|
|
addManageTopic();
|
2022-10-18 15:39:41 +00:00
|
|
|
addToggleTopicClosed();
|
2022-01-03 15:16:19 +00:00
|
|
|
addViewDiscussion();
|
|
|
|
addExportChat();
|
|
|
|
addBlockUser();
|
|
|
|
addReport();
|
|
|
|
addLeaveChat();
|
|
|
|
addDeleteContact();
|
2022-10-18 15:39:41 +00:00
|
|
|
addDeleteTopic();
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::fillRepliesActions() {
|
2022-10-18 15:39:41 +00:00
|
|
|
if (_topic) {
|
2022-09-27 12:05:47 +00:00
|
|
|
addInfo();
|
|
|
|
addManageTopic();
|
|
|
|
}
|
2022-01-03 15:16:19 +00:00
|
|
|
addCreatePoll();
|
2022-10-18 15:39:41 +00:00
|
|
|
addToggleTopicClosed();
|
2022-10-19 10:59:37 +00:00
|
|
|
addDeleteTopic();
|
2022-01-03 15:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::fillScheduledActions() {
|
|
|
|
addCreatePoll();
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:16:19 +00:00
|
|
|
void Filler::fillArchiveActions() {
|
2020-11-12 15:46:17 +00:00
|
|
|
Expects(_folder != nullptr);
|
2019-05-03 10:55:44 +00:00
|
|
|
|
|
|
|
if (_folder->id() != Data::Folder::kId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto controller = _controller;
|
|
|
|
const auto hidden = controller->session().settings().archiveCollapsed();
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = hidden
|
|
|
|
? tr::lng_context_archive_expand(tr::now)
|
|
|
|
: tr::lng_context_archive_collapse(tr::now);
|
2019-05-03 10:55:44 +00:00
|
|
|
_addAction(text, [=] {
|
|
|
|
controller->session().settings().setArchiveCollapsed(!hidden);
|
|
|
|
controller->session().saveSettingsDelayed();
|
2021-12-09 17:56:24 +00:00
|
|
|
}, hidden ? &st::menuIconExpand : &st::menuIconCollapse);
|
2019-05-16 08:39:45 +00:00
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
_addAction(tr::lng_context_archive_to_menu(tr::now), [=] {
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->showToast({
|
|
|
|
.text = { tr::lng_context_archive_to_menu_info(tr::now) },
|
|
|
|
.st = &st::windowArchiveToast,
|
|
|
|
.duration = kArchivedToastDuration,
|
|
|
|
});
|
2019-05-16 08:39:45 +00:00
|
|
|
|
|
|
|
controller->session().settings().setArchiveInMainMenu(
|
|
|
|
!controller->session().settings().archiveInMainMenu());
|
|
|
|
controller->session().saveSettingsDelayed();
|
2021-12-09 17:56:24 +00:00
|
|
|
}, &st::menuIconToMainMenu);
|
2020-09-16 14:09:04 +00:00
|
|
|
|
|
|
|
MenuAddMarkAsReadChatListAction(
|
2022-02-21 01:17:19 +00:00
|
|
|
controller,
|
2020-09-16 14:09:04 +00:00
|
|
|
[folder = _folder] { return folder->chatsList(); },
|
|
|
|
_addAction);
|
2023-08-11 14:20:38 +00:00
|
|
|
|
|
|
|
_addAction({ .isSeparator = true });
|
|
|
|
Settings::PreloadArchiveSettings(&controller->session());
|
|
|
|
_addAction(tr::lng_context_archive_settings(tr::now), [=] {
|
|
|
|
controller->show(Box(Settings::ArchiveSettingsBox, controller));
|
|
|
|
}, &st::menuIconManage);
|
2018-02-18 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
void PeerMenuExportChat(not_null<PeerData*> peer) {
|
2020-06-25 07:14:05 +00:00
|
|
|
Core::App().exportManager().start(peer);
|
2018-07-23 13:11:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 01:17:19 +00:00
|
|
|
void PeerMenuDeleteContact(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<UserData*> user) {
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto text = tr::lng_sure_delete_contact(
|
|
|
|
tr::now,
|
2017-11-07 13:13:41 +00:00
|
|
|
lt_contact,
|
2022-08-09 11:12:19 +00:00
|
|
|
user->name());
|
2022-02-21 01:17:19 +00:00
|
|
|
const auto deleteSure = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
2019-06-06 15:42:15 +00:00
|
|
|
user->session().api().request(MTPcontacts_DeleteContacts(
|
|
|
|
MTP_vector<MTPInputUser>(1, user->inputUser)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
user->session().api().applyUpdates(result);
|
2019-03-21 12:07:32 +00:00
|
|
|
}).send();
|
2017-11-07 13:13:41 +00:00
|
|
|
};
|
2022-02-21 01:17:19 +00:00
|
|
|
controller->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = text,
|
|
|
|
.confirmed = deleteSure,
|
|
|
|
.confirmText = tr::lng_box_delete(),
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
2022-10-19 10:59:37 +00:00
|
|
|
|
|
|
|
void PeerMenuDeleteTopicWithConfirmation(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<Data::ForumTopic*> topic) {
|
|
|
|
const auto weak = base::make_weak(topic);
|
|
|
|
const auto callback = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
PeerMenuDeleteTopic(navigation, strong);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
navigation->parentController()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_forum_topic_delete_sure(tr::now),
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_box_delete(),
|
|
|
|
.confirmStyle = &st::attentionBoxButton,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerMenuDeleteTopic(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
MsgId rootId) {
|
|
|
|
const auto api = &channel->session().api();
|
|
|
|
api->request(MTPchannels_DeleteTopicHistory(
|
|
|
|
channel->inputChannel,
|
|
|
|
MTP_int(rootId)
|
|
|
|
)).done([=](const MTPmessages_AffectedHistory &result) {
|
|
|
|
const auto offset = api->applyAffectedHistory(channel, result);
|
|
|
|
if (offset > 0) {
|
|
|
|
PeerMenuDeleteTopic(navigation, channel, rootId);
|
|
|
|
} else if (const auto forum = channel->forum()) {
|
|
|
|
forum->applyTopicDeleted(rootId);
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerMenuDeleteTopic(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<Data::ForumTopic*> topic) {
|
|
|
|
PeerMenuDeleteTopic(navigation, topic->channel(), topic->rootId());
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
void PeerMenuShareContactBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<UserData*> user) {
|
2022-02-21 01:17:19 +00:00
|
|
|
// There is no async to make weak from controller.
|
|
|
|
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
2022-11-01 04:46:31 +00:00
|
|
|
auto callback = [=](not_null<Data::Thread*> thread) {
|
2022-11-01 11:17:13 +00:00
|
|
|
const auto peer = thread->peer();
|
2023-01-10 18:56:20 +00:00
|
|
|
if (!Data::CanSend(thread, ChatRestriction::SendOther)) {
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
2023-05-02 09:33:19 +00:00
|
|
|
Ui::MakeInformBox(tr::lng_forward_share_cant()));
|
2017-11-07 13:13:41 +00:00
|
|
|
return;
|
2017-12-07 08:56:10 +00:00
|
|
|
} else if (peer->isSelf()) {
|
2022-11-01 04:46:31 +00:00
|
|
|
auto action = Api::SendAction(thread);
|
2019-08-30 10:17:18 +00:00
|
|
|
action.clearDraft = false;
|
2019-08-12 12:11:34 +00:00
|
|
|
user->session().api().shareContact(user, action);
|
2023-05-02 09:33:19 +00:00
|
|
|
navigation->showToast(tr::lng_share_done(tr::now));
|
2017-12-07 13:02:24 +00:00
|
|
|
if (auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
2017-12-07 08:56:10 +00:00
|
|
|
return;
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2022-11-01 04:46:31 +00:00
|
|
|
const auto title = thread->asTopic()
|
|
|
|
? thread->asTopic()->title()
|
|
|
|
: peer->name();
|
2017-11-07 13:13:41 +00:00
|
|
|
auto recipient = peer->isUser()
|
2022-11-01 04:46:31 +00:00
|
|
|
? title
|
|
|
|
: ('\xAB' + title + '\xBB');
|
|
|
|
const auto weak = base::make_weak(thread);
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_forward_share_contact(
|
|
|
|
tr::now,
|
|
|
|
lt_recipient,
|
|
|
|
recipient),
|
2022-11-01 04:46:31 +00:00
|
|
|
.confirmed = [weak, user, navigation](Fn<void()> &&close) {
|
|
|
|
if (const auto strong = weak.get()) {
|
|
|
|
navigation->showThread(
|
|
|
|
strong,
|
|
|
|
ShowAtTheEndMsgId,
|
|
|
|
Window::SectionShow::Way::ClearStack);
|
|
|
|
auto action = Api::SendAction(strong);
|
|
|
|
action.clearDraft = false;
|
|
|
|
strong->session().api().shareContact(user, action);
|
|
|
|
}
|
2022-02-21 01:17:19 +00:00
|
|
|
close();
|
2022-02-27 08:23:20 +00:00
|
|
|
},
|
|
|
|
.confirmText = tr::lng_forward_send(),
|
2023-05-02 09:33:19 +00:00
|
|
|
}));
|
2017-11-07 13:13:41 +00:00
|
|
|
};
|
2022-02-21 01:17:19 +00:00
|
|
|
*weak = navigation->parentController()->show(
|
|
|
|
Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseRecipientBoxController>(
|
|
|
|
&navigation->session(),
|
|
|
|
std::move(callback)),
|
|
|
|
[](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(tr::lng_cancel(), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
2023-05-02 09:33:19 +00:00
|
|
|
}));
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 13:30:29 +00:00
|
|
|
void PeerMenuCreatePoll(
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-01-15 13:30:29 +00:00
|
|
|
not_null<PeerData*> peer,
|
2023-10-10 06:49:22 +00:00
|
|
|
FullReplyTo replyTo,
|
2020-01-15 13:30:29 +00:00
|
|
|
PollData::Flags chosen,
|
2020-08-03 09:02:41 +00:00
|
|
|
PollData::Flags disabled,
|
2020-11-20 17:04:50 +00:00
|
|
|
Api::SendType sendType,
|
|
|
|
SendMenu::Type sendMenuType) {
|
2020-01-15 13:30:29 +00:00
|
|
|
if (peer->isChannel() && !peer->isMegagroup()) {
|
|
|
|
chosen &= ~PollData::Flag::PublicVotes;
|
|
|
|
disabled |= PollData::Flag::PublicVotes;
|
|
|
|
}
|
2022-02-21 01:17:19 +00:00
|
|
|
auto box = Box<CreatePollBox>(
|
2020-06-10 18:08:17 +00:00
|
|
|
controller,
|
2020-01-15 13:30:29 +00:00
|
|
|
chosen,
|
|
|
|
disabled,
|
2020-11-20 17:04:50 +00:00
|
|
|
sendType,
|
2022-02-21 01:17:19 +00:00
|
|
|
sendMenuType);
|
|
|
|
const auto weak = Ui::MakeWeak(box.data());
|
2018-12-23 16:47:00 +00:00
|
|
|
const auto lock = box->lifetime().make_state<bool>(false);
|
2018-12-20 16:02:44 +00:00
|
|
|
box->submitRequests(
|
2019-08-20 13:21:10 +00:00
|
|
|
) | rpl::start_with_next([=](const CreatePollBox::Result &result) {
|
2018-12-23 16:47:00 +00:00
|
|
|
if (std::exchange(*lock, true)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-09 15:24:13 +00:00
|
|
|
auto action = Api::SendAction(
|
|
|
|
peer->owner().history(peer),
|
|
|
|
result.options);
|
2023-10-10 06:49:22 +00:00
|
|
|
action.replyTo = replyTo;
|
|
|
|
const auto topicRootId = replyTo.topicRootId;
|
2022-10-17 16:29:48 +00:00
|
|
|
if (const auto local = action.history->localDraft(topicRootId)) {
|
|
|
|
action.clearDraft = local->textWithTags.text.isEmpty();
|
2023-10-10 06:49:22 +00:00
|
|
|
} else {
|
|
|
|
action.clearDraft = false;
|
2019-02-17 11:43:46 +00:00
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto api = &peer->session().api();
|
2022-02-21 01:17:19 +00:00
|
|
|
api->polls().create(result.poll, action, crl::guard(weak, [=] {
|
|
|
|
weak->closeBox();
|
2022-08-10 13:41:48 +00:00
|
|
|
}), crl::guard(weak, [=] {
|
2018-12-23 16:47:00 +00:00
|
|
|
*lock = false;
|
2022-02-21 01:17:19 +00:00
|
|
|
weak->submitFailed(tr::lng_attach_failed(tr::now));
|
2018-12-20 16:02:44 +00:00
|
|
|
}));
|
|
|
|
}, box->lifetime());
|
2022-02-21 01:17:19 +00:00
|
|
|
controller->show(std::move(box), Ui::LayerOption::CloseOther);
|
2018-12-20 16:02:44 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
void PeerMenuBlockUserBox(
|
2019-09-18 11:19:05 +00:00
|
|
|
not_null<Ui::GenericBox*> box,
|
2019-06-12 14:13:49 +00:00
|
|
|
not_null<Window::Controller*> window,
|
2020-09-17 13:26:53 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
std::variant<v::null_t, bool> suggestReport,
|
2020-09-25 12:31:36 +00:00
|
|
|
std::variant<v::null_t, ClearChat, ClearReply> suggestClear) {
|
2021-07-08 14:30:27 +00:00
|
|
|
const auto settings = peer->settings().value_or(PeerSettings(0));
|
2020-09-17 13:26:53 +00:00
|
|
|
const auto reportNeeded = v::is_null(suggestReport)
|
2021-07-08 14:30:27 +00:00
|
|
|
? ((settings & PeerSetting::ReportSpam) != 0)
|
2020-09-17 13:26:53 +00:00
|
|
|
: v::get<bool>(suggestReport);
|
|
|
|
|
|
|
|
const auto user = peer->asUser();
|
2022-08-09 11:12:19 +00:00
|
|
|
const auto name = user ? user->shortName() : peer->name();
|
2020-09-17 13:26:53 +00:00
|
|
|
if (user) {
|
|
|
|
box->addRow(object_ptr<Ui::FlatLabel>(
|
|
|
|
box,
|
|
|
|
tr::lng_blocked_list_confirm_text(
|
|
|
|
lt_name,
|
|
|
|
rpl::single(Ui::Text::Bold(name)),
|
|
|
|
Ui::Text::WithEntities),
|
|
|
|
st::blockUserConfirmation));
|
2019-06-12 13:26:04 +00:00
|
|
|
|
2020-09-17 13:26:53 +00:00
|
|
|
box->addSkip(st::boxMediumSkip);
|
|
|
|
}
|
|
|
|
const auto report = reportNeeded
|
2019-06-12 13:26:04 +00:00
|
|
|
? box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_report_spam(tr::now),
|
2019-06-12 13:26:04 +00:00
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox))
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
if (report) {
|
|
|
|
box->addSkip(st::boxMediumSkip);
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:26:53 +00:00
|
|
|
const auto clear = v::is<ClearChat>(suggestClear)
|
2019-07-15 13:47:40 +00:00
|
|
|
? box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
|
|
|
tr::lng_blocked_list_confirm_clear(tr::now),
|
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox))
|
2020-09-25 12:31:36 +00:00
|
|
|
: v::is<ClearReply>(suggestClear)
|
2020-09-17 13:26:53 +00:00
|
|
|
? box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
|
|
|
tr::lng_context_delete_msg(tr::now),
|
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox))
|
2019-07-15 13:47:40 +00:00
|
|
|
: nullptr;
|
2020-09-25 12:31:36 +00:00
|
|
|
if (clear) {
|
|
|
|
box->addSkip(st::boxMediumSkip);
|
|
|
|
}
|
|
|
|
const auto allFromUser = v::is<ClearReply>(suggestClear)
|
|
|
|
? box->addRow(object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
2022-02-28 16:45:19 +00:00
|
|
|
tr::lng_delete_all_from_user(
|
|
|
|
tr::now,
|
|
|
|
lt_user,
|
2022-08-09 11:12:19 +00:00
|
|
|
Ui::Text::Bold(peer->name()),
|
2022-02-28 16:45:19 +00:00
|
|
|
Ui::Text::WithEntities),
|
2020-09-25 12:31:36 +00:00
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox))
|
|
|
|
: nullptr;
|
2019-06-12 13:26:04 +00:00
|
|
|
|
2020-09-25 12:31:36 +00:00
|
|
|
if (allFromUser) {
|
2019-07-15 13:47:40 +00:00
|
|
|
box->addSkip(st::boxLittleSkip);
|
|
|
|
}
|
2019-06-12 13:26:04 +00:00
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
box->setTitle(tr::lng_blocked_list_confirm_title(
|
|
|
|
lt_name,
|
|
|
|
rpl::single(name)));
|
2019-06-12 13:26:04 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_blocked_list_confirm_ok(), [=] {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto reportChecked = report && report->checked();
|
2019-07-15 13:47:40 +00:00
|
|
|
const auto clearChecked = clear && clear->checked();
|
2020-09-25 12:31:36 +00:00
|
|
|
const auto fromUserChecked = allFromUser && allFromUser->checked();
|
2019-06-12 13:26:04 +00:00
|
|
|
|
|
|
|
box->closeBox();
|
|
|
|
|
2020-09-25 12:31:36 +00:00
|
|
|
if (const auto clearReply = std::get_if<ClearReply>(&suggestClear)) {
|
|
|
|
using Flag = MTPcontacts_BlockFromReplies::Flag;
|
|
|
|
peer->session().api().request(MTPcontacts_BlockFromReplies(
|
|
|
|
MTP_flags((clearChecked ? Flag::f_delete_message : Flag(0))
|
|
|
|
| (fromUserChecked ? Flag::f_delete_history : Flag(0))
|
|
|
|
| (reportChecked ? Flag::f_report_spam : Flag(0))),
|
|
|
|
MTP_int(clearReply->replyId.msg)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
peer->session().updates().applyUpdates(result);
|
|
|
|
}).send();
|
|
|
|
} else {
|
2021-08-01 22:57:36 +00:00
|
|
|
peer->session().api().blockedPeers().block(peer);
|
2020-09-25 12:31:36 +00:00
|
|
|
if (reportChecked) {
|
2020-09-21 16:56:38 +00:00
|
|
|
peer->session().api().request(MTPmessages_ReportSpam(
|
|
|
|
peer->input
|
|
|
|
)).send();
|
|
|
|
}
|
2020-09-25 12:31:36 +00:00
|
|
|
if (clearChecked) {
|
2020-09-17 13:26:53 +00:00
|
|
|
crl::on_main(&peer->session(), [=] {
|
|
|
|
peer->session().api().deleteConversation(peer, false);
|
|
|
|
});
|
|
|
|
window->sessionController()->showBackFromStack();
|
|
|
|
}
|
2019-06-12 13:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 09:33:19 +00:00
|
|
|
window->showToast(
|
2020-09-17 13:26:53 +00:00
|
|
|
tr::lng_new_contact_block_done(tr::now, lt_user, name));
|
2019-06-12 13:26:04 +00:00
|
|
|
}, st::attentionBoxButton);
|
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [=] {
|
2019-06-12 13:26:04 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-04 14:02:22 +00:00
|
|
|
void PeerMenuUnblockUserWithBotRestart(not_null<UserData*> user) {
|
2023-09-01 13:34:05 +00:00
|
|
|
user->session().api().blockedPeers().unblock(user, [=](bool success) {
|
|
|
|
if (success && user->isBot() && !user->isSupport()) {
|
2019-07-04 14:02:22 +00:00
|
|
|
user->session().api().sendBotStart(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-15 17:37:22 +00:00
|
|
|
void BlockSenderFromRepliesBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<SessionController*> controller,
|
|
|
|
FullMsgId id) {
|
|
|
|
const auto item = controller->session().data().message(id);
|
|
|
|
Assert(item != nullptr);
|
|
|
|
|
|
|
|
PeerMenuBlockUserBox(
|
|
|
|
box,
|
|
|
|
&controller->window(),
|
2023-10-10 06:49:22 +00:00
|
|
|
item->originalSender(),
|
2021-02-15 17:37:22 +00:00
|
|
|
true,
|
|
|
|
Window::ClearReply{ id });
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:02:40 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowChooseRecipientBox(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2022-11-30 12:02:40 +00:00
|
|
|
FnMut<bool(not_null<Data::Thread*>)> &&chosen,
|
|
|
|
rpl::producer<QString> titleOverride,
|
2023-05-24 15:36:58 +00:00
|
|
|
FnMut<void()> &&successCallback,
|
|
|
|
InlineBots::PeerTypes typesRestriction) {
|
2022-02-21 01:17:19 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
2022-11-30 12:02:40 +00:00
|
|
|
auto callback = [
|
|
|
|
chosen = std::move(chosen),
|
|
|
|
success = std::move(successCallback),
|
|
|
|
weak
|
2022-11-01 04:46:31 +00:00
|
|
|
](not_null<Data::Thread*> thread) mutable {
|
2022-11-30 12:02:40 +00:00
|
|
|
if (!chosen(thread)) {
|
2019-07-18 10:03:09 +00:00
|
|
|
return;
|
2022-11-30 12:02:40 +00:00
|
|
|
} else if (const auto strong = *weak) {
|
2017-12-06 10:13:38 +00:00
|
|
|
strong->closeBox();
|
|
|
|
}
|
2022-11-30 12:02:40 +00:00
|
|
|
if (success) {
|
|
|
|
success();
|
2017-12-06 10:13:38 +00:00
|
|
|
}
|
|
|
|
};
|
2023-05-24 15:36:58 +00:00
|
|
|
auto filter = typesRestriction
|
|
|
|
? [=](not_null<Data::Thread*> thread) -> bool {
|
|
|
|
using namespace InlineBots;
|
|
|
|
const auto peer = thread->peer();
|
|
|
|
if (const auto user = peer->asUser()) {
|
|
|
|
if (user->isBot()) {
|
|
|
|
return (typesRestriction & PeerType::Bot);
|
|
|
|
} else {
|
|
|
|
return (typesRestriction & PeerType::User);
|
|
|
|
}
|
|
|
|
} else if (peer->isBroadcast()) {
|
|
|
|
return (typesRestriction & PeerType::Broadcast);
|
|
|
|
} else {
|
|
|
|
return (typesRestriction & PeerType::Group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: Fn<bool(not_null<Data::Thread*>)>();
|
2022-11-30 12:02:40 +00:00
|
|
|
auto initBox = [=](not_null<PeerListBox*> box) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [box] {
|
2017-12-06 10:13:38 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
2022-11-30 12:02:40 +00:00
|
|
|
if (titleOverride) {
|
|
|
|
box->setTitle(std::move(titleOverride));
|
|
|
|
}
|
2017-12-06 10:13:38 +00:00
|
|
|
};
|
2022-02-21 01:17:19 +00:00
|
|
|
*weak = navigation->parentController()->show(Box<PeerListBox>(
|
2019-07-25 18:55:11 +00:00
|
|
|
std::make_unique<ChooseRecipientBoxController>(
|
2020-12-21 19:43:23 +00:00
|
|
|
&navigation->session(),
|
2023-05-24 15:36:58 +00:00
|
|
|
std::move(callback),
|
|
|
|
std::move(filter)),
|
2023-05-02 09:33:19 +00:00
|
|
|
std::move(initBox)));
|
2017-12-09 15:13:06 +00:00
|
|
|
return weak->data();
|
2017-12-06 10:13:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 12:02:40 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2022-11-30 12:02:40 +00:00
|
|
|
Data::ForwardDraft &&draft,
|
2022-12-02 00:40:16 +00:00
|
|
|
Fn<void()> &&successCallback) {
|
2023-05-02 09:33:19 +00:00
|
|
|
const auto session = &show->session();
|
|
|
|
const auto owner = &session->data();
|
2023-03-17 15:24:48 +00:00
|
|
|
const auto msgIds = owner->itemsToIds(owner->idsToItems(draft.ids));
|
|
|
|
if (msgIds.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-12-02 00:40:16 +00:00
|
|
|
|
|
|
|
class ListBox final : public PeerListBox {
|
|
|
|
public:
|
|
|
|
using PeerListBox::PeerListBox;
|
|
|
|
|
|
|
|
void setBottomSkip(int bottomSkip) {
|
|
|
|
PeerListBox::setInnerBottomSkip(bottomSkip);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<> focusRequests() const {
|
|
|
|
return _focusRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] Data::ForwardOptions forwardOptionsData() const {
|
|
|
|
return (_forwardOptions.hasCaptions
|
|
|
|
&& _forwardOptions.dropCaptions)
|
|
|
|
? Data::ForwardOptions::NoNamesAndCaptions
|
|
|
|
: _forwardOptions.dropNames
|
|
|
|
? Data::ForwardOptions::NoSenderNames
|
|
|
|
: Data::ForwardOptions::PreserveInfo;
|
|
|
|
}
|
|
|
|
[[nodiscard]] Ui::ForwardOptions forwardOptions() const {
|
|
|
|
return _forwardOptions;
|
2022-11-30 12:02:40 +00:00
|
|
|
}
|
2022-12-02 00:40:16 +00:00
|
|
|
void setForwardOptions(Ui::ForwardOptions forwardOptions) {
|
|
|
|
_forwardOptions = forwardOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
rpl::event_stream<> _focusRequests;
|
|
|
|
Ui::ForwardOptions _forwardOptions;
|
|
|
|
|
2022-11-30 12:02:40 +00:00
|
|
|
};
|
2022-12-02 00:40:16 +00:00
|
|
|
|
|
|
|
class Controller final : public ChooseRecipientBoxController {
|
|
|
|
public:
|
|
|
|
using Chosen = not_null<Data::Thread*>;
|
|
|
|
|
|
|
|
Controller(not_null<Main::Session*> session)
|
|
|
|
: ChooseRecipientBoxController(
|
|
|
|
session,
|
|
|
|
[=](Chosen thread) mutable { _singleChosen.fire_copy(thread); },
|
|
|
|
nullptr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override final {
|
|
|
|
const auto count = delegate()->peerListSelectedRowsCount();
|
|
|
|
if (count && row->peer()->isForum()) {
|
|
|
|
return;
|
|
|
|
} else if (!count || row->peer()->isForum()) {
|
|
|
|
ChooseRecipientBoxController::rowClicked(row);
|
|
|
|
} else if (count) {
|
|
|
|
delegate()->peerListSetRowChecked(row, !row->checked());
|
|
|
|
_hasSelectedChanges.fire(
|
|
|
|
delegate()->peerListSelectedRowsCount() > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PeerListRow*> row) override final {
|
|
|
|
const auto count = delegate()->peerListSelectedRowsCount();
|
|
|
|
if (!count && !row->peer()->isForum()) {
|
|
|
|
auto menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
parent,
|
|
|
|
st::popupMenuWithIcons);
|
|
|
|
menu->addAction(tr::lng_bot_choose_chat(tr::now), [=] {
|
|
|
|
delegate()->peerListSetRowChecked(row, !row->checked());
|
|
|
|
_hasSelectedChanges.fire(
|
|
|
|
delegate()->peerListSelectedRowsCount() > 0);
|
|
|
|
}, &st::menuIconSelect);
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<bool> hasSelectedChanges() const{
|
|
|
|
return _hasSelectedChanges.events_starting_with(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<Chosen> singleChosen() const{
|
|
|
|
return _singleChosen.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
rpl::event_stream<Chosen> _singleChosen;
|
|
|
|
rpl::event_stream<bool> _hasSelectedChanges;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
not_null<ListBox*> box;
|
|
|
|
not_null<Controller*> controller;
|
|
|
|
base::unique_qptr<Ui::PopupMenu> menu;
|
|
|
|
};
|
|
|
|
const auto state = [&] {
|
|
|
|
auto controller = std::make_unique<Controller>(session);
|
|
|
|
const auto controllerRaw = controller.get();
|
|
|
|
auto box = Box<ListBox>(std::move(controller), nullptr);
|
|
|
|
const auto boxRaw = box.data();
|
2023-05-02 09:33:19 +00:00
|
|
|
show->showBox(std::move(box));
|
2022-12-02 00:40:16 +00:00
|
|
|
auto state = State{ boxRaw, controllerRaw };
|
|
|
|
return boxRaw->lifetime().make_state<State>(std::move(state));
|
|
|
|
}();
|
|
|
|
|
|
|
|
{ // Chosen a single.
|
2023-05-02 09:33:19 +00:00
|
|
|
auto chosen = [show, draft = std::move(draft)](
|
2022-12-02 00:40:16 +00:00
|
|
|
not_null<Data::Thread*> thread) mutable {
|
|
|
|
const auto peer = thread->peer();
|
|
|
|
if (peer->isSelf()
|
|
|
|
&& !draft.ids.empty()
|
|
|
|
&& draft.ids.front().peer != peer->id) {
|
2023-05-02 09:33:19 +00:00
|
|
|
ForwardToSelf(show, draft);
|
2022-12-02 00:40:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-05-02 09:33:19 +00:00
|
|
|
auto controller = Core::App().windowFor(peer);
|
|
|
|
if (!controller) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (controller->maybeSession() != &peer->session()) {
|
|
|
|
controller = peer->isForum()
|
|
|
|
? Core::App().ensureSeparateWindowForAccount(
|
|
|
|
&peer->account())
|
|
|
|
: Core::App().ensureSeparateWindowForPeer(
|
|
|
|
peer,
|
|
|
|
ShowAtUnreadMsgId);
|
|
|
|
if (controller->maybeSession() != &peer->session()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto content = controller->sessionController()->content();
|
2022-12-02 00:40:16 +00:00
|
|
|
return content->setForwardDraft(thread, std::move(draft));
|
|
|
|
};
|
|
|
|
auto callback = [=, chosen = std::move(chosen)](
|
|
|
|
Controller::Chosen thread) mutable {
|
|
|
|
const auto weak = Ui::MakeWeak(state->box);
|
|
|
|
if (!chosen(thread)) {
|
|
|
|
return;
|
2022-12-02 14:31:38 +00:00
|
|
|
} else if (const auto strong = weak.data()) {
|
2022-12-02 00:40:16 +00:00
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
state->controller->singleChosen(
|
|
|
|
) | rpl::start_with_next(std::move(callback), state->box->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto comment = Ui::CreateChild<Ui::SlideWrap<Ui::InputField>>(
|
|
|
|
state->box.get(),
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
state->box,
|
|
|
|
st::shareComment,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
|
|
|
tr::lng_photos_comment()),
|
|
|
|
st::shareCommentPadding);
|
|
|
|
|
|
|
|
const auto send = ShareBox::DefaultForwardCallback(
|
2023-05-02 09:33:19 +00:00
|
|
|
show,
|
2022-12-02 00:40:16 +00:00
|
|
|
session->data().message(msgIds.front())->history(),
|
|
|
|
msgIds);
|
|
|
|
|
|
|
|
const auto submit = [=](Api::SendOptions options) {
|
|
|
|
const auto peers = state->box->collectSelectedRows();
|
|
|
|
send(
|
|
|
|
ranges::views::all(
|
|
|
|
peers
|
|
|
|
) | ranges::views::transform([&](
|
|
|
|
not_null<PeerData*> peer) -> Controller::Chosen {
|
|
|
|
return peer->owner().history(peer);
|
|
|
|
}) | ranges::to_vector,
|
|
|
|
comment->entity()->getTextWithAppliedMarkdown(),
|
|
|
|
options,
|
|
|
|
state->box->forwardOptionsData());
|
|
|
|
if (successCallback) {
|
|
|
|
successCallback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto sendMenuType = [=] {
|
|
|
|
const auto selected = state->box->collectSelectedRows();
|
|
|
|
return ranges::all_of(selected, HistoryView::CanScheduleUntilOnline)
|
|
|
|
? SendMenu::Type::ScheduledToUser
|
|
|
|
: ((selected.size() == 1) && selected.front()->isSelf())
|
|
|
|
? SendMenu::Type::Reminder
|
|
|
|
: SendMenu::Type::Scheduled;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto showForwardOptions = true;
|
|
|
|
const auto showMenu = [=](not_null<Ui::RpWidget*> parent) {
|
|
|
|
if (state->menu) {
|
|
|
|
state->menu = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->menu.emplace(parent, st::popupMenuWithIcons);
|
|
|
|
|
|
|
|
if (showForwardOptions) {
|
|
|
|
auto createView = [&](
|
|
|
|
rpl::producer<QString> &&text,
|
|
|
|
bool checked) {
|
|
|
|
auto item = base::make_unique_q<Menu::ItemWithCheck>(
|
|
|
|
state->menu->menu(),
|
|
|
|
st::popupMenuWithIcons.menu,
|
|
|
|
Ui::CreateChild<QAction>(state->menu->menu().get()),
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
std::move(
|
|
|
|
text
|
|
|
|
) | rpl::start_with_next([action = item->action()](
|
|
|
|
QString text) {
|
|
|
|
action->setText(text);
|
|
|
|
}, item->lifetime());
|
|
|
|
item->init(checked);
|
|
|
|
const auto view = item->checkView();
|
|
|
|
state->menu->addAction(std::move(item));
|
|
|
|
return view;
|
|
|
|
};
|
|
|
|
Ui::FillForwardOptions(
|
|
|
|
std::move(createView),
|
|
|
|
msgIds.size(),
|
|
|
|
state->box->forwardOptions(),
|
|
|
|
[=](Ui::ForwardOptions o) {
|
|
|
|
state->box->setForwardOptions(o);
|
|
|
|
},
|
|
|
|
state->menu->lifetime());
|
|
|
|
|
|
|
|
state->menu->addSeparator();
|
|
|
|
}
|
|
|
|
const auto type = sendMenuType();
|
|
|
|
const auto result = SendMenu::FillSendMenu(
|
|
|
|
state->menu.get(),
|
|
|
|
type,
|
|
|
|
SendMenu::DefaultSilentCallback(submit),
|
2023-04-22 18:26:09 +00:00
|
|
|
SendMenu::DefaultScheduleCallback(state->box, type, submit),
|
|
|
|
SendMenu::DefaultWhenOnlineCallback(submit));
|
2022-12-02 00:40:16 +00:00
|
|
|
const auto success = (result == SendMenu::FillMenuResult::Success);
|
|
|
|
if (showForwardOptions || success) {
|
|
|
|
state->menu->setForcedVerticalOrigin(
|
|
|
|
Ui::PopupMenu::VerticalOrigin::Bottom);
|
|
|
|
state->menu->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
comment->hide(anim::type::instant);
|
|
|
|
comment->toggleOn(state->controller->hasSelectedChanges());
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
state->box->sizeValue(),
|
|
|
|
comment->heightValue()
|
|
|
|
) | rpl::start_with_next([=](const QSize &size, int commentHeight) {
|
|
|
|
comment->moveToLeft(0, size.height() - commentHeight);
|
|
|
|
comment->resizeToWidth(size.width());
|
|
|
|
|
|
|
|
state->box->setBottomSkip(comment->isHidden() ? 0 : commentHeight);
|
|
|
|
}, comment->lifetime());
|
|
|
|
|
|
|
|
const auto field = comment->entity();
|
|
|
|
|
2023-08-31 11:21:24 +00:00
|
|
|
field->submits(
|
|
|
|
) | rpl::start_with_next([=] { submit({}); }, field->lifetime());
|
2023-05-02 09:33:19 +00:00
|
|
|
InitMessageFieldHandlers(
|
|
|
|
session,
|
|
|
|
show,
|
|
|
|
field,
|
|
|
|
[=] { return show->paused(GifPauseReason::Layer); });
|
2022-12-02 00:40:16 +00:00
|
|
|
field->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
|
|
|
|
|
|
|
Ui::SendPendingMoveResizeEvents(comment);
|
|
|
|
|
|
|
|
state->box->focusRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (!comment->isHidden()) {
|
|
|
|
comment->entity()->setFocusFast();
|
|
|
|
}
|
|
|
|
}, comment->lifetime());
|
|
|
|
|
|
|
|
state->controller->hasSelectedChanges(
|
|
|
|
) | rpl::start_with_next([=](bool shown) {
|
|
|
|
state->box->clearButtons();
|
|
|
|
if (shown) {
|
|
|
|
const auto send = state->box->addButton(
|
|
|
|
tr::lng_send_button(),
|
|
|
|
[=] { submit({}); });
|
|
|
|
send->setAcceptBoth();
|
|
|
|
send->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton button) {
|
|
|
|
if (button == Qt::RightButton) {
|
|
|
|
showMenu(send);
|
|
|
|
}
|
|
|
|
}, send->lifetime());
|
|
|
|
}
|
|
|
|
state->box->addButton(tr::lng_cancel(), [=] {
|
|
|
|
state->box->closeBox();
|
|
|
|
});
|
|
|
|
}, state->box->lifetime());
|
|
|
|
|
|
|
|
return QPointer<Ui::BoxContent>(state->box);
|
2022-11-30 12:02:40 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 09:33:19 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
Data::ForwardDraft &&draft,
|
|
|
|
Fn<void()> &&successCallback) {
|
|
|
|
return ShowForwardMessagesBox(
|
|
|
|
navigation->uiShow(),
|
|
|
|
std::move(draft),
|
|
|
|
std::move(successCallback));
|
|
|
|
}
|
|
|
|
|
2022-02-27 11:14:39 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
2021-08-31 16:47:38 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
MessageIdsList &&items,
|
2022-12-02 00:40:16 +00:00
|
|
|
Fn<void()> &&successCallback) {
|
2021-08-31 16:47:38 +00:00
|
|
|
return ShowForwardMessagesBox(
|
|
|
|
navigation,
|
|
|
|
Data::ForwardDraft{ .ids = std::move(items) },
|
|
|
|
std::move(successCallback));
|
|
|
|
}
|
|
|
|
|
2022-11-01 09:00:17 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowShareGameBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
QString shortName) {
|
|
|
|
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
|
|
|
auto chosen = [=](not_null<Data::Thread*> thread) mutable {
|
|
|
|
const auto confirm = std::make_shared<QPointer<Ui::BoxContent>>();
|
|
|
|
auto send = crl::guard(thread, [=] {
|
|
|
|
ShareBotGame(bot, thread, shortName);
|
|
|
|
if (const auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (const auto strong = *confirm) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
navigation->showThread(
|
|
|
|
thread,
|
|
|
|
ShowAtUnreadMsgId,
|
|
|
|
SectionShow::Way::ClearStack);
|
|
|
|
});
|
2022-11-01 11:17:13 +00:00
|
|
|
const auto confirmText = thread->peer()->isUser()
|
2022-11-01 09:00:17 +00:00
|
|
|
? tr::lng_bot_sure_share_game(
|
|
|
|
tr::now,
|
|
|
|
lt_user,
|
|
|
|
thread->chatListName())
|
|
|
|
: tr::lng_bot_sure_share_game_group(
|
|
|
|
tr::now,
|
|
|
|
lt_group,
|
|
|
|
thread->chatListName());
|
|
|
|
*confirm = navigation->parentController()->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = confirmText,
|
|
|
|
.confirmed = std::move(send),
|
2023-05-02 09:33:19 +00:00
|
|
|
}));
|
2022-11-01 09:00:17 +00:00
|
|
|
};
|
|
|
|
auto filter = [](not_null<Data::Thread*> thread) {
|
2023-01-10 18:56:20 +00:00
|
|
|
return !thread->peer()->isSelf()
|
|
|
|
&& (Data::CanSend(thread, ChatRestriction::SendGames)
|
|
|
|
|| thread->asForum());
|
2022-11-01 09:00:17 +00:00
|
|
|
};
|
|
|
|
auto initBox = [](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(tr::lng_cancel(), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*weak = navigation->parentController()->show(Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseRecipientBoxController>(
|
|
|
|
&navigation->session(),
|
|
|
|
std::move(chosen),
|
|
|
|
std::move(filter)),
|
2023-05-02 09:33:19 +00:00
|
|
|
std::move(initBox)));
|
2022-11-01 09:00:17 +00:00
|
|
|
return weak->data();
|
|
|
|
}
|
|
|
|
|
2022-11-01 07:18:56 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowDropMediaBox(
|
2022-11-01 04:46:31 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2022-11-01 07:18:56 +00:00
|
|
|
std::shared_ptr<QMimeData> data,
|
2022-11-01 04:46:31 +00:00
|
|
|
not_null<Data::Forum*> forum,
|
|
|
|
FnMut<void()> &&successCallback) {
|
|
|
|
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
|
|
|
|
auto chosen = [
|
2022-11-01 07:18:56 +00:00
|
|
|
data = std::move(data),
|
2022-11-01 04:46:31 +00:00
|
|
|
callback = std::move(successCallback),
|
|
|
|
weak,
|
|
|
|
navigation
|
|
|
|
](not_null<Data::ForumTopic*> topic) mutable {
|
|
|
|
const auto content = navigation->parentController()->content();
|
2022-11-30 12:02:40 +00:00
|
|
|
if (!content->filesOrForwardDrop(topic, data.get())) {
|
2022-11-01 04:46:31 +00:00
|
|
|
return;
|
|
|
|
} else if (const auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
2022-11-02 04:51:03 +00:00
|
|
|
auto initBox = [=](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(tr::lng_cancel(), [=] {
|
2022-11-01 04:46:31 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
2022-11-02 04:51:03 +00:00
|
|
|
|
|
|
|
forum->destroyed(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
box->closeBox();
|
|
|
|
}, box->lifetime());
|
2022-11-01 04:46:31 +00:00
|
|
|
};
|
|
|
|
*weak = navigation->parentController()->show(Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseTopicBoxController>(
|
|
|
|
forum,
|
|
|
|
std::move(chosen)),
|
2022-11-02 04:51:03 +00:00
|
|
|
std::move(initBox)));
|
2022-11-01 04:46:31 +00:00
|
|
|
return weak->data();
|
|
|
|
}
|
|
|
|
|
2022-02-27 11:14:39 +00:00
|
|
|
QPointer<Ui::BoxContent> ShowSendNowMessagesBox(
|
2019-08-09 17:58:58 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<History*> history,
|
|
|
|
MessageIdsList &&items,
|
2022-02-27 08:28:16 +00:00
|
|
|
Fn<void()> &&successCallback) {
|
2019-08-09 17:58:58 +00:00
|
|
|
const auto session = &navigation->session();
|
2019-08-30 12:24:42 +00:00
|
|
|
const auto text = (items.size() > 1)
|
|
|
|
? tr::lng_scheduled_send_now_many(tr::now, lt_count, items.size())
|
|
|
|
: tr::lng_scheduled_send_now(tr::now);
|
2019-08-30 13:17:46 +00:00
|
|
|
|
2022-10-25 07:20:22 +00:00
|
|
|
const auto list = session->data().idsToItems(items);
|
2019-08-30 13:17:46 +00:00
|
|
|
const auto error = GetErrorTextForSending(
|
|
|
|
history->peer,
|
2022-10-25 07:20:22 +00:00
|
|
|
{ .forward = &list });
|
2019-08-30 13:17:46 +00:00
|
|
|
if (!error.isEmpty()) {
|
2023-05-02 09:33:19 +00:00
|
|
|
navigation->showToast(error);
|
2019-08-30 13:17:46 +00:00
|
|
|
return { nullptr };
|
|
|
|
}
|
2019-08-09 17:58:58 +00:00
|
|
|
auto done = [
|
|
|
|
=,
|
|
|
|
list = std::move(items),
|
|
|
|
callback = std::move(successCallback)
|
2022-02-27 08:28:16 +00:00
|
|
|
](Fn<void()> &&close) {
|
2020-09-24 12:48:02 +00:00
|
|
|
close();
|
2019-08-09 17:58:58 +00:00
|
|
|
auto ids = QVector<MTPint>();
|
2019-08-30 13:17:46 +00:00
|
|
|
for (const auto item : session->data().idsToItems(list)) {
|
|
|
|
if (item->allowsSendNow()) {
|
|
|
|
ids.push_back(MTP_int(
|
|
|
|
session->data().scheduledMessages().lookupId(item)));
|
2019-08-09 17:58:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
session->api().request(MTPmessages_SendScheduledMessages(
|
|
|
|
history->peer->input,
|
|
|
|
MTP_vector<MTPint>(ids)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
session->api().applyUpdates(result);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2019-08-30 13:17:46 +00:00
|
|
|
session->api().sendMessageFail(error, history->peer);
|
2019-08-09 17:58:58 +00:00
|
|
|
}).send();
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
2023-05-02 09:33:19 +00:00
|
|
|
return navigation->parentController()->show(Ui::MakeConfirmBox({
|
|
|
|
.text = text,
|
|
|
|
.confirmed = std::move(done),
|
|
|
|
.confirmText = tr::lng_send_button(),
|
|
|
|
})).data();
|
2019-08-09 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
void PeerMenuAddChannelMembers(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChannelData*> channel) {
|
2017-12-08 14:25:29 +00:00
|
|
|
if (!channel->isMegagroup()
|
2020-06-17 09:36:25 +00:00
|
|
|
&& (channel->membersCount()
|
|
|
|
>= channel->session().serverConfig().chatSizeMax)) {
|
2023-05-02 09:33:19 +00:00
|
|
|
navigation->parentController()->show(Box<MaxInviteBox>(channel));
|
2017-11-19 14:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto api = &channel->session().api();
|
2021-11-24 04:25:05 +00:00
|
|
|
api->chatParticipants().requestForAdd(channel, crl::guard(navigation, [=](
|
2021-11-24 04:25:05 +00:00
|
|
|
const Api::ChatParticipants::TLMembers &data) {
|
|
|
|
const auto &[availableCount, list] = Api::ChatParticipants::Parse(
|
|
|
|
channel,
|
|
|
|
data);
|
|
|
|
const auto already = (
|
|
|
|
list
|
|
|
|
) | ranges::views::transform([&](const Api::ChatParticipant &p) {
|
|
|
|
return p.isUser()
|
|
|
|
? channel->owner().userLoaded(p.userId())
|
|
|
|
: nullptr;
|
|
|
|
}) | ranges::views::filter([](UserData *user) {
|
|
|
|
return (user != nullptr);
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
|
|
|
AddParticipantsBoxController::Start(
|
|
|
|
navigation,
|
|
|
|
channel,
|
|
|
|
{ already.begin(), already.end() });
|
2020-06-30 14:26:44 +00:00
|
|
|
}));
|
2017-11-19 14:41:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 14:41:13 +00:00
|
|
|
void ToggleMessagePinned(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
FullMsgId itemId,
|
|
|
|
bool pin) {
|
|
|
|
const auto item = navigation->session().data().message(itemId);
|
|
|
|
if (!item || !item->canPin()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pin) {
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
2023-04-21 11:09:06 +00:00
|
|
|
Box(PinMessageBox, item),
|
2022-02-21 01:17:19 +00:00
|
|
|
Ui::LayerOption::CloseOther);
|
2020-10-21 14:41:13 +00:00
|
|
|
} else {
|
|
|
|
const auto peer = item->history()->peer;
|
|
|
|
const auto session = &peer->session();
|
2022-02-21 01:17:19 +00:00
|
|
|
const auto callback = crl::guard(session, [=](Fn<void()> &&close) {
|
|
|
|
close();
|
2020-10-21 14:41:13 +00:00
|
|
|
session->api().request(MTPmessages_UpdatePinnedMessage(
|
|
|
|
MTP_flags(MTPmessages_UpdatePinnedMessage::Flag::f_unpin),
|
|
|
|
peer->input,
|
|
|
|
MTP_int(itemId.msg)
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
session->api().applyUpdates(result);
|
|
|
|
}).send();
|
2021-10-18 22:28:08 +00:00
|
|
|
});
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_pinned_unpin_sure(),
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_pinned_unpin(),
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2020-10-21 14:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
void HidePinnedBar(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<PeerData*> peer,
|
2022-10-28 05:19:27 +00:00
|
|
|
MsgId topicRootId,
|
2020-10-22 07:53:56 +00:00
|
|
|
Fn<void()> onHidden) {
|
2022-02-21 01:17:19 +00:00
|
|
|
const auto callback = crl::guard(navigation, [=](Fn<void()> &&close) {
|
|
|
|
close();
|
2020-10-22 07:53:56 +00:00
|
|
|
auto &session = peer->session();
|
2022-10-28 05:19:27 +00:00
|
|
|
const auto migrated = topicRootId ? nullptr : peer->migrateFrom();
|
|
|
|
const auto top = Data::ResolveTopPinnedId(
|
|
|
|
peer,
|
|
|
|
topicRootId,
|
|
|
|
migrated);
|
2020-10-22 12:40:33 +00:00
|
|
|
const auto universal = !top
|
2021-12-09 07:32:54 +00:00
|
|
|
? MsgId(0)
|
|
|
|
: (migrated && !peerIsChannel(top.peer))
|
2020-10-22 12:40:33 +00:00
|
|
|
? (top.msg - ServerMaxMsgId)
|
|
|
|
: top.msg;
|
|
|
|
if (universal) {
|
2022-10-28 05:19:27 +00:00
|
|
|
session.settings().setHiddenPinnedMessageId(
|
|
|
|
peer->id,
|
|
|
|
topicRootId,
|
|
|
|
universal);
|
2020-10-22 07:53:56 +00:00
|
|
|
session.saveSettingsDelayed();
|
|
|
|
if (onHidden) {
|
|
|
|
onHidden();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session.api().requestFullPeer(peer);
|
|
|
|
}
|
2021-10-18 22:28:08 +00:00
|
|
|
});
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_pinned_hide_all_sure(),
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_pinned_hide_all_hide(),
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2020-10-22 07:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnpinAllMessages(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2022-10-28 05:19:27 +00:00
|
|
|
not_null<Data::Thread*> thread) {
|
|
|
|
const auto weak = base::make_weak(thread);
|
2022-02-21 01:17:19 +00:00
|
|
|
const auto callback = crl::guard(navigation, [=](Fn<void()> &&close) {
|
|
|
|
close();
|
2022-10-28 05:19:27 +00:00
|
|
|
const auto strong = weak.get();
|
2022-11-01 05:22:21 +00:00
|
|
|
if (!strong) {
|
2022-10-28 05:19:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto api = &strong->session().api();
|
2020-10-22 07:53:56 +00:00
|
|
|
const auto sendRequest = [=](auto self) -> void {
|
2022-10-28 05:19:27 +00:00
|
|
|
const auto history = strong->owningHistory();
|
|
|
|
const auto topicRootId = strong->topicRootId();
|
2022-11-01 05:22:21 +00:00
|
|
|
using Flag = MTPmessages_UnpinAllMessages::Flag;
|
2020-10-22 07:53:56 +00:00
|
|
|
api->request(MTPmessages_UnpinAllMessages(
|
2022-11-01 05:22:21 +00:00
|
|
|
MTP_flags(topicRootId ? Flag::f_top_msg_id : Flag()),
|
|
|
|
history->peer->input,
|
|
|
|
MTP_int(topicRootId.bare)
|
2020-10-22 07:53:56 +00:00
|
|
|
)).done([=](const MTPmessages_AffectedHistory &result) {
|
2020-10-30 14:12:04 +00:00
|
|
|
const auto peer = history->peer;
|
2020-10-22 07:53:56 +00:00
|
|
|
const auto offset = api->applyAffectedHistory(peer, result);
|
|
|
|
if (offset > 0) {
|
|
|
|
self(self);
|
|
|
|
} else {
|
2022-10-28 05:19:27 +00:00
|
|
|
history->unpinMessagesFor(topicRootId);
|
2020-10-22 07:53:56 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
sendRequest(sendRequest);
|
2021-10-18 22:28:08 +00:00
|
|
|
});
|
2022-02-21 01:17:19 +00:00
|
|
|
navigation->parentController()->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_pinned_unpin_all_sure(),
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_pinned_unpin(),
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2020-10-22 07:53:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 14:56:01 +00:00
|
|
|
void MenuAddMarkAsReadAllChatsAction(
|
2022-02-21 01:17:19 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-16 14:09:04 +00:00
|
|
|
const PeerMenuCallback &addAction) {
|
2022-02-21 01:17:19 +00:00
|
|
|
// There is no async to make weak from controller.
|
|
|
|
auto callback = [=, owner = &controller->session().data()] {
|
2020-09-17 14:56:01 +00:00
|
|
|
auto boxCallback = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
|
|
|
|
|
|
|
MarkAsReadChatList(owner->chatsList());
|
|
|
|
if (const auto folder = owner->folderLoaded(Data::Folder::kId)) {
|
|
|
|
MarkAsReadChatList(folder->chatsList());
|
|
|
|
}
|
|
|
|
};
|
2022-02-21 01:17:19 +00:00
|
|
|
controller->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
tr::lng_context_mark_read_all_sure(),
|
|
|
|
std::move(boxCallback)
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2020-09-17 14:56:01 +00:00
|
|
|
};
|
|
|
|
addAction(
|
|
|
|
tr::lng_context_mark_read_all(tr::now),
|
2021-12-09 17:56:24 +00:00
|
|
|
std::move(callback),
|
|
|
|
&st::menuIconMarkRead);
|
2020-09-17 14:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MenuAddMarkAsReadChatListAction(
|
2022-02-21 01:17:19 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-17 14:56:01 +00:00
|
|
|
Fn<not_null<Dialogs::MainList*>()> &&list,
|
2023-07-28 00:28:29 +00:00
|
|
|
const PeerMenuCallback &addAction,
|
|
|
|
Fn<Dialogs::UnreadState()> customUnreadState) {
|
2022-02-21 01:17:19 +00:00
|
|
|
// There is no async to make weak from controller.
|
2023-07-28 00:28:29 +00:00
|
|
|
const auto unreadState = customUnreadState
|
|
|
|
? customUnreadState()
|
|
|
|
: list()->unreadState();
|
2022-10-20 08:57:12 +00:00
|
|
|
if (!unreadState.messages && !unreadState.marks && !unreadState.chats) {
|
2020-09-16 14:09:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto callback = [=] {
|
|
|
|
if (unreadState.messages > kMaxUnreadWithoutConfirmation) {
|
|
|
|
auto boxCallback = [=](Fn<void()> &&close) {
|
2020-09-17 14:56:01 +00:00
|
|
|
MarkAsReadChatList(list());
|
2020-09-16 14:09:04 +00:00
|
|
|
close();
|
|
|
|
};
|
2022-02-21 01:17:19 +00:00
|
|
|
controller->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
tr::lng_context_mark_read_sure(),
|
|
|
|
std::move(boxCallback)
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2020-09-16 14:09:04 +00:00
|
|
|
} else {
|
2020-09-17 14:56:01 +00:00
|
|
|
MarkAsReadChatList(list());
|
2020-09-16 14:09:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
addAction(
|
|
|
|
tr::lng_context_mark_read(tr::now),
|
2021-12-09 17:56:24 +00:00
|
|
|
std::move(callback),
|
|
|
|
&st::menuIconMarkRead);
|
2020-09-16 14:09:04 +00:00
|
|
|
}
|
2021-02-25 13:03:51 +00:00
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
void ToggleHistoryArchived(not_null<History*> history, bool archived) {
|
|
|
|
const auto callback = [=] {
|
2020-04-29 14:52:40 +00:00
|
|
|
Ui::Toast::Show(Ui::Toast::Config{
|
|
|
|
.text = { (archived
|
|
|
|
? tr::lng_archived_added(tr::now)
|
|
|
|
: tr::lng_archived_removed(tr::now)) },
|
|
|
|
.st = &st::windowArchiveToast,
|
2023-05-02 09:33:19 +00:00
|
|
|
.duration = (archived
|
2020-04-29 14:52:40 +00:00
|
|
|
? kArchivedToastDuration
|
|
|
|
: Ui::Toast::kDefaultDuration),
|
|
|
|
.multiline = true,
|
|
|
|
});
|
2019-04-18 08:28:43 +00:00
|
|
|
};
|
|
|
|
history->session().api().toggleHistoryArchived(
|
|
|
|
history,
|
|
|
|
archived,
|
|
|
|
callback);
|
|
|
|
}
|
2018-01-23 16:51:12 +00:00
|
|
|
|
2022-02-21 01:17:19 +00:00
|
|
|
Fn<void()> ClearHistoryHandler(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->show(Box<DeleteMessagesBox>(peer, true));
|
2017-12-06 14:39:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-21 01:17:19 +00:00
|
|
|
Fn<void()> DeleteAndLeaveHandler(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2023-05-02 09:33:19 +00:00
|
|
|
controller->show(Box<DeleteMessagesBox>(peer, false));
|
2017-12-06 14:39:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-12 15:46:17 +00:00
|
|
|
void FillDialogsEntryMenu(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller,
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState request,
|
2020-11-11 20:47:40 +00:00
|
|
|
const PeerMenuCallback &callback) {
|
2020-11-12 15:46:17 +00:00
|
|
|
Filler(controller, request, callback).fill();
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:21:11 +00:00
|
|
|
bool FillVideoChatMenu(
|
|
|
|
not_null<SessionController*> controller,
|
|
|
|
Dialogs::EntryState request,
|
|
|
|
const PeerMenuCallback &addAction) {
|
|
|
|
const auto peer = request.key.peer();
|
|
|
|
if (!peer || peer->isUser()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto callback = [=](Calls::StartGroupCallArgs &&args) {
|
|
|
|
controller->startOrJoinGroupCall(peer, std::move(args));
|
|
|
|
};
|
|
|
|
const auto rtmpCallback = [=] {
|
2023-05-02 09:33:19 +00:00
|
|
|
Core::App().calls().showStartWithRtmp(controller->uiShow(), peer);
|
2022-10-28 13:21:11 +00:00
|
|
|
};
|
|
|
|
const auto livestream = !peer->isMegagroup() && peer->isChannel();
|
|
|
|
const auto has = (peer->groupCall() != nullptr);
|
|
|
|
const auto manager = peer->canManageGroupCall();
|
|
|
|
const auto creator = peer->isChat()
|
|
|
|
? peer->asChat()->amCreator()
|
|
|
|
: peer->asChannel()->amCreator();
|
|
|
|
if (has) {
|
|
|
|
addAction(
|
|
|
|
tr::lng_menu_start_group_call_join(tr::now),
|
|
|
|
[=] { callback({}); },
|
2022-11-01 15:23:52 +00:00
|
|
|
&st::menuIconVideoChat);
|
2022-10-28 13:21:11 +00:00
|
|
|
} else if (manager) {
|
|
|
|
addAction(
|
|
|
|
(livestream
|
|
|
|
? tr::lng_menu_start_group_call_channel
|
|
|
|
: tr::lng_menu_start_group_call)(tr::now),
|
|
|
|
[=] { callback({}); },
|
2022-11-01 15:23:52 +00:00
|
|
|
creator ? &st::menuIconStartStream : &st::menuIconVideoChat);
|
2022-10-28 13:21:11 +00:00
|
|
|
}
|
|
|
|
if (!has && creator) {
|
|
|
|
addAction(
|
|
|
|
(livestream
|
|
|
|
? tr::lng_menu_start_group_call_scheduled_channel
|
|
|
|
: tr::lng_menu_start_group_call_scheduled)(tr::now),
|
|
|
|
[=] { callback({ .scheduleNeeded = true }); },
|
|
|
|
&st::menuIconReschedule);
|
|
|
|
addAction(
|
|
|
|
(livestream
|
|
|
|
? tr::lng_menu_start_group_call_with_channel
|
|
|
|
: tr::lng_menu_start_group_call_with)(tr::now),
|
|
|
|
rtmpCallback,
|
|
|
|
&st::menuIconStartStreamWith);
|
|
|
|
}
|
|
|
|
return has || manager;
|
|
|
|
}
|
|
|
|
|
2023-01-04 10:34:37 +00:00
|
|
|
bool IsUnreadThread(not_null<Data::Thread*> thread) {
|
|
|
|
return thread->chatListBadgesState().unread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsReadThread(not_null<Data::Thread*> thread) {
|
|
|
|
const auto readHistory = [&](not_null<History*> history) {
|
|
|
|
history->owner().histories().readInbox(history);
|
|
|
|
};
|
|
|
|
if (!IsUnreadThread(thread)) {
|
|
|
|
return;
|
|
|
|
} else if (const auto forum = thread->asForum()) {
|
|
|
|
forum->enumerateTopics([](
|
|
|
|
not_null<Data::ForumTopic*> topic) {
|
|
|
|
MarkAsReadThread(topic);
|
|
|
|
});
|
|
|
|
} else if (const auto history = thread->asHistory()) {
|
|
|
|
readHistory(history);
|
|
|
|
if (const auto migrated = history->migrateSibling()) {
|
|
|
|
readHistory(migrated);
|
|
|
|
}
|
|
|
|
} else if (const auto topic = thread->asTopic()) {
|
|
|
|
topic->readTillEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 15:32:25 +00:00
|
|
|
void AddSeparatorAndShiftUp(const PeerMenuCallback &addAction) {
|
|
|
|
addAction({ .isSeparator = true });
|
|
|
|
|
|
|
|
const auto &st = st::popupMenuExpandedSeparator.menu;
|
|
|
|
const auto shift = st::popupMenuExpandedSeparator.scrollPadding.top()
|
|
|
|
+ st.itemPadding.top()
|
|
|
|
+ st.itemStyle.font->height
|
|
|
|
+ st.itemPadding.bottom()
|
|
|
|
+ st.separator.padding.top()
|
|
|
|
+ st.separator.width / 2;
|
|
|
|
addAction({ .addTopShift = -shift });
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace Window
|