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"
|
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/mute_settings_box.h"
|
2017-11-07 13:13:41 +00:00
|
|
|
#include "boxes/add_contact_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"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/add_participants_box.h"
|
2019-06-12 14:13:49 +00:00
|
|
|
#include "boxes/peers/edit_contact_box.h"
|
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"
|
2019-06-12 13:26:04 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2020-09-30 07:51:17 +00:00
|
|
|
#include "ui/toasts/common_toasts.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"
|
2017-11-06 18:03:20 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2017-11-30 17:45:36 +00:00
|
|
|
#include "mainwindow.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"
|
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"
|
2019-08-09 17:58:58 +00:00
|
|
|
#include "history/history_item.h"
|
2019-08-30 13:17:46 +00:00
|
|
|
#include "history/history_message.h" // GetErrorTextForSending.
|
2021-02-15 17:37:22 +00:00
|
|
|
#include "history/view/history_view_context_menu.h"
|
2021-05-26 21:55:40 +00:00
|
|
|
#include "window/window_adaptive.h" // Adaptive::isThreeColumn
|
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"
|
2018-11-20 15:36:36 +00:00
|
|
|
#include "support/support_helper.h"
|
2018-02-16 15:46:24 +00:00
|
|
|
#include "info/info_memento.h"
|
|
|
|
#include "info/info_controller.h"
|
2018-04-09 17:48:29 +00:00
|
|
|
#include "info/profile/info_profile_values.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"
|
2019-02-17 11:43:46 +00:00
|
|
|
#include "data/data_drafts.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"
|
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
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QAction>
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
namespace Window {
|
2017-11-07 13:13:41 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-06-24 09:14:19 +00:00
|
|
|
constexpr auto kArchivedToastDuration = crl::time(5000);
|
2020-09-16 14:09:04 +00:00
|
|
|
constexpr auto kMaxUnreadWithoutConfirmation = 10000;
|
2019-04-25 09:20:20 +00:00
|
|
|
|
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
|
|
|
[[nodiscard]] bool IsUnreadHistory(not_null<History*> history) {
|
|
|
|
return (history->chatListUnreadCount() > 0)
|
|
|
|
|| (history->chatListUnreadMark());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MarkAsReadHistory(not_null<History*> history) {
|
|
|
|
const auto read = [&](not_null<History*> history) {
|
|
|
|
if (IsUnreadHistory(history)) {
|
|
|
|
history->peer->owner().histories().readInbox(history);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
read(history);
|
|
|
|
if (const auto migrated = history->migrateSibling()) {
|
|
|
|
read(migrated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2020-09-25 17:22:43 +00:00
|
|
|
ranges::for_each(mark, MarkAsReadHistory);
|
2020-09-17 14:56:01 +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
|
|
|
|
2020-04-29 10:42:24 +00:00
|
|
|
[[nodiscard]] bool showInfo();
|
|
|
|
[[nodiscard]] bool showHidePromotion();
|
|
|
|
[[nodiscard]] bool showToggleArchived();
|
|
|
|
[[nodiscard]] bool showTogglePin();
|
|
|
|
void addHidePromotion();
|
2019-05-01 13:10:11 +00:00
|
|
|
void addTogglePin();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addInfo();
|
2019-04-25 08:36:31 +00:00
|
|
|
//void addSearch();
|
2018-06-26 18:03:45 +00:00
|
|
|
void addToggleUnreadMark();
|
2019-04-18 08:28:43 +00:00
|
|
|
void addToggleArchive();
|
2017-11-06 18:03:20 +00:00
|
|
|
void addUserActions(not_null<UserData*> user);
|
|
|
|
void addBlockUser(not_null<UserData*> user);
|
|
|
|
void addChatActions(not_null<ChatData*> chat);
|
|
|
|
void addChannelActions(not_null<ChannelData*> channel);
|
2020-11-12 15:46:17 +00:00
|
|
|
void addTogglesForArchive();
|
2017-11-06 18:03:20 +00:00
|
|
|
|
2020-08-03 09:02:41 +00:00
|
|
|
void addPollAction(not_null<PeerData*> peer);
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> _controller;
|
2020-11-12 15:46:17 +00:00
|
|
|
Dialogs::EntryState _request;
|
|
|
|
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) {
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto &order = data->pinnedChatsOrder(folder, FilterId());
|
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
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
bool PinnedLimitReached(Dialogs::Key key, FilterId filterId) {
|
2021-09-01 10:27:36 +00:00
|
|
|
Expects(filterId != 0 || key.entry()->folderKnown());
|
2019-04-19 08:47:49 +00:00
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto entry = key.entry();
|
|
|
|
const auto owner = &entry->owner();
|
|
|
|
const auto folder = entry->folder();
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto pinnedCount = owner->pinnedChatsCount(folder, filterId);
|
|
|
|
const auto pinnedMax = owner->pinnedChatsLimit(folder, filterId);
|
2018-01-05 15:57:18 +00:00
|
|
|
if (pinnedCount < pinnedMax) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Some old chat, that was converted, maybe is still pinned.
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto wasted = filterId ? nullptr : FindWastedPin(owner, folder);
|
|
|
|
if (wasted) {
|
|
|
|
owner->setChatPinned(wasted, FilterId(), false);
|
|
|
|
owner->setChatPinned(key, FilterId(), true);
|
2019-07-24 11:13:51 +00:00
|
|
|
entry->session().api().savePinnedOrder(folder);
|
2018-01-05 15:57:18 +00:00
|
|
|
} else {
|
2020-03-19 20:20:35 +00:00
|
|
|
const auto errorText = filterId
|
|
|
|
? tr::lng_filters_error_pinned_max(tr::now)
|
|
|
|
: tr::lng_error_pinned_max(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
pinnedMax);
|
2018-01-05 15:57:18 +00:00
|
|
|
Ui::show(Box<InformBox>(errorText));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:33:15 +00:00
|
|
|
void TogglePinnedDialog(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Dialogs::Key key) {
|
2019-04-19 08:47:49 +00:00
|
|
|
if (!key.entry()->folderKnown()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &key.entry()->owner();
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto isPinned = !key.entry()->isPinnedDialog(0);
|
|
|
|
if (isPinned && PinnedLimitReached(key, 0)) {
|
2018-01-05 15:57:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
owner->setChatPinned(key, FilterId(), isPinned);
|
2019-04-19 08:47:49 +00:00
|
|
|
const auto flags = isPinned
|
|
|
|
? MTPmessages_ToggleDialogPin::Flag::f_pinned
|
|
|
|
: MTPmessages_ToggleDialogPin::Flag(0);
|
|
|
|
if (const auto history = key.history()) {
|
|
|
|
history->session().api().request(MTPmessages_ToggleDialogPin(
|
2018-03-06 17:07:42 +00:00
|
|
|
MTP_flags(flags),
|
2019-04-19 08:47:49 +00:00
|
|
|
MTP_inputDialogPeer(key.history()->peer->input)
|
2019-05-02 13:26:47 +00:00
|
|
|
)).done([=](const MTPBool &result) {
|
2019-07-24 11:13:51 +00:00
|
|
|
owner->notifyPinnedDialogsOrderUpdated();
|
2019-05-02 13:26:47 +00:00
|
|
|
}).send();
|
2019-04-19 08:47:49 +00:00
|
|
|
} else if (const auto folder = key.folder()) {
|
|
|
|
folder->session().api().request(MTPmessages_ToggleDialogPin(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_inputDialogPeerFolder(MTP_int(folder->id()))
|
|
|
|
)).send();
|
2018-03-06 17:07:42 +00:00
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
if (isPinned) {
|
2020-06-11 16:33:15 +00:00
|
|
|
controller->content()->dialogsToUp();
|
2018-01-05 15:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:33:15 +00:00
|
|
|
void TogglePinnedDialog(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Dialogs::Key key,
|
|
|
|
FilterId filterId) {
|
2020-03-17 13:04:30 +00:00
|
|
|
if (!filterId) {
|
2020-06-11 16:33:15 +00:00
|
|
|
return TogglePinnedDialog(controller, key);
|
2020-03-17 13:04:30 +00:00
|
|
|
}
|
|
|
|
const auto owner = &key.entry()->owner();
|
2020-04-29 17:40:09 +00:00
|
|
|
|
|
|
|
// This can happen when you remove this filter from another client.
|
|
|
|
if (!ranges::contains(
|
|
|
|
(&owner->session())->data().chatsFilters().list(),
|
|
|
|
filterId,
|
|
|
|
&Data::ChatFilter::id)) {
|
|
|
|
Ui::Toast::Show(tr::lng_cant_do_this(tr::now));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto isPinned = !key.entry()->isPinnedDialog(filterId);
|
|
|
|
if (isPinned && PinnedLimitReached(key, filterId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
owner->setChatPinned(key, 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)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool Filler::showInfo() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section == Section::Profile
|
2020-09-15 06:58:24 +00:00
|
|
|
|| _peer->isSelf()
|
|
|
|
|| _peer->isRepliesChat()) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return false;
|
2018-01-22 16:42:25 +00:00
|
|
|
} else if (_controller->activeChatCurrent().peer() != _peer) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return true;
|
2021-05-26 21:55:40 +00:00
|
|
|
} else if (!_controller->adaptive().isThreeColumn()) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return true;
|
2020-06-25 12:16:09 +00:00
|
|
|
} else if (!Core::App().settings().thirdSectionInfoEnabled()
|
|
|
|
&& !Core::App().settings().tabbedReplacedWithInfo()) {
|
2017-11-07 15:12:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 10:42:24 +00:00
|
|
|
bool Filler::showHidePromotion() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2020-04-29 10:42:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
|
|
|
return history
|
|
|
|
&& history->useTopPromotion()
|
|
|
|
&& !history->topPromotionType().isEmpty();
|
|
|
|
}
|
|
|
|
|
2019-04-25 09:04:30 +00:00
|
|
|
bool Filler::showToggleArchived() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2019-04-25 09:04:30 +00:00
|
|
|
return false;
|
2019-05-01 09:41:56 +00:00
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
2020-04-24 10:31:28 +00:00
|
|
|
if (history && history->useTopPromotion()) {
|
2019-05-01 09:41:56 +00:00
|
|
|
return false;
|
2019-05-01 11:54:26 +00:00
|
|
|
} else if (!_peer->isNotificationsUser() && !_peer->isSelf()) {
|
2019-04-25 09:04:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-01 09:41:56 +00:00
|
|
|
return history && (history->folder() != nullptr);
|
2019-04-25 09:04:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 13:10:11 +00:00
|
|
|
bool Filler::showTogglePin() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2019-05-01 13:10:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto history = _peer->owner().historyLoaded(_peer);
|
|
|
|
return history && !history->fixedOnTopIndex();
|
|
|
|
}
|
|
|
|
|
2020-04-29 10:42:24 +00:00
|
|
|
void Filler::addHidePromotion() {
|
|
|
|
const auto history = _peer->owner().history(_peer);
|
|
|
|
_addAction(tr::lng_context_hide_psa(tr::now), [=] {
|
|
|
|
history->cacheTopPromotion(false, QString(), QString());
|
|
|
|
history->session().api().request(MTPhelp_HidePromoData(
|
|
|
|
history->peer->input
|
|
|
|
)).send();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-01 13:10:11 +00:00
|
|
|
void Filler::addTogglePin() {
|
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;
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto peer = _peer;
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
|
|
|
const auto pinText = [=] {
|
|
|
|
return history->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
|
|
|
};
|
2020-03-17 13:04:30 +00:00
|
|
|
const auto pinToggle = [=] {
|
2020-06-17 14:00:20 +00:00
|
|
|
TogglePinnedDialog(controller, history, filterId);
|
2017-11-06 18:03:20 +00:00
|
|
|
};
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto pinAction = _addAction(pinText(), pinToggle);
|
2017-11-06 18:03:20 +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::IsPinned
|
2020-09-30 11:59:54 +00:00
|
|
|
) | rpl::map(pinText);
|
|
|
|
SetActionText(pinAction, std::move(actionText));
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addInfo() {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
const auto peer = _peer;
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = (peer->isChat() || peer->isMegagroup())
|
|
|
|
? tr::lng_context_view_group(tr::now)
|
2017-11-07 11:53:05 +00:00
|
|
|
: (peer->isUser()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_view_profile(tr::now)
|
|
|
|
: tr::lng_context_view_channel(tr::now));
|
|
|
|
_addAction(text, [=] {
|
2017-11-07 11:53:05 +00:00
|
|
|
controller->showPeerInfo(peer);
|
2017-11-06 18:03:20 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-25 08:36:31 +00:00
|
|
|
//void Filler::addSearch() {
|
2020-06-11 16:33:15 +00:00
|
|
|
// const auto controller = _controller;
|
|
|
|
// const auto peer = _peer;
|
|
|
|
// _addAction(tr::lng_profile_search_messages(tr::now), [=] {
|
|
|
|
// controller->content()->searchInChat(peer->owner().history(peer));
|
2019-04-25 08:36:31 +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;
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
|
|
|
const auto label = [=] {
|
2020-09-17 14:56:01 +00:00
|
|
|
return IsUnreadHistory(history)
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_context_mark_read(tr::now)
|
|
|
|
: tr::lng_context_mark_unread(tr::now);
|
2018-06-26 18:03:45 +00:00
|
|
|
};
|
2020-06-12 12:12:34 +00:00
|
|
|
auto action = _addAction(label(), [=] {
|
2020-09-17 14:56:01 +00:00
|
|
|
const auto markAsRead = IsUnreadHistory(history);
|
2018-06-26 18:03:45 +00:00
|
|
|
if (markAsRead) {
|
2020-09-17 14:56:01 +00:00
|
|
|
MarkAsReadHistory(history);
|
|
|
|
} else {
|
|
|
|
peer->owner().histories().changeDialogUnreadMark(
|
|
|
|
history,
|
|
|
|
!markAsRead);
|
2018-06-26 18:03:45 +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::UnreadView
|
2020-09-30 11:59:54 +00:00
|
|
|
) | rpl::map(label);
|
|
|
|
SetActionText(action, std::move(actionText));
|
2018-06-26 18:03:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
void Filler::addToggleArchive() {
|
|
|
|
const auto peer = _peer;
|
2020-06-12 12:12:34 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
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
|
|
|
};
|
2020-09-30 11:59:54 +00:00
|
|
|
const auto archiveAction = _addAction(label(), toggle);
|
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
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::addBlockUser(not_null<UserData*> user) {
|
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));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addUserActions(not_null<UserData*> user) {
|
2019-07-25 18:55:11 +00:00
|
|
|
const auto controller = _controller;
|
2019-09-03 15:24:51 +00:00
|
|
|
const auto window = &_controller->window();
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (user->session().supportMode()) {
|
2018-11-20 15:36:36 +00:00
|
|
|
_addAction("Edit support info", [=] {
|
2020-06-10 18:08:17 +00:00
|
|
|
user->session().supportHelper().editInfo(controller, user);
|
2018-11-20 15:36:36 +00:00
|
|
|
});
|
|
|
|
}
|
2019-06-10 14:58:45 +00:00
|
|
|
if (!user->isContact() && !user->isSelf() && !user->isBot()) {
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_info_add_as_contact(tr::now),
|
2020-06-23 17:21:58 +00:00
|
|
|
[=] { window->show(Box(EditContactBox, controller, user)); });
|
2019-06-10 14:58:45 +00:00
|
|
|
}
|
|
|
|
if (user->canShareThisContact()) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_info_share_contact(tr::now),
|
2019-07-25 18:55:11 +00:00
|
|
|
[=] { PeerMenuShareContactBox(controller, user); });
|
2019-06-10 14:58:45 +00:00
|
|
|
}
|
|
|
|
if (user->isContact() && !user->isSelf()) {
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_info_edit_contact(tr::now),
|
2020-06-23 17:21:58 +00:00
|
|
|
[=] { window->show(Box(EditContactBox, controller, user)); });
|
2019-06-10 14:58:45 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_info_delete_contact(tr::now),
|
2019-06-10 14:58:45 +00:00
|
|
|
[=] { PeerMenuDeleteContact(user); });
|
|
|
|
}
|
2020-09-15 06:58:24 +00:00
|
|
|
if (user->isBot()
|
|
|
|
&& !user->isRepliesChat()
|
|
|
|
&& !user->botInfo->cantJoinGroups) {
|
2019-07-25 18:55:11 +00:00
|
|
|
using AddBotToGroup = AddBotToGroupBoxController;
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_invite_to_group(tr::now),
|
2020-12-21 19:43:23 +00:00
|
|
|
[=] { AddBotToGroup::Start(user); });
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2020-08-03 09:02:41 +00:00
|
|
|
addPollAction(user);
|
2021-09-30 11:30:29 +00:00
|
|
|
if (!user->isBot() && _request.section == Section::History) {
|
2021-09-24 15:10:25 +00:00
|
|
|
_addAction(
|
|
|
|
tr::lng_chat_theme_change(tr::now),
|
|
|
|
[=] { controller->toggleChooseChatTheme(user); });
|
|
|
|
}
|
2019-03-21 18:14:48 +00:00
|
|
|
if (user->canExportChatHistory()) {
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_export_chat(tr::now),
|
2019-03-21 18:14:48 +00:00
|
|
|
[=] { PeerMenuExportChat(user); });
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_delete_conversation(tr::now),
|
2017-11-06 18:03:20 +00:00
|
|
|
DeleteAndLeaveHandler(user));
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_clear_history(tr::now),
|
2017-11-06 18:03:20 +00:00
|
|
|
ClearHistoryHandler(user));
|
2019-04-25 08:36:31 +00:00
|
|
|
if (!user->isInaccessible()
|
2019-07-24 11:13:51 +00:00
|
|
|
&& user != user->session().user()
|
2020-09-15 06:58:24 +00:00
|
|
|
&& !user->isRepliesChat()
|
2020-11-12 15:46:17 +00:00
|
|
|
&& _request.section != Section::ChatsList) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addBlockUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addChatActions(not_null<ChatData*> chat) {
|
2021-06-24 13:25:10 +00:00
|
|
|
const auto navigation = _controller;
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2019-03-17 10:06:00 +00:00
|
|
|
if (EditPeerInfoBox::Available(chat)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = tr::lng_manage_group_title(tr::now);
|
2019-01-07 12:55:49 +00:00
|
|
|
_addAction(text, [=] {
|
2021-06-24 13:25:10 +00:00
|
|
|
navigation->showEditPeerBox(chat);
|
2019-01-07 12:55:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (chat->canAddMembers()) {
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2020-12-22 14:23:10 +00:00
|
|
|
tr::lng_channel_add_members(tr::now),
|
2021-06-24 13:25:10 +00:00
|
|
|
[=] { AddChatMembers(navigation, chat); });
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2020-08-03 09:02:41 +00:00
|
|
|
addPollAction(chat);
|
2019-03-21 18:14:48 +00:00
|
|
|
if (chat->canExportChatHistory()) {
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_export_chat(tr::now),
|
2019-03-21 18:14:48 +00:00
|
|
|
[=] { PeerMenuExportChat(chat); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_clear_and_exit(tr::now),
|
2017-11-06 18:03:20 +00:00
|
|
|
DeleteAndLeaveHandler(_peer));
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_clear_history(tr::now),
|
2017-11-06 18:03:20 +00:00
|
|
|
ClearHistoryHandler(_peer));
|
2021-06-24 13:25:10 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
|
|
|
if (!chat->amCreator()) {
|
|
|
|
_addAction(tr::lng_profile_report(tr::now), [=] {
|
|
|
|
HistoryView::ShowReportPeerBox(navigation, chat);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Filler::addChannelActions(not_null<ChannelData*> channel) {
|
2019-07-25 18:55:11 +00:00
|
|
|
const auto isGroup = channel->isMegagroup();
|
|
|
|
const auto navigation = _controller;
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2020-09-03 11:53:54 +00:00
|
|
|
if (channel->isBroadcast()) {
|
|
|
|
if (const auto chat = channel->linkedChat()) {
|
|
|
|
_addAction(tr::lng_profile_view_discussion(tr::now), [=] {
|
2021-02-23 13:16:29 +00:00
|
|
|
if (channel->invitePeekExpires()) {
|
|
|
|
Ui::Toast::Show(
|
|
|
|
tr::lng_channel_invite_private(tr::now));
|
|
|
|
return;
|
|
|
|
}
|
2020-09-03 11:53:54 +00:00
|
|
|
navigation->showPeerHistory(
|
|
|
|
chat,
|
|
|
|
Window::SectionShow::Way::Forward);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 10:06:00 +00:00
|
|
|
if (EditPeerInfoBox::Available(channel)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = isGroup
|
|
|
|
? tr::lng_manage_group_title(tr::now)
|
|
|
|
: tr::lng_manage_channel_title(tr::now);
|
2019-06-06 10:21:40 +00:00
|
|
|
_addAction(text, [=] {
|
2020-09-03 11:53:54 +00:00
|
|
|
navigation->showEditPeerBox(channel);
|
2017-11-08 16:45:30 +00:00
|
|
|
});
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
if (channel->canAddMembers()) {
|
|
|
|
_addAction(
|
2020-12-22 14:23:10 +00:00
|
|
|
(channel->isMegagroup()
|
|
|
|
? tr::lng_channel_add_members(tr::now)
|
|
|
|
: tr::lng_channel_add_users(tr::now)),
|
2019-07-25 18:55:11 +00:00
|
|
|
[=] { PeerMenuAddChannelMembers(navigation, channel); });
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2020-08-03 09:02:41 +00:00
|
|
|
addPollAction(channel);
|
2019-03-21 18:14:48 +00:00
|
|
|
if (channel->canExportChatHistory()) {
|
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(isGroup
|
|
|
|
? tr::lng_profile_export_chat(tr::now)
|
|
|
|
: tr::lng_profile_export_channel(tr::now)),
|
2019-03-21 18:14:48 +00:00
|
|
|
[=] { PeerMenuExportChat(channel); });
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
2017-11-07 11:53:05 +00:00
|
|
|
if (channel->amIn()) {
|
2021-02-19 10:18:13 +00:00
|
|
|
auto text = isGroup
|
|
|
|
? tr::lng_profile_leave_group(tr::now)
|
|
|
|
: tr::lng_profile_leave_channel(tr::now);
|
|
|
|
_addAction(text, DeleteAndLeaveHandler(channel));
|
2021-02-15 10:57:07 +00:00
|
|
|
if ((isGroup && !channel->isPublic())
|
|
|
|
|| channel->canDeleteMessages()) {
|
2017-11-21 16:38:17 +00:00
|
|
|
_addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_profile_clear_history(tr::now),
|
2017-11-21 16:38:17 +00:00
|
|
|
ClearHistoryHandler(channel));
|
|
|
|
}
|
2017-11-07 13:13:41 +00:00
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
auto text = isGroup
|
|
|
|
? tr::lng_profile_join_group(tr::now)
|
|
|
|
: tr::lng_profile_join_channel(tr::now);
|
2017-11-07 13:13:41 +00:00
|
|
|
_addAction(
|
2017-11-21 16:38:17 +00:00
|
|
|
text,
|
2019-07-24 11:13:51 +00:00
|
|
|
[=] { channel->session().api().joinChannel(channel); });
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::ChatsList) {
|
2021-06-24 13:25:10 +00:00
|
|
|
if (!channel->amCreator()) {
|
2021-02-15 17:37:22 +00:00
|
|
|
_addAction(tr::lng_profile_report(tr::now), [=] {
|
|
|
|
HistoryView::ShowReportPeerBox(navigation, channel);
|
2017-11-07 11:53:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2020-08-03 09:02:41 +00:00
|
|
|
void Filler::addPollAction(not_null<PeerData*> peer) {
|
|
|
|
if (!peer->canSendPolls()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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();
|
2020-11-13 17:27:08 +00:00
|
|
|
const auto replyToId = _request.currentReplyToId
|
|
|
|
? _request.currentReplyToId
|
|
|
|
: _request.rootId;
|
2020-08-03 09:02:41 +00:00
|
|
|
auto callback = [=] {
|
2020-11-11 20:47:40 +00:00
|
|
|
PeerMenuCreatePoll(
|
|
|
|
controller,
|
|
|
|
peer,
|
|
|
|
replyToId,
|
|
|
|
flag,
|
|
|
|
flag,
|
2020-11-20 17:04:50 +00:00
|
|
|
source,
|
|
|
|
sendMenuType);
|
2020-08-03 09:02:41 +00:00
|
|
|
};
|
|
|
|
_addAction(tr::lng_polls_create(tr::now), std::move(callback));
|
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
void Filler::fill() {
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_folder) {
|
|
|
|
addTogglesForArchive();
|
|
|
|
return;
|
|
|
|
} else if (_request.section == Section::Scheduled
|
|
|
|
|| _request.section == Section::Replies) {
|
2020-08-03 09:02:41 +00:00
|
|
|
addPollAction(_peer);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 10:42:24 +00:00
|
|
|
if (showHidePromotion()) {
|
|
|
|
addHidePromotion();
|
|
|
|
}
|
2019-05-01 13:10:11 +00:00
|
|
|
if (showToggleArchived()) {
|
|
|
|
addToggleArchive();
|
|
|
|
}
|
|
|
|
if (showTogglePin()) {
|
|
|
|
addTogglePin();
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
2017-11-07 15:12:54 +00:00
|
|
|
if (showInfo()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addInfo();
|
|
|
|
}
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section != Section::Profile && !_peer->isSelf()) {
|
2018-02-12 11:10:40 +00:00
|
|
|
PeerMenuAddMuteAction(_peer, _addAction);
|
2017-11-07 15:12:54 +00:00
|
|
|
}
|
2020-11-12 15:46:17 +00:00
|
|
|
if (_request.section == Section::ChatsList) {
|
2019-04-25 08:36:31 +00:00
|
|
|
//addSearch();
|
2018-06-26 18:03:45 +00:00
|
|
|
addToggleUnreadMark();
|
2017-11-06 18:03:20 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 16:11:00 +00:00
|
|
|
if (const auto user = _peer->asUser()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addUserActions(user);
|
2018-02-13 16:11:00 +00:00
|
|
|
} else if (const auto chat = _peer->asChat()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addChatActions(chat);
|
2018-02-13 16:11:00 +00:00
|
|
|
} else if (const auto channel = _peer->asChannel()) {
|
2017-11-06 18:03:20 +00:00
|
|
|
addChannelActions(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 15:46:17 +00:00
|
|
|
void Filler::addTogglesForArchive() {
|
|
|
|
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();
|
|
|
|
});
|
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), [=] {
|
2020-04-29 14:52:40 +00:00
|
|
|
Ui::Toast::Show(Ui::Toast::Config{
|
|
|
|
.text = { tr::lng_context_archive_to_menu_info(tr::now) },
|
|
|
|
.st = &st::windowArchiveToast,
|
|
|
|
.durationMs = kArchivedToastDuration,
|
|
|
|
.multiline = true,
|
|
|
|
});
|
2019-05-16 08:39:45 +00:00
|
|
|
|
|
|
|
controller->session().settings().setArchiveInMainMenu(
|
|
|
|
!controller->session().settings().archiveInMainMenu());
|
|
|
|
controller->session().saveSettingsDelayed();
|
|
|
|
});
|
2020-09-16 14:09:04 +00:00
|
|
|
|
|
|
|
MenuAddMarkAsReadChatListAction(
|
|
|
|
[folder = _folder] { return folder->chatsList(); },
|
|
|
|
_addAction);
|
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
|
|
|
}
|
|
|
|
|
2017-11-07 13:13:41 +00:00
|
|
|
void PeerMenuDeleteContact(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,
|
2019-09-13 06:06:02 +00:00
|
|
|
user->name);
|
2019-03-21 12:07:32 +00:00
|
|
|
const auto deleteSure = [=] {
|
2017-11-07 13:13:41 +00:00
|
|
|
Ui::hideLayer();
|
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
|
|
|
};
|
2019-03-21 12:07:32 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2017-11-07 13:13:41 +00:00
|
|
|
text,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_box_delete(tr::now),
|
2019-03-21 12:07:32 +00:00
|
|
|
deleteSure));
|
2017-11-07 13:13:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
void PeerMenuShareContactBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<UserData*> user) {
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<PeerListBox>>();
|
|
|
|
auto callback = [=](not_null<PeerData*> peer) {
|
2017-11-07 13:13:41 +00:00
|
|
|
if (!peer->canWrite()) {
|
|
|
|
Ui::show(Box<InformBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_forward_share_cant(tr::now)),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2017-11-07 13:13:41 +00:00
|
|
|
return;
|
2017-12-07 08:56:10 +00:00
|
|
|
} else if (peer->isSelf()) {
|
2019-08-12 12:11:34 +00:00
|
|
|
auto action = Api::SendAction(peer->owner().history(peer));
|
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);
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(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
|
|
|
}
|
|
|
|
auto recipient = peer->isUser()
|
|
|
|
? peer->name
|
|
|
|
: '\xAB' + peer->name + '\xBB';
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_forward_share_contact(tr::now, lt_recipient, recipient),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_forward_send(tr::now),
|
2021-05-26 21:55:40 +00:00
|
|
|
[peer, user, navigation] {
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
2021-05-26 21:55:40 +00:00
|
|
|
navigation->showPeerHistory(
|
|
|
|
history,
|
|
|
|
Window::SectionShow::Way::ClearStack,
|
|
|
|
ShowAtTheEndMsgId);
|
2019-08-12 12:11:34 +00:00
|
|
|
auto action = Api::SendAction(history);
|
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);
|
2019-09-18 11:19:05 +00:00
|
|
|
}), Ui::LayerOption::KeepOther);
|
2017-11-07 13:13:41 +00:00
|
|
|
};
|
2017-12-07 13:02:24 +00:00
|
|
|
*weak = Ui::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(),
|
2019-07-25 18:55:11 +00:00
|
|
|
std::move(callback)),
|
2017-11-07 13:13:41 +00:00
|
|
|
[](not_null<PeerListBox*> box) {
|
2019-07-25 18:55:11 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [=] {
|
2017-11-07 13:13:41 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
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,
|
2020-11-11 20:47:40 +00:00
|
|
|
MsgId replyToId,
|
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;
|
|
|
|
}
|
2019-08-20 13:21:10 +00:00
|
|
|
const auto box = Ui::show(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,
|
|
|
|
sendMenuType));
|
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;
|
|
|
|
}
|
2019-08-12 12:11:34 +00:00
|
|
|
auto action = Api::SendAction(peer->owner().history(peer));
|
2019-08-30 10:17:18 +00:00
|
|
|
action.clearDraft = false;
|
2019-08-20 13:21:10 +00:00
|
|
|
action.options = result.options;
|
2020-11-11 20:47:40 +00:00
|
|
|
action.replyTo = replyToId;
|
2019-08-12 12:11:34 +00:00
|
|
|
if (const auto localDraft = action.history->localDraft()) {
|
|
|
|
action.clearDraft = localDraft->textWithTags.text.isEmpty();
|
2019-02-17 11:43:46 +00:00
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto api = &peer->session().api();
|
2019-08-20 13:21:10 +00:00
|
|
|
api->createPoll(result.poll, action, crl::guard(box, [=] {
|
2018-12-20 16:02:44 +00:00
|
|
|
box->closeBox();
|
2021-03-12 12:48:00 +00:00
|
|
|
}), crl::guard(box, [=](const MTP::Error &error) {
|
2018-12-23 16:47:00 +00:00
|
|
|
*lock = false;
|
2019-06-19 15:09:03 +00:00
|
|
|
box->submitFailed(tr::lng_attach_failed(tr::now));
|
2018-12-20 16:02:44 +00:00
|
|
|
}));
|
|
|
|
}, box->lifetime());
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
const auto name = user ? user->shortName() : peer->name;
|
|
|
|
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,
|
|
|
|
tr::lng_delete_all_from(tr::now),
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Ui::Toast::Show(
|
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) {
|
2021-08-01 22:57:36 +00:00
|
|
|
user->session().api().blockedPeers().unblock(user, [=] {
|
2019-07-04 14:02:22 +00:00
|
|
|
if (user->isBot() && !user->isSupport()) {
|
|
|
|
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(),
|
|
|
|
item->senderOriginal(),
|
|
|
|
true,
|
|
|
|
Window::ClearReply{ id });
|
|
|
|
}
|
|
|
|
|
2017-12-09 15:13:06 +00:00
|
|
|
QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2021-08-31 16:47:38 +00:00
|
|
|
Data::ForwardDraft &&draft,
|
2018-06-04 15:35:11 +00:00
|
|
|
FnMut<void()> &&successCallback) {
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto weak = std::make_shared<QPointer<PeerListBox>>();
|
2017-12-06 10:13:38 +00:00
|
|
|
auto callback = [
|
2021-08-31 16:47:38 +00:00
|
|
|
draft = std::move(draft),
|
2017-12-06 10:13:38 +00:00
|
|
|
callback = std::move(successCallback),
|
2020-06-10 18:08:17 +00:00
|
|
|
weak,
|
|
|
|
navigation
|
2017-12-06 10:13:38 +00:00
|
|
|
](not_null<PeerData*> peer) mutable {
|
2021-08-31 16:47:38 +00:00
|
|
|
const auto content = navigation->parentController()->content();
|
2017-12-06 10:13:38 +00:00
|
|
|
if (peer->isSelf()) {
|
2021-08-31 16:47:38 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
|
|
|
auto resolved = history->resolveForwardDraft(draft);
|
|
|
|
if (!resolved.items.empty()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto api = &peer->session().api();
|
2019-08-12 12:11:34 +00:00
|
|
|
auto action = Api::SendAction(peer->owner().history(peer));
|
2019-08-30 10:17:18 +00:00
|
|
|
action.clearDraft = false;
|
2019-08-12 12:11:34 +00:00
|
|
|
action.generateLocal = false;
|
2021-08-31 16:47:38 +00:00
|
|
|
api->forwardMessages(std::move(resolved), action, [] {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_share_done(tr::now));
|
2017-12-06 13:56:40 +00:00
|
|
|
});
|
|
|
|
}
|
2021-08-31 16:47:38 +00:00
|
|
|
} else if (!content->setForwardDraft(peer->id, std::move(draft))) {
|
2019-07-18 10:03:09 +00:00
|
|
|
return;
|
2017-12-06 10:13:38 +00:00
|
|
|
}
|
|
|
|
if (const auto strong = *weak) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*weak = Ui::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(),
|
2019-07-25 18:55:11 +00:00
|
|
|
std::move(callback)),
|
2019-09-18 11:19:05 +00:00
|
|
|
std::move(initBox)), Ui::LayerOption::KeepOther);
|
2017-12-09 15:13:06 +00:00
|
|
|
return weak->data();
|
2017-12-06 10:13:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 16:47:38 +00:00
|
|
|
QPointer<Ui::RpWidget> ShowForwardMessagesBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
MessageIdsList &&items,
|
|
|
|
FnMut<void()> &&successCallback) {
|
|
|
|
return ShowForwardMessagesBox(
|
|
|
|
navigation,
|
|
|
|
Data::ForwardDraft{ .ids = std::move(items) },
|
|
|
|
std::move(successCallback));
|
|
|
|
}
|
|
|
|
|
2019-08-09 17:58:58 +00:00
|
|
|
QPointer<Ui::RpWidget> ShowSendNowMessagesBox(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<History*> history,
|
|
|
|
MessageIdsList &&items,
|
|
|
|
FnMut<void()> &&successCallback) {
|
|
|
|
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
|
|
|
|
|
|
|
const auto error = GetErrorTextForSending(
|
|
|
|
history->peer,
|
|
|
|
session->data().idsToItems(items),
|
|
|
|
TextWithTags());
|
|
|
|
if (!error.isEmpty()) {
|
2020-09-30 07:51:17 +00:00
|
|
|
Ui::ShowMultilineToast({
|
2020-04-29 14:52:40 +00:00
|
|
|
.text = { 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)
|
2020-09-24 12:48:02 +00:00
|
|
|
](Fn<void()> &&close) mutable {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
2020-09-24 12:48:02 +00:00
|
|
|
return Ui::show(
|
2019-08-09 17:58:58 +00:00
|
|
|
Box<ConfirmBox>(text, tr::lng_send_button(tr::now), std::move(done)),
|
2020-09-24 12:48:02 +00:00
|
|
|
Ui::LayerOption::KeepOther).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)) {
|
2017-11-19 14:41:52 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<MaxInviteBox>(channel),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2017-11-19 14:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto api = &channel->session().api();
|
2020-06-30 14:26:44 +00:00
|
|
|
api->requestChannelMembersForAdd(channel, crl::guard(navigation, [=](
|
2019-07-24 11:13:51 +00:00
|
|
|
const MTPchannels_ChannelParticipants &result) {
|
|
|
|
api->parseChannelParticipants(channel, result, [&](
|
2017-11-28 18:30:01 +00:00
|
|
|
int availableCount,
|
2017-11-20 19:54:05 +00:00
|
|
|
const QVector<MTPChannelParticipant> &list) {
|
|
|
|
auto already = (
|
|
|
|
list
|
2021-03-13 12:12:08 +00:00
|
|
|
) | ranges::views::transform([](const MTPChannelParticipant &p) {
|
2021-03-19 14:01:21 +00:00
|
|
|
return p.match([](const MTPDchannelParticipantBanned &data) {
|
|
|
|
return peerFromMTP(data.vpeer());
|
2021-03-20 14:19:31 +00:00
|
|
|
}, [](const MTPDchannelParticipantLeft &data) {
|
|
|
|
return peerFromMTP(data.vpeer());
|
2021-03-19 14:01:21 +00:00
|
|
|
}, [](const auto &data) {
|
|
|
|
return peerFromUser(data.vuser_id());
|
2019-01-10 11:15:13 +00:00
|
|
|
});
|
2021-03-19 14:01:21 +00:00
|
|
|
}) | ranges::views::transform([&](PeerId participantId) {
|
|
|
|
return peerIsUser(participantId)
|
|
|
|
? channel->owner().userLoaded(
|
|
|
|
peerToUser(participantId))
|
|
|
|
: nullptr;
|
2021-03-13 12:12:08 +00:00
|
|
|
}) | ranges::views::filter([](UserData *user) {
|
2017-11-20 19:54:05 +00:00
|
|
|
return (user != nullptr);
|
2017-11-21 11:59:18 +00:00
|
|
|
}) | ranges::to_vector;
|
2017-11-19 14:41:52 +00:00
|
|
|
|
2017-11-20 19:54:05 +00:00
|
|
|
AddParticipantsBoxController::Start(
|
2019-07-25 18:55:11 +00:00
|
|
|
navigation,
|
2017-11-20 19:54:05 +00:00
|
|
|
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) {
|
|
|
|
Ui::show(Box<PinMessageBox>(item->history()->peer, item->id));
|
|
|
|
} else {
|
|
|
|
const auto peer = item->history()->peer;
|
|
|
|
const auto session = &peer->session();
|
|
|
|
Ui::show(Box<ConfirmBox>(tr::lng_pinned_unpin_sure(tr::now), tr::lng_pinned_unpin(tr::now), crl::guard(session, [=] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
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();
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 07:53:56 +00:00
|
|
|
void HidePinnedBar(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Fn<void()> onHidden) {
|
|
|
|
Ui::show(Box<ConfirmBox>(tr::lng_pinned_hide_all_sure(tr::now), tr::lng_pinned_hide_all_hide(tr::now), crl::guard(navigation, [=] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
auto &session = peer->session();
|
2020-10-22 12:40:33 +00:00
|
|
|
const auto migrated = peer->migrateFrom();
|
|
|
|
const auto top = Data::ResolveTopPinnedId(peer, migrated);
|
|
|
|
const auto universal = !top
|
|
|
|
? int32(0)
|
|
|
|
: (migrated && !top.channel)
|
|
|
|
? (top.msg - ServerMaxMsgId)
|
|
|
|
: top.msg;
|
|
|
|
if (universal) {
|
|
|
|
session.settings().setHiddenPinnedMessageId(peer->id, universal);
|
2020-10-22 07:53:56 +00:00
|
|
|
session.saveSettingsDelayed();
|
|
|
|
if (onHidden) {
|
|
|
|
onHidden();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
session.api().requestFullPeer(peer);
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnpinAllMessages(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<History*> history) {
|
|
|
|
Ui::show(Box<ConfirmBox>(tr::lng_pinned_unpin_all_sure(tr::now), tr::lng_pinned_unpin(tr::now), crl::guard(navigation, [=] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
const auto api = &history->session().api();
|
|
|
|
const auto sendRequest = [=](auto self) -> void {
|
|
|
|
api->request(MTPmessages_UnpinAllMessages(
|
2020-10-30 14:12:04 +00:00
|
|
|
history->peer->input
|
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 {
|
2020-10-30 14:12:04 +00:00
|
|
|
history->unpinAllMessages();
|
2020-10-22 07:53:56 +00:00
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
};
|
|
|
|
sendRequest(sendRequest);
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
2018-02-12 11:10:40 +00:00
|
|
|
void PeerMenuAddMuteAction(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const PeerMenuCallback &addAction) {
|
2019-07-24 11:13:51 +00:00
|
|
|
peer->owner().requestNotifySettings(peer);
|
2020-09-30 11:59:54 +00:00
|
|
|
const auto muteText = [](bool isUnmuted) {
|
|
|
|
return isUnmuted
|
|
|
|
? tr::lng_disable_notifications_from_tray(tr::now)
|
|
|
|
: tr::lng_enable_notifications_from_tray(tr::now);
|
2018-02-12 11:10:40 +00:00
|
|
|
};
|
2018-04-09 17:48:29 +00:00
|
|
|
const auto muteAction = addAction(QString("-"), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (!peer->owner().notifyIsMuted(peer)) {
|
2018-02-12 11:10:40 +00:00
|
|
|
Ui::show(Box<MuteSettingsBox>(peer));
|
|
|
|
} else {
|
2019-07-24 11:13:51 +00:00
|
|
|
peer->owner().updateNotifySettings(peer, 0);
|
2018-02-12 11:10:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-30 11:59:54 +00:00
|
|
|
auto actionText = Info::Profile::NotificationsEnabledValue(
|
2018-04-09 17:48:29 +00:00
|
|
|
peer
|
2020-09-30 11:59:54 +00:00
|
|
|
) | rpl::map(muteText);
|
|
|
|
SetActionText(muteAction, std::move(actionText));
|
2018-02-12 11:10:40 +00:00
|
|
|
}
|
2020-09-16 14:09:04 +00:00
|
|
|
|
2020-09-17 14:56:01 +00:00
|
|
|
void MenuAddMarkAsReadAllChatsAction(
|
2020-09-16 14:09:04 +00:00
|
|
|
not_null<Data::Session*> data,
|
|
|
|
const PeerMenuCallback &addAction) {
|
2020-09-17 14:56:01 +00:00
|
|
|
auto callback = [owner = data] {
|
|
|
|
auto boxCallback = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
|
|
|
|
|
|
|
MarkAsReadChatList(owner->chatsList());
|
|
|
|
if (const auto folder = owner->folderLoaded(Data::Folder::kId)) {
|
|
|
|
MarkAsReadChatList(folder->chatsList());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
tr::lng_context_mark_read_all_sure(tr::now),
|
|
|
|
std::move(boxCallback)));
|
|
|
|
};
|
|
|
|
addAction(
|
|
|
|
tr::lng_context_mark_read_all(tr::now),
|
|
|
|
std::move(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuAddMarkAsReadChatListAction(
|
|
|
|
Fn<not_null<Dialogs::MainList*>()> &&list,
|
|
|
|
const PeerMenuCallback &addAction) {
|
2020-09-16 14:09:04 +00:00
|
|
|
const auto unreadState = list()->unreadState();
|
|
|
|
if (unreadState.empty()) {
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
|
|
|
tr::lng_context_mark_read_sure(tr::now),
|
|
|
|
std::move(boxCallback)));
|
|
|
|
} 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),
|
|
|
|
std::move(callback));
|
|
|
|
}
|
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,
|
|
|
|
.durationMs = (archived
|
|
|
|
? 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
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> ClearHistoryHandler(not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<DeleteMessagesBox>(peer, true),
|
|
|
|
Ui::LayerOption::KeepOther);
|
2017-12-06 14:39:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> DeleteAndLeaveHandler(not_null<PeerData*> peer) {
|
2019-03-21 12:07:32 +00:00
|
|
|
return [=] {
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<DeleteMessagesBox>(peer, false),
|
|
|
|
Ui::LayerOption::KeepOther);
|
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
|
|
|
}
|
|
|
|
|
2017-11-06 18:03:20 +00:00
|
|
|
} // namespace Window
|