2018-09-05 19:05:49 +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_information.h"
|
|
|
|
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "ui/wrap/vertical_layout_reorder.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2023-08-31 11:21:24 +00:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
2018-09-13 20:09:26 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/widgets/box_content_divider.h"
|
2022-06-03 16:07:33 +00:00
|
|
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2022-12-19 11:48:24 +00:00
|
|
|
#include "ui/controls/userpic_button.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2023-02-03 15:32:25 +00:00
|
|
|
#include "ui/delayed_activation.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2023-11-14 19:12:53 +00:00
|
|
|
#include "ui/vertical_list.h"
|
2022-12-19 11:48:24 +00:00
|
|
|
#include "ui/unread_badge_paint.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "chat_helpers/emoji_suggestions_widget.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
2022-05-30 14:30:51 +00:00
|
|
|
#include "boxes/premium_limits_box.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "boxes/username_box.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "data/data_peer_values.h"
|
|
|
|
#include "data/data_changes.h"
|
2022-06-15 22:24:10 +00:00
|
|
|
#include "data/data_premium_limits.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2022-09-06 16:53:42 +00:00
|
|
|
#include "info/profile/info_profile_badge.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "main/main_account.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "main/main_domain.h"
|
|
|
|
#include "mtproto/mtproto_dc_options.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2022-04-13 08:05:10 +00:00
|
|
|
#include "window/window_controller.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2018-09-09 17:38:08 +00:00
|
|
|
#include "apiwrap.h"
|
2021-10-20 16:54:22 +00:00
|
|
|
#include "api/api_peer_photo.h"
|
2022-10-12 18:16:04 +00:00
|
|
|
#include "api/api_user_names.h"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.h"
|
2023-01-17 15:47:58 +00:00
|
|
|
#include "base/options.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "base/unixtime.h"
|
2022-03-15 13:00:17 +00:00
|
|
|
#include "base/random.h"
|
2023-02-03 15:32:25 +00:00
|
|
|
#include "styles/style_chat.h" // popupMenuExpandedSeparator
|
2022-06-14 04:03:18 +00:00
|
|
|
#include "styles/style_dialogs.h" // dialogsPremiumIcon
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "styles/style_settings.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2022-12-19 11:48:24 +00:00
|
|
|
#include "styles/style_window.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
2022-03-15 13:00:17 +00:00
|
|
|
#include <QtCore/QBuffer>
|
2019-09-04 07:19:15 +00:00
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
namespace Settings {
|
2018-09-09 17:38:08 +00:00
|
|
|
namespace {
|
|
|
|
|
2018-09-18 16:32:07 +00:00
|
|
|
constexpr auto kSaveBioTimeout = 1000;
|
2022-08-31 14:37:31 +00:00
|
|
|
constexpr auto kPlayStatusLimit = 2;
|
2018-09-18 16:32:07 +00:00
|
|
|
|
2022-06-14 04:03:18 +00:00
|
|
|
class ComposedBadge final : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
ComposedBadge(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
not_null<Ui::SettingsButton*> button,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
rpl::producer<QString> &&text,
|
2022-08-11 17:22:21 +00:00
|
|
|
bool hasUnread,
|
|
|
|
Fn<bool()> animationPaused);
|
2022-06-14 04:03:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
rpl::variable<QString> _text;
|
|
|
|
rpl::event_stream<int> _unreadWidth;
|
|
|
|
rpl::event_stream<int> _premiumWidth;
|
|
|
|
|
|
|
|
QPointer<Ui::RpWidget> _unread;
|
2022-09-06 16:53:42 +00:00
|
|
|
Info::Profile::Badge _badge;
|
2022-06-14 04:03:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
ComposedBadge::ComposedBadge(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
not_null<Ui::SettingsButton*> button,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
rpl::producer<QString> &&text,
|
2022-08-11 17:22:21 +00:00
|
|
|
bool hasUnread,
|
|
|
|
Fn<bool()> animationPaused)
|
2022-06-14 04:03:18 +00:00
|
|
|
: Ui::RpWidget(parent)
|
2022-08-11 17:22:21 +00:00
|
|
|
, _text(std::move(text))
|
|
|
|
, _badge(
|
|
|
|
this,
|
|
|
|
st::settingsInfoPeerBadge,
|
|
|
|
session->user(),
|
2022-09-06 16:53:42 +00:00
|
|
|
nullptr,
|
2022-08-11 17:22:21 +00:00
|
|
|
std::move(animationPaused),
|
2022-08-31 14:37:31 +00:00
|
|
|
kPlayStatusLimit,
|
2022-09-06 16:53:42 +00:00
|
|
|
Info::Profile::BadgeType::Premium) {
|
2022-06-14 04:03:18 +00:00
|
|
|
if (hasUnread) {
|
|
|
|
_unread = CreateUnread(this, rpl::single(
|
|
|
|
rpl::empty
|
|
|
|
) | rpl::then(
|
|
|
|
session->data().unreadBadgeChanges()
|
|
|
|
) | rpl::map([=] {
|
|
|
|
auto &owner = session->data();
|
|
|
|
return Badge::UnreadBadge{
|
|
|
|
owner.unreadBadge(),
|
|
|
|
owner.unreadBadgeMuted(),
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
rpl::combine(
|
|
|
|
_unread->shownValue(),
|
|
|
|
_unread->widthValue()
|
|
|
|
) | rpl::map([=](bool shown, int width) {
|
|
|
|
return shown ? width : 0;
|
|
|
|
}) | rpl::start_to_stream(_unreadWidth, _unread->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-08-11 17:22:21 +00:00
|
|
|
_badge.updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (const auto button = _badge.widget()) {
|
|
|
|
button->widthValue(
|
|
|
|
) | rpl::start_to_stream(_premiumWidth, button->lifetime());
|
|
|
|
} else {
|
2022-06-14 04:03:18 +00:00
|
|
|
_premiumWidth.fire(0);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2022-10-14 08:01:53 +00:00
|
|
|
auto textWidth = _text.value() | rpl::map([=] {
|
|
|
|
return button->fullTextWidth();
|
|
|
|
});
|
2022-06-14 04:03:18 +00:00
|
|
|
rpl::combine(
|
|
|
|
_unreadWidth.events_starting_with(_unread ? _unread->width() : 0),
|
2022-09-12 14:56:03 +00:00
|
|
|
_premiumWidth.events_starting_with(_badge.widget()
|
|
|
|
? _badge.widget()->width()
|
|
|
|
: 0),
|
2022-10-14 08:01:53 +00:00
|
|
|
std::move(textWidth),
|
2022-06-14 04:03:18 +00:00
|
|
|
button->sizeValue()
|
|
|
|
) | rpl::start_with_next([=](
|
|
|
|
int unreadWidth,
|
|
|
|
int premiumWidth,
|
2022-10-14 08:01:53 +00:00
|
|
|
int textWidth,
|
2022-06-14 04:03:18 +00:00
|
|
|
const QSize &buttonSize) {
|
|
|
|
const auto &st = button->st();
|
|
|
|
const auto skip = st.style.font->spacew;
|
|
|
|
const auto textRightPosition = st.padding.left()
|
2022-10-14 08:01:53 +00:00
|
|
|
+ textWidth
|
2022-08-11 17:22:21 +00:00
|
|
|
+ skip;
|
2022-06-14 04:03:18 +00:00
|
|
|
const auto minWidth = unreadWidth + premiumWidth + skip;
|
|
|
|
const auto maxTextWidth = buttonSize.width()
|
|
|
|
- minWidth
|
|
|
|
- st.padding.right();
|
|
|
|
|
|
|
|
const auto finalTextRight = std::min(textRightPosition, maxTextWidth);
|
|
|
|
|
|
|
|
resize(
|
|
|
|
buttonSize.width() - st.padding.right() - finalTextRight,
|
|
|
|
buttonSize.height());
|
|
|
|
|
2022-08-11 17:56:07 +00:00
|
|
|
_badge.move(
|
|
|
|
0,
|
|
|
|
st.padding.top(),
|
|
|
|
buttonSize.height() - st.padding.top());
|
2022-06-14 04:03:18 +00:00
|
|
|
if (_unread) {
|
|
|
|
_unread->moveToRight(
|
|
|
|
0,
|
|
|
|
(buttonSize.height() - _unread->height()) / 2);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
class AccountsList final {
|
|
|
|
public:
|
|
|
|
AccountsList(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Window::SessionController*> controller);
|
|
|
|
|
2023-04-23 14:21:31 +00:00
|
|
|
[[nodiscard]] rpl::producer<> closeRequests() const;
|
2022-03-15 11:12:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup();
|
|
|
|
|
|
|
|
[[nodiscard]] not_null<Ui::SlideWrap<Ui::SettingsButton>*> setupAdd();
|
|
|
|
void rebuild();
|
|
|
|
|
|
|
|
const not_null<Window::SessionController*> _controller;
|
|
|
|
const not_null<Ui::VerticalLayout*> _outer;
|
|
|
|
int _outerIndex = 0;
|
|
|
|
|
|
|
|
Ui::SlideWrap<Ui::SettingsButton> *_addAccount = nullptr;
|
|
|
|
base::flat_map<
|
|
|
|
not_null<Main::Account*>,
|
|
|
|
base::unique_qptr<Ui::SettingsButton>> _watched;
|
|
|
|
|
|
|
|
base::unique_qptr<Ui::PopupMenu> _contextMenu;
|
|
|
|
std::unique_ptr<Ui::VerticalLayoutReorder> _reorder;
|
|
|
|
int _reordering = 0;
|
|
|
|
|
2023-04-23 14:21:31 +00:00
|
|
|
rpl::event_stream<> _closeRequests;
|
2022-03-15 11:12:49 +00:00
|
|
|
|
|
|
|
base::binary_guard _accountSwitchGuard;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<TextWithEntities> StatusValue(
|
|
|
|
not_null<UserData*> user) {
|
|
|
|
return [=](auto consumer) {
|
|
|
|
auto lifetime = rpl::lifetime();
|
|
|
|
const auto timer = lifetime.make_state<base::Timer>();
|
|
|
|
const auto push = [=] {
|
|
|
|
const auto now = base::unixtime::now();
|
|
|
|
consumer.put_next(Data::OnlineTextActive(user, now)
|
|
|
|
? Ui::Text::Link(Data::OnlineText(user, now))
|
|
|
|
: Ui::Text::WithEntities(Data::OnlineText(user, now)));
|
|
|
|
timer->callOnce(Data::OnlineChangeTimeout(user, now));
|
|
|
|
};
|
|
|
|
timer->setCallback(push);
|
|
|
|
user->session().changes().peerFlagsValue(
|
|
|
|
user,
|
|
|
|
Data::PeerUpdate::Flag::OnlineStatus
|
|
|
|
) | rpl::start_with_next(push, lifetime);
|
|
|
|
return lifetime;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
void SetupPhoto(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-09-13 20:09:26 +00:00
|
|
|
not_null<UserData*> self) {
|
2022-03-15 11:12:49 +00:00
|
|
|
const auto wrap = container->add(object_ptr<Ui::FixedHeightWidget>(
|
2018-09-13 20:09:26 +00:00
|
|
|
container,
|
|
|
|
st::settingsInfoPhotoHeight));
|
|
|
|
const auto photo = Ui::CreateChild<Ui::UserpicButton>(
|
|
|
|
wrap,
|
|
|
|
controller,
|
|
|
|
self,
|
|
|
|
Ui::UserpicButton::Role::OpenPhoto,
|
2022-12-20 13:12:32 +00:00
|
|
|
Ui::UserpicButton::Source::PeerPhoto,
|
2018-09-13 20:09:26 +00:00
|
|
|
st::settingsInfoPhoto);
|
2022-12-19 11:48:24 +00:00
|
|
|
const auto upload = CreateUploadSubButton(wrap, controller);
|
2022-03-15 12:35:28 +00:00
|
|
|
|
|
|
|
upload->chosenImages(
|
2022-12-09 12:34:34 +00:00
|
|
|
) | rpl::start_with_next([=](Ui::UserpicButton::ChosenImage &&chosen) {
|
2022-12-10 03:21:27 +00:00
|
|
|
auto &image = chosen.image;
|
|
|
|
UpdatePhotoLocally(self, image);
|
2022-12-20 13:12:32 +00:00
|
|
|
photo->showCustom(base::duplicate(image));
|
2023-01-30 21:37:34 +00:00
|
|
|
self->session().api().peerPhoto().upload(
|
|
|
|
self,
|
|
|
|
{
|
|
|
|
std::move(image),
|
|
|
|
chosen.markup.documentId,
|
|
|
|
chosen.markup.colors,
|
|
|
|
});
|
2022-03-15 12:35:28 +00:00
|
|
|
}, upload->lifetime());
|
2022-03-15 11:12:49 +00:00
|
|
|
|
|
|
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
2018-09-13 20:09:26 +00:00
|
|
|
wrap,
|
2022-03-15 11:12:49 +00:00
|
|
|
Info::Profile::NameValue(self),
|
|
|
|
st::settingsCoverName);
|
|
|
|
const auto status = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
wrap,
|
|
|
|
StatusValue(self),
|
|
|
|
st::settingsCoverStatus);
|
2023-01-07 03:41:56 +00:00
|
|
|
status->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2018-09-13 20:09:26 +00:00
|
|
|
rpl::combine(
|
|
|
|
wrap->widthValue(),
|
|
|
|
photo->widthValue(),
|
2022-03-16 07:20:39 +00:00
|
|
|
Info::Profile::NameValue(self),
|
2022-03-15 11:12:49 +00:00
|
|
|
status->widthValue()
|
|
|
|
) | rpl::start_with_next([=](
|
|
|
|
int max,
|
|
|
|
int photoWidth,
|
2022-09-27 12:05:47 +00:00
|
|
|
const QString&,
|
2022-03-15 11:12:49 +00:00
|
|
|
int statusWidth) {
|
2018-09-13 20:09:26 +00:00
|
|
|
photo->moveToLeft(
|
|
|
|
(max - photoWidth) / 2,
|
|
|
|
st::settingsInfoPhotoTop);
|
2022-03-15 12:35:28 +00:00
|
|
|
upload->moveToLeft(
|
|
|
|
((max - photoWidth) / 2
|
|
|
|
+ photoWidth
|
|
|
|
- upload->width()
|
|
|
|
+ st::settingsInfoUploadLeft),
|
|
|
|
photo->y() + photo->height() - upload->height());
|
2022-03-16 07:20:39 +00:00
|
|
|
const auto skip = st::settingsButton.iconLeft;
|
|
|
|
name->resizeToNaturalWidth(max - 2 * skip);
|
2022-03-15 11:12:49 +00:00
|
|
|
name->moveToLeft(
|
2022-03-16 07:20:39 +00:00
|
|
|
(max - name->width()) / 2,
|
2022-03-15 11:12:49 +00:00
|
|
|
(photo->y() + photo->height() + st::settingsInfoPhotoSkip));
|
|
|
|
status->moveToLeft(
|
|
|
|
(max - statusWidth) / 2,
|
|
|
|
(name->y() + name->height() + st::settingsInfoNameSkip));
|
2018-09-13 20:09:26 +00:00
|
|
|
}, photo->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowMenu(
|
|
|
|
QWidget *parent,
|
|
|
|
const QString ©Button,
|
|
|
|
const QString &text) {
|
2022-04-28 14:29:31 +00:00
|
|
|
const auto menu = Ui::CreateChild<Ui::PopupMenu>(parent);
|
2018-09-13 20:09:26 +00:00
|
|
|
|
|
|
|
menu->addAction(copyButton, [=] {
|
2019-09-04 07:19:15 +00:00
|
|
|
QGuiApplication::clipboard()->setText(text);
|
2018-09-13 20:09:26 +00:00
|
|
|
});
|
|
|
|
menu->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:38:08 +00:00
|
|
|
void AddRow(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> label,
|
|
|
|
rpl::producer<TextWithEntities> value,
|
2018-09-13 20:09:26 +00:00
|
|
|
const QString ©Button,
|
2018-09-09 17:38:08 +00:00
|
|
|
Fn<void()> edit,
|
2022-03-15 11:12:49 +00:00
|
|
|
IconDescriptor &&descriptor) {
|
|
|
|
const auto wrap = AddButtonWithLabel(
|
2018-09-09 17:38:08 +00:00
|
|
|
container,
|
2022-03-15 11:12:49 +00:00
|
|
|
std::move(label),
|
|
|
|
std::move(value) | rpl::map([](const auto &t) { return t.text; }),
|
|
|
|
st::settingsButton,
|
|
|
|
std::move(descriptor));
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto forcopy = Ui::CreateChild<QString>(wrap.get());
|
2018-09-13 20:09:26 +00:00
|
|
|
wrap->setAcceptBoth();
|
|
|
|
wrap->clicks(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !wrap->isDisabled();
|
|
|
|
}) | rpl::start_with_next([=](Qt::MouseButton button) {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
edit();
|
|
|
|
} else if (!forcopy->isEmpty()) {
|
|
|
|
ShowMenu(wrap, copyButton, *forcopy);
|
|
|
|
}
|
2018-09-09 17:38:08 +00:00
|
|
|
}, wrap->lifetime());
|
|
|
|
|
|
|
|
auto existing = base::duplicate(
|
|
|
|
value
|
|
|
|
) | rpl::map([](const TextWithEntities &text) {
|
|
|
|
return text.entities.isEmpty();
|
|
|
|
});
|
2018-09-13 20:09:26 +00:00
|
|
|
base::duplicate(
|
|
|
|
value
|
|
|
|
) | rpl::filter([](const TextWithEntities &text) {
|
|
|
|
return text.entities.isEmpty();
|
|
|
|
}) | rpl::start_with_next([=](const TextWithEntities &text) {
|
|
|
|
*forcopy = text.text;
|
|
|
|
}, wrap->lifetime());
|
2018-09-09 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupRows(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2021-06-13 07:37:52 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-09-09 17:38:08 +00:00
|
|
|
not_null<UserData*> self) {
|
2019-08-06 16:40:08 +00:00
|
|
|
const auto session = &self->session();
|
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSkip(container);
|
2018-09-09 17:38:08 +00:00
|
|
|
|
|
|
|
AddRow(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_name_label(),
|
2022-09-27 12:05:47 +00:00
|
|
|
Info::Profile::NameValue(self) | Ui::Text::ToWithEntities(),
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_profile_copy_fullname(tr::now),
|
2021-06-13 07:37:52 +00:00
|
|
|
[=] { controller->show(Box<EditNameBox>(self)); },
|
2023-08-14 12:04:33 +00:00
|
|
|
{ &st::menuIconProfile });
|
2018-09-09 17:38:08 +00:00
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
const auto showChangePhone = [=] {
|
2023-05-24 14:11:17 +00:00
|
|
|
controller->show(
|
|
|
|
Ui::MakeInformBox(tr::lng_change_phone_error()));
|
2022-04-13 08:05:10 +00:00
|
|
|
controller->window().activate();
|
|
|
|
};
|
2018-09-09 17:38:08 +00:00
|
|
|
AddRow(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_phone_label(),
|
2018-09-09 17:38:08 +00:00
|
|
|
Info::Profile::PhoneValue(self),
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_profile_copy_phone(tr::now),
|
2022-04-13 08:05:10 +00:00
|
|
|
showChangePhone,
|
2023-08-14 12:04:33 +00:00
|
|
|
{ &st::menuIconPhone });
|
2018-09-09 17:38:08 +00:00
|
|
|
|
|
|
|
auto username = Info::Profile::UsernameValue(self);
|
|
|
|
auto empty = base::duplicate(
|
|
|
|
username
|
|
|
|
) | rpl::map([](const TextWithEntities &username) {
|
|
|
|
return username.text.isEmpty();
|
|
|
|
});
|
|
|
|
auto label = rpl::combine(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_username_label(),
|
2018-09-09 17:38:08 +00:00
|
|
|
std::move(empty)
|
|
|
|
) | rpl::map([](const QString &label, bool empty) {
|
|
|
|
return empty ? "t.me/username" : label;
|
|
|
|
});
|
|
|
|
auto value = rpl::combine(
|
|
|
|
std::move(username),
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_username_add()
|
2018-09-09 17:38:08 +00:00
|
|
|
) | rpl::map([](const TextWithEntities &username, const QString &add) {
|
|
|
|
if (!username.text.isEmpty()) {
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
auto result = TextWithEntities{ add };
|
2019-04-08 15:10:06 +00:00
|
|
|
result.entities.push_back({
|
|
|
|
EntityType::CustomUrl,
|
2018-09-09 17:38:08 +00:00
|
|
|
0,
|
2021-10-19 13:00:21 +00:00
|
|
|
int(add.size()),
|
2019-04-08 15:10:06 +00:00
|
|
|
"internal:edit_username" });
|
2018-09-09 17:38:08 +00:00
|
|
|
return result;
|
|
|
|
});
|
2022-10-12 18:16:04 +00:00
|
|
|
session->api().usernames().requestToCache(session->user());
|
2018-09-09 17:38:08 +00:00
|
|
|
AddRow(
|
|
|
|
container,
|
|
|
|
std::move(label),
|
|
|
|
std::move(value),
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_context_copy_mention(tr::now),
|
2022-10-12 18:16:04 +00:00
|
|
|
[=] {
|
2023-04-09 20:25:18 +00:00
|
|
|
const auto box = controller->show(
|
|
|
|
Box(UsernamesBox, session->user()));
|
2022-10-12 18:16:04 +00:00
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
session->api().usernames().requestToCache(session->user());
|
|
|
|
}, box->lifetime());
|
|
|
|
},
|
2023-08-14 12:04:33 +00:00
|
|
|
{ &st::menuIconUsername });
|
2018-09-09 17:38:08 +00:00
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSkip(container);
|
|
|
|
Ui::AddDividerText(container, tr::lng_settings_username_about());
|
2018-09-09 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 13:05:43 +00:00
|
|
|
void SetupBio(
|
2018-09-09 17:38:08 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<UserData*> self) {
|
2022-06-15 22:24:10 +00:00
|
|
|
const auto limits = Data::PremiumLimits(&self->session());
|
|
|
|
const auto defaultLimit = limits.aboutLengthDefault();
|
|
|
|
const auto premiumLimit = limits.aboutLengthPremium();
|
2022-05-30 14:30:51 +00:00
|
|
|
const auto bioStyle = [=] {
|
2018-09-10 12:18:39 +00:00
|
|
|
auto result = st::settingsBio;
|
2021-10-18 13:05:43 +00:00
|
|
|
result.textMargins.setRight(st::boxTextFont->spacew
|
2022-05-30 14:30:51 +00:00
|
|
|
+ st::boxTextFont->width('-' + QString::number(premiumLimit)));
|
2018-09-09 17:38:08 +00:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
const auto style = Ui::AttachAsChild(container, bioStyle());
|
|
|
|
const auto current = Ui::AttachAsChild(container, self->about());
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto changed = Ui::CreateChild<rpl::event_stream<bool>>(
|
|
|
|
container.get());
|
2018-09-09 17:38:08 +00:00
|
|
|
const auto bio = container->add(
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
container,
|
|
|
|
*style,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_bio_placeholder(),
|
2018-09-09 17:38:08 +00:00
|
|
|
*current),
|
|
|
|
st::settingsBioMargins);
|
|
|
|
|
|
|
|
const auto countdown = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
container.get(),
|
|
|
|
QString(),
|
|
|
|
st::settingsBioCountdown);
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
bio->geometryValue(),
|
|
|
|
countdown->widthValue()
|
|
|
|
) | rpl::start_with_next([=](QRect geometry, int width) {
|
|
|
|
countdown->move(
|
|
|
|
geometry.x() + geometry.width() - width,
|
|
|
|
geometry.y() + style->textMargins.top());
|
|
|
|
}, countdown->lifetime());
|
|
|
|
|
2018-09-11 12:50:40 +00:00
|
|
|
const auto assign = [=](QString text) {
|
|
|
|
auto position = bio->textCursor().position();
|
|
|
|
bio->setText(text.replace('\n', ' '));
|
|
|
|
auto cursor = bio->textCursor();
|
|
|
|
cursor.setPosition(position);
|
|
|
|
bio->setTextCursor(cursor);
|
|
|
|
};
|
2018-09-09 17:38:08 +00:00
|
|
|
const auto updated = [=] {
|
|
|
|
auto text = bio->getLastText();
|
|
|
|
if (text.indexOf('\n') >= 0) {
|
2018-09-11 12:50:40 +00:00
|
|
|
assign(text);
|
|
|
|
text = bio->getLastText();
|
2018-09-09 17:38:08 +00:00
|
|
|
}
|
|
|
|
changed->fire(*current != text);
|
2022-05-30 14:30:51 +00:00
|
|
|
const auto limit = self->isPremium() ? premiumLimit : defaultLimit;
|
|
|
|
const auto countLeft = limit - int(text.size());
|
2018-09-09 17:38:08 +00:00
|
|
|
countdown->setText(QString::number(countLeft));
|
2022-05-30 14:30:51 +00:00
|
|
|
countdown->setTextColorOverride(
|
|
|
|
countLeft < 0 ? st::boxTextFgError->c : std::optional<QColor>());
|
2018-09-09 17:38:08 +00:00
|
|
|
};
|
2021-10-18 13:05:43 +00:00
|
|
|
const auto save = [=] {
|
2019-07-24 14:00:30 +00:00
|
|
|
self->session().api().saveSelfBio(
|
2021-10-18 13:05:43 +00:00
|
|
|
TextUtilities::PrepareForSending(bio->getLastText()));
|
2018-09-09 17:38:08 +00:00
|
|
|
};
|
|
|
|
|
2020-10-29 16:53:07 +00:00
|
|
|
Info::Profile::AboutValue(
|
2018-09-09 17:38:08 +00:00
|
|
|
self
|
|
|
|
) | rpl::start_with_next([=](const TextWithEntities &text) {
|
2018-09-11 12:50:40 +00:00
|
|
|
const auto wasChanged = (*current != bio->getLastText());
|
2018-09-09 17:38:08 +00:00
|
|
|
*current = text.text;
|
2018-09-11 12:50:40 +00:00
|
|
|
if (wasChanged) {
|
|
|
|
changed->fire(*current != bio->getLastText());
|
|
|
|
} else {
|
|
|
|
assign(text.text);
|
|
|
|
*current = bio->getLastText();
|
|
|
|
}
|
2018-09-09 17:38:08 +00:00
|
|
|
}, bio->lifetime());
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto generation = Ui::CreateChild<int>(bio);
|
2018-09-18 16:32:07 +00:00
|
|
|
changed->events(
|
|
|
|
) | rpl::start_with_next([=](bool changed) {
|
|
|
|
if (changed) {
|
|
|
|
const auto saved = *generation = std::abs(*generation) + 1;
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(kSaveBioTimeout, bio, [=] {
|
2018-09-18 16:32:07 +00:00
|
|
|
if (*generation == saved) {
|
2021-10-18 13:05:43 +00:00
|
|
|
save();
|
2018-09-18 16:32:07 +00:00
|
|
|
*generation = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (*generation > 0) {
|
|
|
|
*generation = -*generation;
|
|
|
|
}
|
|
|
|
}, bio->lifetime());
|
|
|
|
|
|
|
|
// We need 'bio' to still exist here as InputField, so we add this
|
|
|
|
// to 'container' lifetime, not to the 'bio' lifetime.
|
|
|
|
container->lifetime().add([=] {
|
|
|
|
if (*generation > 0) {
|
2021-10-18 13:05:43 +00:00
|
|
|
save();
|
2018-09-18 16:32:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-30 14:30:51 +00:00
|
|
|
bio->setMaxLength(premiumLimit * 2);
|
2018-09-09 17:38:08 +00:00
|
|
|
bio->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
|
|
|
|
auto cursor = bio->textCursor();
|
|
|
|
cursor.setPosition(bio->getLastText().size());
|
|
|
|
bio->setTextCursor(cursor);
|
2023-08-31 11:21:24 +00:00
|
|
|
bio->submits() | rpl::start_with_next([=] { save(); }, bio->lifetime());
|
|
|
|
bio->changes() | rpl::start_with_next(updated, bio->lifetime());
|
2018-09-09 17:38:08 +00:00
|
|
|
bio->setInstantReplaces(Ui::InstantReplaces::Default());
|
2019-08-02 10:40:35 +00:00
|
|
|
bio->setInstantReplacesEnabled(
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().replaceEmojiValue());
|
2019-08-02 10:40:35 +00:00
|
|
|
Ui::Emoji::SuggestionsController::Init(
|
|
|
|
container->window(),
|
|
|
|
bio,
|
|
|
|
&self->session());
|
2018-09-09 17:38:08 +00:00
|
|
|
updated();
|
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddDividerText(container, tr::lng_settings_about_bio());
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
2018-09-13 20:09:26 +00:00
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
void SetupAccountsWrap(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Window::SessionController*> controller) {
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSkip(container);
|
2022-03-15 11:12:49 +00:00
|
|
|
|
|
|
|
SetupAccounts(container, controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsAltShift(Qt::KeyboardModifiers modifiers) {
|
|
|
|
return (modifiers & Qt::ShiftModifier) && (modifiers & Qt::AltModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] object_ptr<Ui::SettingsButton> MakeAccountButton(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> window,
|
|
|
|
not_null<Main::Account*> account,
|
2023-01-17 15:47:58 +00:00
|
|
|
Fn<void(Qt::KeyboardModifiers)> callback,
|
2022-06-02 10:54:10 +00:00
|
|
|
bool locked) {
|
2023-01-23 05:29:35 +00:00
|
|
|
const auto active = (account == &window->session().account());
|
2022-03-15 11:12:49 +00:00
|
|
|
const auto session = &account->session();
|
|
|
|
const auto user = session->user();
|
|
|
|
|
|
|
|
auto text = rpl::single(
|
2022-08-09 11:12:19 +00:00
|
|
|
user->name()
|
2022-03-15 11:12:49 +00:00
|
|
|
) | rpl::then(session->changes().realtimeNameUpdates(
|
|
|
|
user
|
|
|
|
) | rpl::map([=] {
|
2022-08-09 11:12:19 +00:00
|
|
|
return user->name();
|
2022-03-15 11:12:49 +00:00
|
|
|
}));
|
|
|
|
auto result = object_ptr<Ui::SettingsButton>(
|
|
|
|
parent,
|
2022-06-14 04:03:18 +00:00
|
|
|
rpl::duplicate(text),
|
2022-03-15 11:12:49 +00:00
|
|
|
st::mainMenuAddAccountButton);
|
|
|
|
const auto raw = result.data();
|
|
|
|
|
2022-06-14 04:03:18 +00:00
|
|
|
{
|
|
|
|
const auto container = Badge::AddRight(raw);
|
|
|
|
const auto composedBadge = Ui::CreateChild<ComposedBadge>(
|
|
|
|
container.get(),
|
|
|
|
raw,
|
|
|
|
session,
|
|
|
|
std::move(text),
|
2022-08-11 17:22:21 +00:00
|
|
|
!active,
|
|
|
|
[=] { return window->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Layer); });
|
2022-06-14 04:03:18 +00:00
|
|
|
composedBadge->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
container->resize(s);
|
|
|
|
}, container->lifetime());
|
|
|
|
}
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
struct State {
|
|
|
|
State(QWidget *parent) : userpic(parent) {
|
|
|
|
userpic.setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::RpWidget userpic;
|
2022-12-05 12:18:10 +00:00
|
|
|
Ui::PeerUserpicView view;
|
2022-03-15 11:12:49 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> menu;
|
|
|
|
};
|
|
|
|
const auto state = raw->lifetime().make_state<State>(raw);
|
|
|
|
|
|
|
|
const auto userpicSkip = 2 * st::mainMenuAccountLine + st::lineWidth;
|
|
|
|
const auto userpicSize = st::mainMenuAccountSize
|
|
|
|
+ userpicSkip * 2;
|
|
|
|
raw->heightValue(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
const auto left = st::mainMenuAddAccountButton.iconLeft
|
2022-05-03 18:11:47 +00:00
|
|
|
+ (st::settingsIconAdd.width() - userpicSize) / 2;
|
2022-03-15 11:12:49 +00:00
|
|
|
const auto top = (height - userpicSize) / 2;
|
|
|
|
state->userpic.setGeometry(left, top, userpicSize, userpicSize);
|
|
|
|
}, state->userpic.lifetime());
|
|
|
|
|
|
|
|
state->userpic.paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = Painter(&state->userpic);
|
|
|
|
const auto size = st::mainMenuAccountSize;
|
|
|
|
const auto line = st::mainMenuAccountLine;
|
|
|
|
const auto skip = 2 * line + st::lineWidth;
|
|
|
|
const auto full = size + skip * 2;
|
|
|
|
user->paintUserpicLeft(p, state->view, skip, skip, full, size);
|
|
|
|
if (active) {
|
|
|
|
const auto shift = st::lineWidth + (line * 0.5);
|
|
|
|
const auto diameter = full - 2 * shift;
|
|
|
|
const auto rect = QRectF(shift, shift, diameter, diameter);
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
auto pen = st::windowBgActive->p; // The same as '+' in add.
|
|
|
|
pen.setWidthF(line);
|
|
|
|
p.setPen(pen);
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
}
|
|
|
|
}, state->userpic.lifetime());
|
|
|
|
|
|
|
|
raw->setAcceptBoth(true);
|
|
|
|
raw->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
|
|
|
if (which == Qt::LeftButton) {
|
2023-01-17 15:47:58 +00:00
|
|
|
callback(raw->clickModifiers());
|
2022-03-15 11:12:49 +00:00
|
|
|
return;
|
|
|
|
} else if (which != Qt::RightButton) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-02 10:54:10 +00:00
|
|
|
if (!state->menu && IsAltShift(raw->clickModifiers()) && !locked) {
|
2022-03-15 11:12:49 +00:00
|
|
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
raw,
|
|
|
|
st::popupMenuWithIcons);
|
2022-11-06 15:18:19 +00:00
|
|
|
Window::MenuAddMarkAsReadAllChatsAction(
|
|
|
|
window,
|
|
|
|
Ui::Menu::CreateAddActionCallback(state->menu));
|
2022-03-15 11:12:49 +00:00
|
|
|
state->menu->popup(QCursor::pos());
|
|
|
|
return;
|
|
|
|
}
|
2023-01-23 05:29:35 +00:00
|
|
|
if (session == &window->session() || state->menu) {
|
2022-03-15 11:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
raw,
|
2023-02-03 15:32:25 +00:00
|
|
|
st::popupMenuExpandedSeparator);
|
2022-11-06 15:18:19 +00:00
|
|
|
const auto addAction = Ui::Menu::CreateAddActionCallback(
|
|
|
|
state->menu);
|
2023-02-03 15:32:25 +00:00
|
|
|
addAction(tr::lng_context_new_window(tr::now), [=] {
|
|
|
|
Ui::PreventDelayedActivation();
|
2023-04-05 17:27:11 +00:00
|
|
|
callback(Qt::ControlModifier);
|
2023-02-03 15:32:25 +00:00
|
|
|
}, &st::menuIconNewWindow);
|
|
|
|
Window::AddSeparatorAndShiftUp(addAction);
|
|
|
|
|
2022-04-28 14:29:31 +00:00
|
|
|
addAction(tr::lng_profile_copy_phone(tr::now), [=] {
|
|
|
|
const auto phone = rpl::variable<TextWithEntities>(
|
|
|
|
Info::Profile::PhoneValue(session->user()));
|
|
|
|
QGuiApplication::clipboard()->setText(phone.current().text);
|
|
|
|
}, &st::menuIconCopy);
|
|
|
|
|
2022-06-02 10:54:10 +00:00
|
|
|
if (!locked) {
|
|
|
|
addAction(tr::lng_menu_activate(tr::now), [=] {
|
2023-02-15 04:44:10 +00:00
|
|
|
callback({});
|
2022-06-02 10:54:10 +00:00
|
|
|
}, &st::menuIconProfile);
|
|
|
|
}
|
2022-04-04 14:15:45 +00:00
|
|
|
|
|
|
|
auto logoutCallback = [=] {
|
2022-03-15 11:12:49 +00:00
|
|
|
const auto callback = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
|
|
|
Core::App().logoutWithChecks(&session->account());
|
|
|
|
};
|
|
|
|
window->show(
|
|
|
|
Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_sure_logout(),
|
|
|
|
.confirmed = crl::guard(session, callback),
|
|
|
|
.confirmText = tr::lng_settings_logout(),
|
|
|
|
.confirmStyle = &st::attentionBoxButton,
|
|
|
|
}),
|
|
|
|
Ui::LayerOption::CloseOther);
|
2022-04-04 14:15:45 +00:00
|
|
|
};
|
|
|
|
addAction({
|
|
|
|
.text = tr::lng_settings_logout(tr::now),
|
|
|
|
.handler = std::move(logoutCallback),
|
|
|
|
.icon = &st::menuIconLeaveAttention,
|
|
|
|
.isAttention = true,
|
|
|
|
});
|
2022-03-15 11:12:49 +00:00
|
|
|
state->menu->popup(QCursor::pos());
|
|
|
|
}, raw->lifetime());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountsList::AccountsList(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: _controller(controller)
|
|
|
|
, _outer(container)
|
|
|
|
, _outerIndex(container->count()) {
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2023-04-23 14:21:31 +00:00
|
|
|
rpl::producer<> AccountsList::closeRequests() const {
|
|
|
|
return _closeRequests.events();
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AccountsList::setup() {
|
|
|
|
_addAccount = setupAdd();
|
|
|
|
|
|
|
|
rpl::single(rpl::empty) | rpl::then(
|
|
|
|
Core::App().domain().accountsChanges()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto &list = Core::App().domain().accounts();
|
|
|
|
const auto exists = [&](not_null<Main::Account*> account) {
|
|
|
|
for (const auto &[index, existing] : list) {
|
|
|
|
if (account == existing.get()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
for (auto i = _watched.begin(); i != _watched.end();) {
|
|
|
|
if (!exists(i->first)) {
|
|
|
|
i = _watched.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &[index, account] : list) {
|
|
|
|
if (_watched.emplace(account.get()).second) {
|
|
|
|
account->sessionChanges(
|
2022-06-02 10:54:10 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-15 11:12:49 +00:00
|
|
|
rebuild();
|
|
|
|
}, _outer->lifetime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuild();
|
|
|
|
}, _outer->lifetime());
|
2022-06-02 10:54:10 +00:00
|
|
|
|
|
|
|
Core::App().domain().maxAccountsChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
// Full rebuild.
|
|
|
|
for (auto i = _watched.begin(); i != _watched.end(); i++) {
|
|
|
|
i->second = nullptr;
|
|
|
|
}
|
|
|
|
rebuild();
|
|
|
|
}, _outer->lifetime());
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
not_null<Ui::SlideWrap<Ui::SettingsButton>*> AccountsList::setupAdd() {
|
|
|
|
const auto result = _outer->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
|
|
|
|
_outer.get(),
|
2023-11-14 20:59:21 +00:00
|
|
|
CreateButtonWithIcon(
|
2022-03-15 11:12:49 +00:00
|
|
|
_outer.get(),
|
|
|
|
tr::lng_menu_add_account(),
|
|
|
|
st::mainMenuAddAccountButton,
|
|
|
|
{
|
2022-05-03 18:11:47 +00:00
|
|
|
&st::settingsIconAdd,
|
2022-03-15 11:12:49 +00:00
|
|
|
IconType::Round,
|
|
|
|
&st::windowBgActive
|
|
|
|
})))->setDuration(0);
|
|
|
|
const auto button = result->entity();
|
|
|
|
|
2023-01-27 15:56:43 +00:00
|
|
|
using Environment = MTP::Environment;
|
|
|
|
const auto add = [=](Environment environment, bool newWindow = false) {
|
|
|
|
auto &domain = _controller->session().domain();
|
|
|
|
auto found = false;
|
|
|
|
for (const auto &[index, account] : domain.accounts()) {
|
|
|
|
const auto raw = account.get();
|
|
|
|
if (!raw->sessionExists()
|
|
|
|
&& raw->mtp().environment() == environment) {
|
|
|
|
found = true;
|
2022-05-31 12:32:41 +00:00
|
|
|
}
|
2023-01-27 15:56:43 +00:00
|
|
|
}
|
|
|
|
if (!found && domain.accounts().size() >= domain.maxAccounts()) {
|
|
|
|
_controller->show(
|
|
|
|
Box(AccountsLimitBox, &_controller->session()));
|
|
|
|
} else if (newWindow) {
|
|
|
|
domain.addActivated(environment, true);
|
|
|
|
} else {
|
|
|
|
_controller->window().preventOrInvoke([=] {
|
|
|
|
_controller->session().domain().addActivated(environment);
|
|
|
|
});
|
|
|
|
}
|
2022-03-15 11:12:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
button->setAcceptBoth(true);
|
|
|
|
button->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
|
|
|
if (which == Qt::LeftButton) {
|
2023-01-27 15:56:43 +00:00
|
|
|
const auto modifiers = button->clickModifiers();
|
2023-02-03 15:32:25 +00:00
|
|
|
const auto newWindow = (modifiers & Qt::ControlModifier);
|
2023-01-27 15:56:43 +00:00
|
|
|
add(Environment::Production, newWindow);
|
2022-03-15 11:12:49 +00:00
|
|
|
return;
|
|
|
|
} else if (which != Qt::RightButton
|
|
|
|
|| !IsAltShift(button->clickModifiers())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_contextMenu = base::make_unique_q<Ui::PopupMenu>(_outer);
|
|
|
|
_contextMenu->addAction("Production Server", [=] {
|
2023-01-27 15:56:43 +00:00
|
|
|
add(Environment::Production);
|
2022-03-15 11:12:49 +00:00
|
|
|
});
|
|
|
|
_contextMenu->addAction("Test Server", [=] {
|
2023-01-27 15:56:43 +00:00
|
|
|
add(Environment::Test);
|
2022-03-15 11:12:49 +00:00
|
|
|
});
|
|
|
|
_contextMenu->popup(QCursor::pos());
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AccountsList::rebuild() {
|
|
|
|
const auto inner = _outer->insert(
|
|
|
|
_outerIndex,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_outer.get()));
|
|
|
|
|
|
|
|
_reorder = std::make_unique<Ui::VerticalLayoutReorder>(inner);
|
|
|
|
_reorder->updates(
|
|
|
|
) | rpl::start_with_next([=](Ui::VerticalLayoutReorder::Single data) {
|
|
|
|
using State = Ui::VerticalLayoutReorder::State;
|
|
|
|
if (data.state == State::Started) {
|
|
|
|
++_reordering;
|
|
|
|
} else {
|
|
|
|
Ui::PostponeCall(inner, [=] {
|
|
|
|
--_reordering;
|
|
|
|
});
|
|
|
|
if (data.state == State::Applied) {
|
|
|
|
std::vector<uint64> order;
|
|
|
|
order.reserve(inner->count());
|
|
|
|
for (auto i = 0; i < inner->count(); i++) {
|
|
|
|
for (const auto &[account, button] : _watched) {
|
|
|
|
if (button.get() == inner->widgetAt(i)) {
|
|
|
|
order.push_back(account->session().uniqueId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Core::App().settings().setAccountsOrder(order);
|
|
|
|
Core::App().saveSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, inner->lifetime());
|
|
|
|
|
2022-06-02 10:54:10 +00:00
|
|
|
const auto premiumLimit = _controller->session().domain().maxAccounts();
|
2022-06-02 10:47:57 +00:00
|
|
|
const auto list = _controller->session().domain().orderedAccounts();
|
2022-03-15 11:12:49 +00:00
|
|
|
for (const auto &account : list) {
|
|
|
|
auto i = _watched.find(account);
|
|
|
|
Assert(i != _watched.end());
|
|
|
|
|
|
|
|
auto &button = i->second;
|
|
|
|
if (!account->sessionExists() || list.size() == 1) {
|
|
|
|
button = nullptr;
|
|
|
|
} else if (!button) {
|
2022-06-02 10:54:10 +00:00
|
|
|
const auto nextIsLocked = (inner->count() >= premiumLimit);
|
2023-01-17 15:47:58 +00:00
|
|
|
auto callback = [=](Qt::KeyboardModifiers modifiers) {
|
2022-03-15 11:12:49 +00:00
|
|
|
if (_reordering) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-17 15:47:58 +00:00
|
|
|
if (account == &_controller->session().account()) {
|
2023-04-23 14:21:31 +00:00
|
|
|
_closeRequests.fire({});
|
2022-03-15 11:12:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-02-03 15:32:25 +00:00
|
|
|
const auto newWindow = (modifiers & Qt::ControlModifier);
|
2022-03-15 11:12:49 +00:00
|
|
|
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
|
|
|
|
if (guard) {
|
|
|
|
_reorder->finishReordering();
|
2023-04-23 14:21:31 +00:00
|
|
|
if (newWindow) {
|
|
|
|
_closeRequests.fire({});
|
|
|
|
Core::App().ensureSeparateWindowForAccount(
|
|
|
|
account);
|
|
|
|
}
|
|
|
|
Core::App().domain().maybeActivate(account);
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
|
|
|
};
|
2023-04-23 14:21:31 +00:00
|
|
|
if (const auto window = Core::App().separateWindowForAccount(account)) {
|
|
|
|
_closeRequests.fire({});
|
|
|
|
window->activate();
|
2023-02-03 05:59:28 +00:00
|
|
|
} else {
|
|
|
|
base::call_delayed(
|
|
|
|
st::defaultRippleAnimation.hideDuration,
|
|
|
|
account,
|
|
|
|
std::move(activate));
|
|
|
|
}
|
2022-03-15 11:12:49 +00:00
|
|
|
};
|
|
|
|
button.reset(inner->add(MakeAccountButton(
|
|
|
|
inner,
|
|
|
|
_controller,
|
|
|
|
account,
|
2022-06-02 10:54:10 +00:00
|
|
|
std::move(callback),
|
|
|
|
nextIsLocked)));
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
inner->resizeToWidth(_outer->width());
|
|
|
|
|
2022-06-02 10:54:10 +00:00
|
|
|
const auto count = int(list.size());
|
|
|
|
|
|
|
|
_reorder->addPinnedInterval(
|
|
|
|
premiumLimit,
|
|
|
|
std::max(1, count - premiumLimit));
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
_addAccount->toggle(
|
2022-06-02 10:54:10 +00:00
|
|
|
(count < Main::Domain::kPremiumMaxAccounts),
|
2022-03-15 11:12:49 +00:00
|
|
|
anim::type::instant);
|
|
|
|
|
|
|
|
_reorder->start();
|
2018-09-09 17:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
Information::Information(
|
|
|
|
QWidget *parent,
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: Section(parent) {
|
2018-09-13 20:09:26 +00:00
|
|
|
setupContent(controller);
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
rpl::producer<QString> Information::title() {
|
2022-04-01 11:53:23 +00:00
|
|
|
return tr::lng_settings_section_info();
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void Information::setupContent(
|
|
|
|
not_null<Window::SessionController*> controller) {
|
2018-09-05 19:05:49 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto self = controller->session().user();
|
|
|
|
SetupPhoto(content, controller, self);
|
|
|
|
SetupBio(content, self);
|
2022-03-15 11:12:49 +00:00
|
|
|
SetupRows(content, controller, self);
|
|
|
|
SetupAccountsWrap(content, controller);
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
AccountsEvents SetupAccounts(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Window::SessionController*> controller) {
|
|
|
|
const auto list = container->lifetime().make_state<AccountsList>(
|
|
|
|
container,
|
|
|
|
controller);
|
|
|
|
return {
|
2023-04-23 14:21:31 +00:00
|
|
|
.closeRequests = list->closeRequests(),
|
2022-03-15 11:12:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-10 03:21:27 +00:00
|
|
|
void UpdatePhotoLocally(not_null<UserData*> user, const QImage &image) {
|
|
|
|
auto bytes = QByteArray();
|
|
|
|
auto buffer = QBuffer(&bytes);
|
|
|
|
image.save(&buffer, "JPG", 87);
|
|
|
|
user->setUserpic(
|
|
|
|
base::RandomValue<PhotoId>(),
|
|
|
|
ImageLocation(
|
|
|
|
{ .data = InMemoryLocation{ .bytes = bytes } },
|
|
|
|
image.width(),
|
|
|
|
image.height()),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
2022-06-13 22:43:13 +00:00
|
|
|
namespace Badge {
|
|
|
|
|
2022-12-19 11:48:24 +00:00
|
|
|
Ui::UnreadBadgeStyle Style() {
|
|
|
|
auto result = Ui::UnreadBadgeStyle();
|
2022-03-15 11:12:49 +00:00
|
|
|
result.font = st::mainMenuBadgeFont;
|
|
|
|
result.size = st::mainMenuBadgeSize;
|
2022-12-19 11:48:24 +00:00
|
|
|
result.sizeId = Ui::UnreadBadgeSize::MainMenu;
|
2022-03-15 11:12:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-06-13 22:43:13 +00:00
|
|
|
not_null<Ui::RpWidget*> AddRight(
|
|
|
|
not_null<Ui::SettingsButton*> button) {
|
|
|
|
const auto widget = Ui::CreateChild<Ui::RpWidget>(button.get());
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
button->sizeValue(),
|
|
|
|
widget->sizeValue(),
|
|
|
|
widget->shownValue()
|
|
|
|
) | rpl::start_with_next([=](QSize outer, QSize inner, bool shown) {
|
|
|
|
auto padding = button->st().padding;
|
|
|
|
if (shown) {
|
|
|
|
widget->moveToRight(
|
|
|
|
padding.right(),
|
|
|
|
(outer.height() - inner.height()) / 2,
|
|
|
|
outer.width());
|
2022-08-11 17:22:21 +00:00
|
|
|
padding.setRight(padding.right() + inner.width());
|
2022-06-13 22:43:13 +00:00
|
|
|
}
|
|
|
|
button->setPaddingOverride(padding);
|
2022-06-14 04:03:18 +00:00
|
|
|
button->update();
|
2022-06-13 22:43:13 +00:00
|
|
|
}, widget->lifetime());
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::RpWidget*> CreateUnread(
|
|
|
|
not_null<Ui::RpWidget*> container,
|
2022-03-15 11:12:49 +00:00
|
|
|
rpl::producer<UnreadBadge> value) {
|
|
|
|
struct State {
|
|
|
|
State(QWidget *parent) : widget(parent) {
|
|
|
|
widget.setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::RpWidget widget;
|
2022-12-19 11:48:24 +00:00
|
|
|
Ui::UnreadBadgeStyle st = Style();
|
2022-03-15 11:12:49 +00:00
|
|
|
int count = 0;
|
|
|
|
QString string;
|
|
|
|
};
|
2022-06-13 22:43:13 +00:00
|
|
|
const auto state = container->lifetime().make_state<State>(container);
|
2022-03-15 11:12:49 +00:00
|
|
|
|
|
|
|
std::move(
|
|
|
|
value
|
|
|
|
) | rpl::start_with_next([=](UnreadBadge badge) {
|
|
|
|
state->st.muted = badge.muted;
|
|
|
|
state->count = badge.count;
|
|
|
|
if (!state->count) {
|
|
|
|
state->widget.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
state->string = Lang::FormatCountToShort(state->count).string;
|
2022-12-19 11:48:24 +00:00
|
|
|
state->widget.resize(Ui::CountUnreadBadgeSize(state->string, state->st));
|
2022-03-15 11:12:49 +00:00
|
|
|
if (state->widget.isHidden()) {
|
|
|
|
state->widget.show();
|
|
|
|
}
|
|
|
|
}, state->widget.lifetime());
|
|
|
|
|
|
|
|
state->widget.paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = Painter(&state->widget);
|
2022-12-19 11:48:24 +00:00
|
|
|
Ui::PaintUnreadBadge(
|
2022-03-15 11:12:49 +00:00
|
|
|
p,
|
|
|
|
state->string,
|
|
|
|
state->widget.width(),
|
|
|
|
0,
|
|
|
|
state->st);
|
|
|
|
}, state->widget.lifetime());
|
|
|
|
|
2022-06-13 22:43:13 +00:00
|
|
|
return &state->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddUnread(
|
|
|
|
not_null<Ui::SettingsButton*> button,
|
|
|
|
rpl::producer<UnreadBadge> value) {
|
|
|
|
const auto container = AddRight(button);
|
|
|
|
const auto badge = CreateUnread(container, std::move(value));
|
|
|
|
badge->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
container->resize(s);
|
|
|
|
}, container->lifetime());
|
2022-03-15 11:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 22:43:13 +00:00
|
|
|
} // namespace Badge
|
2018-09-05 19:05:49 +00:00
|
|
|
} // namespace Settings
|