2018-09-11 19:00:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "settings/settings_privacy_controllers.h"
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "settings/settings_common.h"
|
2018-09-11 19:00:23 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-01-18 12:27:37 +00:00
|
|
|
#include "data/data_session.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2019-03-19 13:50:36 +00:00
|
|
|
#include "history/admin_log/history_admin_log_item.h"
|
|
|
|
#include "history/view/history_view_element.h"
|
|
|
|
#include "history/view/history_view_message.h"
|
|
|
|
#include "history/history_item_components.h"
|
|
|
|
#include "history/history_message.h"
|
2018-09-11 19:00:23 +00:00
|
|
|
#include "history/history.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2019-03-19 13:50:36 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2019-08-29 08:44:03 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2019-03-19 13:50:36 +00:00
|
|
|
#include "ui/image/image_prepare.h"
|
|
|
|
#include "window/section_widget.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-09-11 19:00:23 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2019-05-21 12:51:24 +00:00
|
|
|
#include "settings/settings_privacy_security.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2019-03-19 13:50:36 +00:00
|
|
|
#include "styles/style_history.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_settings.h"
|
2018-09-11 19:00:23 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kBlockedPerPage = 40;
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
class BlockPeerBoxController
|
2019-04-18 08:28:43 +00:00
|
|
|
: public ChatsListBoxController
|
|
|
|
, private base::Subscriber {
|
2018-09-11 19:00:23 +00:00
|
|
|
public:
|
2020-09-01 06:44:18 +00:00
|
|
|
explicit BlockPeerBoxController(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation);
|
|
|
|
|
|
|
|
Main::Session &session() const override;
|
2018-09-11 19:00:23 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void setBlockPeerCallback(Fn<void(not_null<PeerData*> peer)> callback) {
|
|
|
|
_blockPeerCallback = std::move(callback);
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepareViewHook() override;
|
|
|
|
std::unique_ptr<Row> createRow(not_null<History*> history) override;
|
|
|
|
void updateRowHook(not_null<Row*> row) override {
|
2020-09-01 06:44:18 +00:00
|
|
|
updateIsBlocked(row, row->peer());
|
2018-09-11 19:00:23 +00:00
|
|
|
delegate()->peerListUpdateRow(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-01 06:44:18 +00:00
|
|
|
void updateIsBlocked(not_null<PeerListRow*> row, PeerData *peer) const;
|
2018-09-11 19:00:23 +00:00
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
const not_null<Window::SessionNavigation*> _navigation;
|
2020-09-01 06:44:18 +00:00
|
|
|
Fn<void(not_null<PeerData*> peer)> _blockPeerCallback;
|
2018-09-11 19:00:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
BlockPeerBoxController::BlockPeerBoxController(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation)
|
|
|
|
: ChatsListBoxController(navigation)
|
|
|
|
, _navigation(navigation) {
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
Main::Session &BlockPeerBoxController::session() const {
|
2019-07-25 18:55:11 +00:00
|
|
|
return _navigation->session();
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockPeerBoxController::prepareViewHook() {
|
2019-06-18 15:00:55 +00:00
|
|
|
delegate()->peerListSetTitle(tr::lng_blocked_list_add_title());
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdates(
|
|
|
|
Data::PeerUpdate::Flag::IsBlocked
|
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
2020-09-01 06:44:18 +00:00
|
|
|
if (auto row = delegate()->peerListFindRow(update.peer->id)) {
|
|
|
|
updateIsBlocked(row, update.peer);
|
|
|
|
delegate()->peerListUpdateRow(row);
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
2020-06-12 12:12:34 +00:00
|
|
|
}, lifetime());
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockPeerBoxController::updateIsBlocked(not_null<PeerListRow*> row, PeerData *peer) const {
|
|
|
|
auto blocked = peer->isBlocked();
|
2018-09-11 19:00:23 +00:00
|
|
|
row->setDisabledState(blocked ? PeerListRow::State::DisabledChecked : PeerListRow::State::Active);
|
|
|
|
if (blocked) {
|
2019-06-19 15:09:03 +00:00
|
|
|
row->setCustomStatus(tr::lng_blocked_list_already_blocked(tr::now));
|
2018-09-11 19:00:23 +00:00
|
|
|
} else {
|
|
|
|
row->clearCustomStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockPeerBoxController::rowClicked(not_null<PeerListRow*> row) {
|
|
|
|
_blockPeerCallback(row->peer());
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
auto BlockPeerBoxController::createRow(not_null<History*> history)
|
|
|
|
-> std::unique_ptr<BlockPeerBoxController::Row> {
|
|
|
|
if (!history->peer->isUser()
|
|
|
|
|| history->peer->isServiceUser()
|
|
|
|
|| history->peer->isSelf()) {
|
2018-09-11 19:00:23 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
auto row = std::make_unique<Row>(history);
|
|
|
|
updateIsBlocked(row.get(), history->peer);
|
|
|
|
return row;
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 13:50:36 +00:00
|
|
|
AdminLog::OwnedItem GenerateForwardedItem(
|
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
|
|
|
not_null<History*> history,
|
|
|
|
const QString &text) {
|
|
|
|
Expects(history->peer->isUser());
|
|
|
|
|
|
|
|
using Flag = MTPDmessage::Flag;
|
|
|
|
using FwdFlag = MTPDmessageFwdHeader::Flag;
|
|
|
|
// #TODO common global incrementable id for fake items, like clientMsgId.
|
|
|
|
static auto id = ServerMaxMsgId + (ServerMaxMsgId / 6);
|
|
|
|
const auto flags = Flag::f_from_id | Flag::f_fwd_from;
|
|
|
|
const auto replyTo = 0;
|
|
|
|
const auto viaBotId = 0;
|
|
|
|
const auto item = MTP_message(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(++id),
|
2020-09-01 06:44:18 +00:00
|
|
|
peerToMTP(history->peer->id),
|
|
|
|
peerToMTP(history->peer->id),
|
2019-03-19 13:50:36 +00:00
|
|
|
MTP_messageFwdHeader(
|
|
|
|
MTP_flags(FwdFlag::f_from_id),
|
2020-09-01 06:44:18 +00:00
|
|
|
peerToMTP(history->session().userPeerId()),
|
2019-03-19 13:50:36 +00:00
|
|
|
MTPstring(), // from_name
|
2019-07-10 17:28:33 +00:00
|
|
|
MTP_int(base::unixtime::now()),
|
2019-03-19 13:50:36 +00:00
|
|
|
MTPint(), // channel_post
|
|
|
|
MTPstring(), // post_author
|
|
|
|
MTPPeer(), // saved_from_peer
|
2020-04-24 10:31:28 +00:00
|
|
|
MTPint(), // saved_from_msg_id
|
|
|
|
MTPstring()), // psa_type
|
2019-03-19 13:50:36 +00:00
|
|
|
MTPint(), // via_bot_id
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPMessageReplyHeader(),
|
2019-07-10 17:28:33 +00:00
|
|
|
MTP_int(base::unixtime::now()), // date
|
2019-03-19 13:50:36 +00:00
|
|
|
MTP_string(text),
|
|
|
|
MTPMessageMedia(),
|
|
|
|
MTPReplyMarkup(),
|
2019-07-05 13:38:38 +00:00
|
|
|
MTPVector<MTPMessageEntity>(),
|
2019-03-19 13:50:36 +00:00
|
|
|
MTPint(), // views
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPint(), // forwards
|
|
|
|
MTPMessageReplies(),
|
2019-03-19 13:50:36 +00:00
|
|
|
MTPint(), // edit_date
|
|
|
|
MTPstring(), // post_author
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPlong(), // grouped_id
|
|
|
|
//MTPMessageReactions(),
|
|
|
|
MTPVector<MTPRestrictionReason>()
|
2019-04-25 12:45:15 +00:00
|
|
|
).match([&](const MTPDmessage &data) {
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeMessage(
|
2019-08-09 19:19:23 +00:00
|
|
|
data,
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_fake_history_item);
|
2019-04-25 12:45:15 +00:00
|
|
|
}, [](auto &&) -> not_null<HistoryMessage*> {
|
2019-03-19 13:50:36 +00:00
|
|
|
Unexpected("Type in GenerateForwardedItem.");
|
|
|
|
});
|
|
|
|
|
|
|
|
return AdminLog::OwnedItem(delegate, item);
|
|
|
|
}
|
|
|
|
|
2018-09-11 19:00:23 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
BlockedBoxController::BlockedBoxController(
|
|
|
|
not_null<Window::SessionController*> window)
|
2019-11-27 08:02:56 +00:00
|
|
|
: _window(window)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_window->session().mtp()) {
|
2019-07-24 14:00:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
Main::Session &BlockedBoxController::session() const {
|
|
|
|
return _window->session();
|
|
|
|
}
|
|
|
|
|
2018-09-11 19:00:23 +00:00
|
|
|
void BlockedBoxController::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
delegate()->peerListSetTitle(tr::lng_blocked_list_title());
|
2019-06-19 15:09:03 +00:00
|
|
|
setDescriptionText(tr::lng_contacts_loading(tr::now));
|
2018-09-11 19:00:23 +00:00
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
session().changes().peerUpdates(
|
|
|
|
Data::PeerUpdate::Flag::IsBlocked
|
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
2020-09-01 06:44:18 +00:00
|
|
|
handleBlockedEvent(update.peer);
|
2020-06-12 12:12:34 +00:00
|
|
|
}, lifetime());
|
2018-09-11 19:00:23 +00:00
|
|
|
|
2019-05-24 13:06:17 +00:00
|
|
|
_loadRequestId = -1;
|
2020-09-01 06:44:18 +00:00
|
|
|
_window->session().api().blockedPeersSlice(
|
2019-05-24 13:06:17 +00:00
|
|
|
) | rpl::take(
|
|
|
|
1
|
2020-09-01 06:44:18 +00:00
|
|
|
) | rpl::start_with_next([=](const ApiWrap::BlockedPeersSlice &result) {
|
2019-06-19 15:09:03 +00:00
|
|
|
setDescriptionText(tr::lng_blocked_list_about(tr::now));
|
2019-05-24 13:06:17 +00:00
|
|
|
_loadRequestId = 0;
|
|
|
|
_offset = result.list.size();
|
|
|
|
_allLoaded = (_offset >= result.total);
|
|
|
|
for (const auto item : result.list) {
|
2020-09-01 06:44:18 +00:00
|
|
|
appendRow(item.peer);
|
2019-05-24 13:06:17 +00:00
|
|
|
};
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
loadMoreRows();
|
|
|
|
}, lifetime());
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::loadMoreRows() {
|
|
|
|
if (_loadRequestId || _allLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
_loadRequestId = _api.request(MTPcontacts_GetBlocked(
|
2019-01-18 12:27:37 +00:00
|
|
|
MTP_int(_offset),
|
|
|
|
MTP_int(kBlockedPerPage)
|
|
|
|
)).done([=](const MTPcontacts_Blocked &result) {
|
2018-09-11 19:00:23 +00:00
|
|
|
_loadRequestId = 0;
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
auto handleContactsBlocked = [&](auto &list) {
|
|
|
|
_window->session().data().processUsers(list.vusers());
|
2020-09-01 06:44:18 +00:00
|
|
|
_window->session().data().processChats(list.vchats());
|
2019-07-05 13:38:38 +00:00
|
|
|
return list.vblocked().v;
|
2018-09-11 19:00:23 +00:00
|
|
|
};
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_contacts_blockedSlice: {
|
2020-09-01 06:44:18 +00:00
|
|
|
receivedPeers(handleContactsBlocked(result.c_contacts_blockedSlice()));
|
2018-09-11 19:00:23 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_contacts_blocked: {
|
|
|
|
_allLoaded = true;
|
2020-09-01 06:44:18 +00:00
|
|
|
receivedPeers(handleContactsBlocked(result.c_contacts_blocked()));
|
2018-09-11 19:00:23 +00:00
|
|
|
} break;
|
|
|
|
default: Unexpected("Bad type() in MTPcontacts_GetBlocked() result.");
|
|
|
|
}
|
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_loadRequestId = 0;
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::rowClicked(not_null<PeerListRow*> row) {
|
2020-06-11 16:33:15 +00:00
|
|
|
const auto peer = row->peer();
|
2020-06-18 18:04:16 +00:00
|
|
|
crl::on_main(&peer->session(), [=] {
|
|
|
|
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
2018-09-11 19:00:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::rowActionClicked(not_null<PeerListRow*> row) {
|
2020-09-01 06:44:18 +00:00
|
|
|
_window->session().api().unblockPeer(row->peer());
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockedBoxController::receivedPeers(
|
|
|
|
const QVector<MTPPeerBlocked> &result) {
|
2018-09-11 19:00:23 +00:00
|
|
|
if (result.empty()) {
|
|
|
|
_allLoaded = true;
|
|
|
|
}
|
|
|
|
|
2019-05-24 13:06:17 +00:00
|
|
|
_offset += result.size();
|
|
|
|
for (const auto &item : result) {
|
2020-09-01 06:44:18 +00:00
|
|
|
item.match([&](const MTPDpeerBlocked &data) {
|
|
|
|
if (const auto peer = _window->session().data().peerLoaded(peerFromMTP(data.vpeer_id()))) {
|
|
|
|
appendRow(peer);
|
|
|
|
peer->setIsBlocked(true);
|
2019-05-24 13:06:17 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockedBoxController::handleBlockedEvent(not_null<PeerData*> user) {
|
2018-09-11 19:00:23 +00:00
|
|
|
if (user->isBlocked()) {
|
|
|
|
if (prependRow(user)) {
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
delegate()->peerListScrollToTop();
|
|
|
|
}
|
|
|
|
} else if (auto row = delegate()->peerListFindRow(user->id)) {
|
|
|
|
delegate()->peerListRemoveRow(row);
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void BlockedBoxController::BlockNewPeer(
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Window::SessionController*> window) {
|
2020-09-01 06:44:18 +00:00
|
|
|
auto controller = std::make_unique<BlockPeerBoxController>(window);
|
2019-07-24 14:00:30 +00:00
|
|
|
auto initBox = [=, controller = controller.get()](
|
|
|
|
not_null<PeerListBox*> box) {
|
2020-09-01 06:44:18 +00:00
|
|
|
controller->setBlockPeerCallback([=](not_null<PeerData*> peer) {
|
|
|
|
window->session().api().blockPeer(peer);
|
2018-09-11 19:00:23 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
|
2018-09-11 19:00:23 +00:00
|
|
|
};
|
|
|
|
Ui::show(
|
|
|
|
Box<PeerListBox>(std::move(controller), std::move(initBox)),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
bool BlockedBoxController::appendRow(not_null<PeerData*> peer) {
|
|
|
|
if (delegate()->peerListFindRow(peer->id)) {
|
2018-09-11 19:00:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
delegate()->peerListAppendRow(createRow(peer));
|
2018-09-11 19:00:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
bool BlockedBoxController::prependRow(not_null<PeerData*> peer) {
|
|
|
|
if (delegate()->peerListFindRow(peer->id)) {
|
2018-09-11 19:00:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
delegate()->peerListPrependRow(createRow(peer));
|
2018-09-11 19:00:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:46:07 +00:00
|
|
|
std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
|
2020-09-01 06:44:18 +00:00
|
|
|
not_null<PeerData*> peer) const {
|
|
|
|
auto row = std::make_unique<PeerListRowWithLink>(peer);
|
2019-07-04 14:02:22 +00:00
|
|
|
row->setActionLink(tr::lng_blocked_list_unblock(tr::now));
|
2018-09-20 17:56:45 +00:00
|
|
|
const auto status = [&] {
|
2020-09-01 06:44:18 +00:00
|
|
|
const auto user = peer->asUser();
|
|
|
|
if (!user) {
|
|
|
|
return tr::lng_group_status(tr::now);
|
|
|
|
} else if (!user->phone().isEmpty()) {
|
2018-09-20 17:56:45 +00:00
|
|
|
return App::formatPhone(user->phone());
|
|
|
|
} else if (!user->username.isEmpty()) {
|
|
|
|
return '@' + user->username;
|
2019-07-18 08:51:11 +00:00
|
|
|
} else if (user->isBot()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_status_bot(tr::now);
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_blocked_list_unknown_phone(tr::now);
|
2018-09-20 17:56:45 +00:00
|
|
|
}();
|
|
|
|
row->setCustomStatus(status);
|
2019-11-12 15:15:34 +00:00
|
|
|
return row;
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
ApiWrap::Privacy::Key PhoneNumberPrivacyController::key() {
|
|
|
|
return Key::PhoneNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey PhoneNumberPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyPhoneNumber();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_phone_number_title();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_phone_number_header();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::warning() {
|
2019-08-29 08:44:03 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
return rpl::combine(
|
|
|
|
_phoneNumberOption.value(),
|
|
|
|
_addedByPhone.value(),
|
|
|
|
(_1 == Option::Nobody) && (_2 != Option::Everyone)
|
|
|
|
) | rpl::map([](bool onlyContactsSee) {
|
|
|
|
return onlyContactsSee
|
|
|
|
? tr::lng_edit_privacy_phone_number_contacts()
|
|
|
|
: tr::lng_edit_privacy_phone_number_warning();
|
|
|
|
}) | rpl::flatten_latest();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::exceptionButtonTextKey(
|
2019-05-21 12:51:24 +00:00
|
|
|
Exception exception) {
|
|
|
|
switch (exception) {
|
|
|
|
case Exception::Always:
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_phone_number_always_empty();
|
2019-05-21 12:51:24 +00:00
|
|
|
case Exception::Never:
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_phone_number_never_empty();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2019-05-21 12:51:24 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_phone_number_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_phone_number_never_title();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> PhoneNumberPrivacyController::exceptionsDescription() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_phone_number_exceptions();
|
2019-05-21 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 08:44:03 +00:00
|
|
|
object_ptr<Ui::RpWidget> PhoneNumberPrivacyController::setupMiddleWidget(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
rpl::producer<Option> optionValue) {
|
|
|
|
const auto key = ApiWrap::Privacy::Key::AddedByPhone;
|
|
|
|
controller->session().api().reloadPrivacy(key);
|
|
|
|
|
|
|
|
_phoneNumberOption = std::move(optionValue);
|
|
|
|
|
|
|
|
auto widget = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
parent,
|
|
|
|
object_ptr<Ui::VerticalLayout>(parent));
|
|
|
|
|
|
|
|
const auto container = widget->entity();
|
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
|
|
|
AddSubsectionTitle(container, tr::lng_edit_privacy_phone_number_find());
|
|
|
|
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>();
|
|
|
|
group->setChangedCallback([=](Option value) {
|
|
|
|
_addedByPhone = value;
|
|
|
|
});
|
|
|
|
controller->session().api().privacyValue(
|
|
|
|
key
|
|
|
|
) | rpl::take(
|
|
|
|
1
|
|
|
|
) | rpl::start_with_next([=](const ApiWrap::Privacy &value) {
|
|
|
|
group->setValue(value.option);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
const auto addOption = [&](Option option) {
|
|
|
|
return EditPrivacyBox::AddOption(container, this, group, option);
|
|
|
|
};
|
|
|
|
addOption(Option::Everyone);
|
|
|
|
addOption(Option::Contacts);
|
|
|
|
AddSkip(container);
|
|
|
|
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
widget->toggleOn(_phoneNumberOption.value(
|
|
|
|
) | rpl::map(
|
|
|
|
_1 == Option::Nobody
|
|
|
|
));
|
|
|
|
|
|
|
|
_saveAdditional = [=] {
|
|
|
|
const auto value = [&] {
|
|
|
|
switch (group->value()) {
|
|
|
|
case Option::Everyone: return MTP_inputPrivacyValueAllowAll();
|
|
|
|
default: return MTP_inputPrivacyValueAllowContacts();
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
controller->session().api().savePrivacy(
|
|
|
|
MTP_inputPrivacyKeyAddedByPhone(),
|
|
|
|
QVector<MTPInputPrivacyRule>(1, value));
|
|
|
|
};
|
|
|
|
|
2019-11-12 15:15:34 +00:00
|
|
|
return widget;
|
2019-08-29 08:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhoneNumberPrivacyController::saveAdditional() {
|
|
|
|
if (_saveAdditional) {
|
|
|
|
_saveAdditional();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
LastSeenPrivacyController::LastSeenPrivacyController(
|
|
|
|
not_null<::Main::Session*> session)
|
|
|
|
: _session(session) {
|
|
|
|
}
|
|
|
|
|
2018-09-11 19:00:23 +00:00
|
|
|
ApiWrap::Privacy::Key LastSeenPrivacyController::key() {
|
|
|
|
return Key::LastSeen;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey LastSeenPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyStatusTimestamp();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_lastseen_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_lastseen_header();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::warning() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_lastseen_warning();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::exceptionButtonTextKey(
|
2018-09-19 09:06:21 +00:00
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2018-09-19 09:06:21 +00:00
|
|
|
case Exception::Always:
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_lastseen_always_empty();
|
2018-09-19 09:06:21 +00:00
|
|
|
case Exception::Never:
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_lastseen_never_empty();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_lastseen_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_lastseen_never_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
rpl::producer<QString> LastSeenPrivacyController::exceptionsDescription() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_lastseen_exceptions();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 08:44:03 +00:00
|
|
|
void LastSeenPrivacyController::confirmSave(
|
|
|
|
bool someAreDisallowed,
|
|
|
|
FnMut<void()> saveCallback) {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (someAreDisallowed && !Core::App().settings().lastSeenWarningSeen()) {
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto session = _session;
|
2018-09-11 19:00:23 +00:00
|
|
|
auto weakBox = std::make_shared<QPointer<ConfirmBox>>();
|
2019-07-24 14:00:30 +00:00
|
|
|
auto callback = [=, saveCallback = std::move(saveCallback)]() mutable {
|
2018-09-11 19:00:23 +00:00
|
|
|
if (auto box = *weakBox) {
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
saveCallback();
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setLastSeenWarningSeen(true);
|
|
|
|
Core::App().saveSettingsDelayed();
|
2018-09-11 19:00:23 +00:00
|
|
|
};
|
2019-03-19 10:39:19 +00:00
|
|
|
auto box = Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_edit_privacy_lastseen_warning(tr::now),
|
|
|
|
tr::lng_continue(tr::now),
|
|
|
|
tr::lng_cancel(tr::now),
|
2019-03-19 10:39:19 +00:00
|
|
|
std::move(callback));
|
2019-09-18 11:19:05 +00:00
|
|
|
*weakBox = Ui::show(std::move(box), Ui::LayerOption::KeepOther);
|
2018-09-11 19:00:23 +00:00
|
|
|
} else {
|
|
|
|
saveCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ApiWrap::Privacy::Key GroupsInvitePrivacyController::key() {
|
|
|
|
return Key::Invites;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey GroupsInvitePrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyChatInvite();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> GroupsInvitePrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_groups_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GroupsInvitePrivacyController::hasOption(Option option) {
|
|
|
|
return (option != Option::Nobody);
|
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> GroupsInvitePrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_groups_header();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> GroupsInvitePrivacyController::exceptionButtonTextKey(
|
2018-09-19 09:06:21 +00:00
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2019-06-18 12:16:43 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_groups_always_empty();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_groups_never_empty();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> GroupsInvitePrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_groups_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_groups_never_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
auto GroupsInvitePrivacyController::exceptionsDescription()
|
|
|
|
-> rpl::producer<QString> {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_groups_exceptions();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ApiWrap::Privacy::Key CallsPrivacyController::key() {
|
|
|
|
return Key::Calls;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey CallsPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyPhoneCall();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> CallsPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_calls_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> CallsPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_calls_header();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> CallsPrivacyController::exceptionButtonTextKey(
|
2018-09-19 09:06:21 +00:00
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2019-06-18 12:16:43 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_calls_always_empty();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_calls_never_empty();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> CallsPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2018-09-11 19:00:23 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_calls_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_calls_never_title();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
rpl::producer<QString> CallsPrivacyController::exceptionsDescription() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_calls_exceptions();
|
2018-09-19 09:06:21 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
object_ptr<Ui::RpWidget> CallsPrivacyController::setupBelowWidget(
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2019-05-21 12:51:24 +00:00
|
|
|
not_null<QWidget*> parent) {
|
|
|
|
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
|
|
|
const auto content = result.data();
|
|
|
|
|
|
|
|
AddDivider(content);
|
|
|
|
AddSkip(content);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(content, tr::lng_settings_calls_peer_to_peer_title());
|
2019-05-21 12:51:24 +00:00
|
|
|
Settings::AddPrivacyButton(
|
2019-07-24 14:00:30 +00:00
|
|
|
controller,
|
2019-05-21 12:51:24 +00:00
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_calls_peer_to_peer_button(),
|
2019-05-21 12:51:24 +00:00
|
|
|
ApiWrap::Privacy::Key::CallsPeer2Peer,
|
|
|
|
[] { return std::make_unique<CallsPeer2PeerPrivacyController>(); });
|
|
|
|
AddSkip(content);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-10-24 09:07:54 +00:00
|
|
|
ApiWrap::Privacy::Key CallsPeer2PeerPrivacyController::key() {
|
|
|
|
return Key::CallsPeer2Peer;
|
|
|
|
}
|
2018-09-19 09:06:21 +00:00
|
|
|
|
2018-10-24 09:07:54 +00:00
|
|
|
MTPInputPrivacyKey CallsPeer2PeerPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyPhoneP2P();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_calls_p2p_title();
|
2018-10-24 09:07:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_calls_p2p_header();
|
2018-10-24 09:07:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
QString CallsPeer2PeerPrivacyController::optionLabel(
|
2018-11-16 05:40:42 +00:00
|
|
|
EditPrivacyBox::Option option) {
|
|
|
|
switch (option) {
|
2019-06-19 15:09:03 +00:00
|
|
|
case Option::Everyone: return tr::lng_edit_privacy_calls_p2p_everyone(tr::now);
|
|
|
|
case Option::Contacts: return tr::lng_edit_privacy_calls_p2p_contacts(tr::now);
|
|
|
|
case Option::Nobody: return tr::lng_edit_privacy_calls_p2p_nobody(tr::now);
|
2018-11-16 05:40:42 +00:00
|
|
|
}
|
|
|
|
Unexpected("Option value in optionsLabelKey.");
|
|
|
|
}
|
|
|
|
|
2018-10-24 09:07:54 +00:00
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::warning() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_settings_peer_to_peer_about();
|
2018-10-24 09:07:54 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionButtonTextKey(
|
2018-10-24 09:07:54 +00:00
|
|
|
Exception exception) {
|
|
|
|
switch (exception) {
|
2019-06-18 12:16:43 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_calls_p2p_always_empty();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_calls_p2p_never_empty();
|
2018-10-24 09:07:54 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2018-10-24 09:07:54 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_calls_p2p_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_calls_p2p_never_title();
|
2018-10-24 09:07:54 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionsDescription() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_calls_p2p_exceptions();
|
2018-09-11 19:00:23 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
ForwardsPrivacyController::ForwardsPrivacyController(
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<Window::SessionController*> controller)
|
2020-06-23 17:21:58 +00:00
|
|
|
: SimpleElementDelegate(controller)
|
|
|
|
, _controller(controller) {
|
2019-07-24 14:00:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 10:39:19 +00:00
|
|
|
ApiWrap::Privacy::Key ForwardsPrivacyController::key() {
|
|
|
|
return Key::Forwards;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey ForwardsPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyForwards();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> ForwardsPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_forwards_title();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> ForwardsPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_forwards_header();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> ForwardsPrivacyController::warning() {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_forwards_warning();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> ForwardsPrivacyController::exceptionButtonTextKey(
|
2019-03-19 10:39:19 +00:00
|
|
|
Exception exception) {
|
|
|
|
switch (exception) {
|
2019-06-18 12:16:43 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_forwards_always_empty();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_forwards_never_empty();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> ForwardsPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2019-03-19 10:39:19 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_forwards_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_forwards_never_title();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ForwardsPrivacyController::exceptionsDescription()
|
|
|
|
-> rpl::producer<QString> {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_forwards_exceptions();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 13:50:36 +00:00
|
|
|
object_ptr<Ui::RpWidget> ForwardsPrivacyController::setupAboveWidget(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
rpl::producer<Option> optionValue) {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
auto message = GenerateForwardedItem(
|
|
|
|
delegate(),
|
2020-06-10 18:08:17 +00:00
|
|
|
_controller->session().data().history(
|
2019-03-19 13:50:36 +00:00
|
|
|
peerFromUser(PeerData::kServiceNotificationsId)),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_edit_privacy_forwards_sample_message(tr::now));
|
2019-03-19 13:50:36 +00:00
|
|
|
const auto view = message.get();
|
|
|
|
|
|
|
|
auto result = object_ptr<Ui::RpWidget>(parent);
|
|
|
|
const auto widget = result.data();
|
|
|
|
Ui::AttachAsChild(widget, std::move(message));
|
|
|
|
|
|
|
|
const auto option = widget->lifetime().make_state<Option>();
|
|
|
|
|
|
|
|
const auto padding = st::settingsForwardPrivacyPadding;
|
|
|
|
widget->widthValue(
|
|
|
|
) | rpl::filter(
|
|
|
|
_1 >= (st::historyMinimalWidth / 2)
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
const auto height = view->resizeGetHeight(width);
|
|
|
|
const auto top = view->marginTop();
|
|
|
|
const auto bottom = view->marginBottom();
|
|
|
|
const auto full = padding + bottom + height + top + padding;
|
|
|
|
widget->resize(width, full);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
widget->paintRequest(
|
|
|
|
) | rpl::start_with_next([=](QRect rect) {
|
2020-06-10 18:08:17 +00:00
|
|
|
Window::SectionWidget::PaintBackground(_controller, widget, rect);
|
2019-03-19 13:50:36 +00:00
|
|
|
|
|
|
|
Painter p(widget);
|
|
|
|
p.translate(0, padding + view->marginBottom());
|
|
|
|
view->draw(p, widget->rect(), TextSelection(), crl::now());
|
|
|
|
|
|
|
|
PaintForwardedTooltip(p, view, *option);
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
optionValue
|
|
|
|
) | rpl::start_with_next([=](Option value) {
|
|
|
|
*option = value;
|
|
|
|
widget->update();
|
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForwardsPrivacyController::PaintForwardedTooltip(
|
|
|
|
Painter &p,
|
|
|
|
not_null<HistoryView::Element*> view,
|
|
|
|
Option value) {
|
|
|
|
// This breaks HistoryView::Element encapsulation :(
|
|
|
|
const auto forwarded = view->data()->Get<HistoryMessageForwarded>();
|
|
|
|
const auto availableWidth = view->width()
|
|
|
|
- st::msgMargin.left()
|
|
|
|
- st::msgMargin.right();
|
|
|
|
const auto bubbleWidth = ranges::min({
|
|
|
|
availableWidth,
|
|
|
|
view->maxWidth(),
|
|
|
|
st::msgMaxWidth
|
|
|
|
});
|
|
|
|
const auto innerWidth = bubbleWidth
|
|
|
|
- st::msgPadding.left()
|
|
|
|
- st::msgPadding.right();
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto phrase = tr::lng_forwarded(
|
|
|
|
tr::now,
|
2019-03-19 13:50:36 +00:00
|
|
|
lt_user,
|
2019-09-13 06:06:02 +00:00
|
|
|
view->data()->history()->session().user()->name);
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto kReplacementPosition = QChar(0x0001);
|
|
|
|
const auto possiblePosition = tr::lng_forwarded(
|
|
|
|
tr::now,
|
|
|
|
lt_user,
|
|
|
|
QString(1, kReplacementPosition)
|
|
|
|
).indexOf(kReplacementPosition);
|
2019-03-19 13:50:36 +00:00
|
|
|
const auto position = (possiblePosition >= 0
|
|
|
|
&& possiblePosition < phrase.size())
|
|
|
|
? possiblePosition
|
|
|
|
: 0;
|
|
|
|
const auto before = phrase.mid(0, position);
|
|
|
|
const auto skip = st::msgMargin.left() + st::msgPadding.left();
|
|
|
|
const auto small = forwarded->text.countHeight(innerWidth)
|
|
|
|
< 2 * st::msgServiceFont->height;
|
|
|
|
const auto nameLeft = skip + (small ? st::msgServiceFont->width(before) : 0);
|
|
|
|
const auto right = skip + innerWidth;
|
2019-06-19 15:09:03 +00:00
|
|
|
const auto text = [&] {
|
2019-03-19 13:50:36 +00:00
|
|
|
switch (value) {
|
|
|
|
case Option::Everyone:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_edit_privacy_forwards_sample_everyone(tr::now);
|
2019-03-19 13:50:36 +00:00
|
|
|
case Option::Contacts:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_edit_privacy_forwards_sample_contacts(tr::now);
|
2019-03-19 13:50:36 +00:00
|
|
|
case Option::Nobody:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_edit_privacy_forwards_sample_nobody(tr::now);
|
2019-03-19 13:50:36 +00:00
|
|
|
}
|
|
|
|
Unexpected("Option value in ForwardsPrivacyController.");
|
|
|
|
}();
|
2020-04-29 14:52:40 +00:00
|
|
|
const auto &font = st::defaultToast.style.font;
|
2019-03-19 13:50:36 +00:00
|
|
|
const auto textWidth = font->width(text);
|
|
|
|
const auto arrowSkip = st::settingsForwardPrivacyArrowSkip;
|
|
|
|
const auto arrowSize = st::settingsForwardPrivacyArrowSize;
|
|
|
|
const auto fullWidth = std::max(textWidth, 2 * arrowSkip);
|
|
|
|
const auto padding = st::settingsForwardPrivacyTooltipPadding;
|
|
|
|
const auto rect = QRect(0, 0, textWidth, font->height).marginsAdded(
|
|
|
|
padding
|
|
|
|
).translated(padding.left(), padding.top());
|
|
|
|
|
|
|
|
const auto top = view->marginTop()
|
|
|
|
+ st::msgPadding.top()
|
|
|
|
+ (small ? 1 : 2) * st::msgServiceFont->height
|
|
|
|
+ arrowSize;
|
|
|
|
const auto left1 = std::min(nameLeft, right - rect.width());
|
|
|
|
const auto left2 = std::max(left1, skip);
|
|
|
|
const auto left = left2;
|
|
|
|
const auto arrowLeft1 = nameLeft + arrowSkip;
|
|
|
|
const auto arrowLeft2 = std::min(
|
|
|
|
arrowLeft1,
|
|
|
|
std::max((left + right) / 2, right - arrowSkip));
|
|
|
|
const auto arrowLeft = arrowLeft2;
|
|
|
|
const auto geometry = rect.translated(left, top);
|
|
|
|
|
|
|
|
App::roundRect(p, geometry, st::toastBg, ImageRoundRadius::Small);
|
|
|
|
|
|
|
|
p.setFont(font);
|
|
|
|
p.setPen(st::toastFg);
|
|
|
|
p.drawText(
|
|
|
|
geometry.x() + padding.left(),
|
|
|
|
geometry.y() + padding.top() + font->ascent,
|
|
|
|
text);
|
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(arrowLeft - arrowSize, top);
|
|
|
|
path.lineTo(arrowLeft, top - arrowSize);
|
|
|
|
path.lineTo(arrowLeft + arrowSize, top);
|
|
|
|
path.lineTo(arrowLeft - arrowSize, top);
|
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.fillPath(path, st::toastBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ForwardsPrivacyController::delegate()
|
|
|
|
-> not_null<HistoryView::ElementDelegate*> {
|
|
|
|
return static_cast<HistoryView::ElementDelegate*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryView::Context ForwardsPrivacyController::elementContext() {
|
|
|
|
return HistoryView::Context::ContactPreview;
|
|
|
|
}
|
|
|
|
|
2019-03-19 10:39:19 +00:00
|
|
|
ApiWrap::Privacy::Key ProfilePhotoPrivacyController::key() {
|
|
|
|
return Key::ProfilePhoto;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputPrivacyKey ProfilePhotoPrivacyController::apiKey() {
|
|
|
|
return MTP_inputPrivacyKeyProfilePhoto();
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> ProfilePhotoPrivacyController::title() {
|
|
|
|
return tr::lng_edit_privacy_profile_photo_title();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 07:11:13 +00:00
|
|
|
bool ProfilePhotoPrivacyController::hasOption(Option option) {
|
|
|
|
return (option != Option::Nobody);
|
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> ProfilePhotoPrivacyController::optionsTitleKey() {
|
|
|
|
return tr::lng_edit_privacy_profile_photo_header();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> ProfilePhotoPrivacyController::exceptionButtonTextKey(
|
2019-03-19 10:39:19 +00:00
|
|
|
Exception exception) {
|
|
|
|
switch (exception) {
|
2019-06-18 12:16:43 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_profile_photo_always_empty();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_profile_photo_never_empty();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> ProfilePhotoPrivacyController::exceptionBoxTitle(
|
|
|
|
Exception exception) {
|
2019-03-19 10:39:19 +00:00
|
|
|
switch (exception) {
|
2019-06-18 15:00:55 +00:00
|
|
|
case Exception::Always: return tr::lng_edit_privacy_profile_photo_always_title();
|
|
|
|
case Exception::Never: return tr::lng_edit_privacy_profile_photo_never_title();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ProfilePhotoPrivacyController::exceptionsDescription()
|
|
|
|
-> rpl::producer<QString> {
|
2019-06-18 12:16:43 +00:00
|
|
|
return tr::lng_edit_privacy_profile_photo_exceptions();
|
2019-03-19 10:39:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 19:00:23 +00:00
|
|
|
} // namespace Settings
|