2015-04-02 10:33:19 +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.
|
2015-04-02 10:33:19 +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
|
2015-04-02 10:33:19 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/sessions_box.h"
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2020-09-08 15:01:12 +00:00
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "api/api_authorizations.h"
|
2020-09-05 14:33:53 +00:00
|
|
|
#include "base/timer.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2021-11-16 16:48:40 +00:00
|
|
|
#include "base/algorithm.h"
|
|
|
|
#include "base/platform/base_platform_info.h"
|
2021-11-25 20:52:06 +00:00
|
|
|
#include "boxes/self_destruction_box.h"
|
2021-11-30 16:38:47 +00:00
|
|
|
#include "boxes/peer_lists_box.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2020-09-05 14:48:15 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "main/main_session.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2021-11-16 16:48:40 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-11-20 10:03:44 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2020-09-05 14:48:15 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2018-11-20 10:03:44 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2021-11-30 12:06:41 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
2018-11-20 10:03:44 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2021-11-16 16:48:40 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2021-11-30 08:36:12 +00:00
|
|
|
#include "lottie/lottie_icon.h"
|
2021-11-16 16:48:40 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2020-09-05 14:48:15 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2021-11-25 15:46:37 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_settings.h"
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kSessionsShortPollTimeout = 60 * crl::time(1000);
|
2021-11-25 11:44:30 +00:00
|
|
|
constexpr auto kMaxDeviceModelLength = 32;
|
2021-11-16 16:48:40 +00:00
|
|
|
|
2021-11-26 13:01:37 +00:00
|
|
|
using EntryData = Api::Authorizations::Entry;
|
|
|
|
|
2021-11-30 08:36:12 +00:00
|
|
|
enum class Type {
|
|
|
|
Windows,
|
|
|
|
Mac,
|
|
|
|
Ubuntu,
|
|
|
|
Linux,
|
|
|
|
iPhone,
|
|
|
|
iPad,
|
|
|
|
Android,
|
|
|
|
Web,
|
|
|
|
Chrome,
|
|
|
|
Edge,
|
|
|
|
Firefox,
|
|
|
|
Safari,
|
|
|
|
Other,
|
|
|
|
};
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
class Row;
|
|
|
|
|
|
|
|
class RowDelegate {
|
|
|
|
public:
|
|
|
|
virtual void rowUpdateRow(not_null<Row*> row) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Row final : public PeerListRow {
|
|
|
|
public:
|
|
|
|
Row(not_null<RowDelegate*> delegate, const EntryData &data);
|
|
|
|
|
|
|
|
void update(const EntryData &data);
|
|
|
|
void updateName(const QString &name);
|
|
|
|
|
|
|
|
[[nodiscard]] EntryData data() const;
|
|
|
|
|
|
|
|
QString generateName() override;
|
|
|
|
QString generateShortName() override;
|
|
|
|
PaintRoundImageCallback generatePaintUserpicCallback() override;
|
|
|
|
|
|
|
|
int elementsCount() const override;
|
|
|
|
QRect elementGeometry(int element, int outerWidth) const override;
|
|
|
|
bool elementDisabled(int element) const override;
|
|
|
|
bool elementOnlySelect(int element) const override;
|
|
|
|
void elementAddRipple(
|
|
|
|
int element,
|
|
|
|
QPoint point,
|
|
|
|
Fn<void()> updateCallback) override;
|
|
|
|
void elementsStopLastRipple() override;
|
|
|
|
void elementsPaint(
|
|
|
|
Painter &p,
|
|
|
|
int outerWidth,
|
|
|
|
bool selected,
|
|
|
|
int selectedElement) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const not_null<RowDelegate*> _delegate;
|
|
|
|
Ui::Text::String _location;
|
|
|
|
Type _type = Type::Other;
|
|
|
|
EntryData _data;
|
|
|
|
QImage _userpic;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-11-16 16:48:40 +00:00
|
|
|
void RenameBox(not_null<Ui::GenericBox*> box) {
|
|
|
|
box->setTitle(tr::lng_settings_rename_device_title());
|
|
|
|
|
2021-11-25 15:46:37 +00:00
|
|
|
const auto skip = st::settingsSubsectionTitlePadding.top();
|
|
|
|
box->addRow(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
box,
|
|
|
|
tr::lng_settings_device_name(),
|
|
|
|
st::settingsSubsectionTitle),
|
|
|
|
st::boxRowPadding + style::margins(0, skip, 0, 0));
|
|
|
|
const auto name = box->addRow(
|
|
|
|
object_ptr<Ui::InputField>(
|
|
|
|
box,
|
|
|
|
st::settingsDeviceName,
|
|
|
|
rpl::single(Platform::DeviceModelPretty()),
|
|
|
|
Core::App().settings().customDeviceModel()),
|
|
|
|
st::boxRowPadding - style::margins(
|
|
|
|
st::settingsDeviceName.textMargins.left(),
|
|
|
|
0,
|
|
|
|
st::settingsDeviceName.textMargins.right(),
|
|
|
|
0));
|
2021-11-16 16:48:40 +00:00
|
|
|
name->setMaxLength(kMaxDeviceModelLength);
|
|
|
|
box->setFocusCallback([=] {
|
|
|
|
name->setFocusFast();
|
|
|
|
});
|
|
|
|
const auto submit = [=] {
|
|
|
|
const auto result = base::CleanAndSimplify(
|
|
|
|
name->getLastText());
|
|
|
|
box->closeBox();
|
|
|
|
Core::App().settings().setCustomDeviceModel(result);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
};
|
|
|
|
QObject::connect(name, &Ui::InputField::submitted, submit);
|
|
|
|
box->addButton(tr::lng_settings_save(), submit);
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
}
|
2018-11-20 10:03:44 +00:00
|
|
|
|
2021-11-26 13:01:37 +00:00
|
|
|
[[nodiscard]] QString LocationAndDate(const EntryData &entry) {
|
|
|
|
return (entry.location.isEmpty() ? entry.ip : entry.location)
|
|
|
|
+ (entry.hash
|
2021-11-29 13:29:45 +00:00
|
|
|
? (QString::fromUtf8(" \xE2\x80\xA2 ") + entry.active)
|
2021-11-26 13:01:37 +00:00
|
|
|
: QString());
|
|
|
|
}
|
|
|
|
|
2021-11-30 08:36:12 +00:00
|
|
|
[[nodiscard]] Type TypeFromEntry(const EntryData &entry) {
|
|
|
|
const auto platform = entry.platform.toLower();
|
|
|
|
const auto device = entry.name.toLower();
|
|
|
|
const auto system = entry.system.toLower();
|
|
|
|
const auto apiId = entry.apiId;
|
|
|
|
const auto kDesktop = std::array{ 2040, 17349, 611335 };
|
|
|
|
const auto kMac = std::array{ 2834 };
|
|
|
|
const auto kAndroid
|
|
|
|
= std::array{ 5, 6, 24, 1026, 1083, 2458, 2521, 21724 };
|
|
|
|
const auto kiOS = std::array{ 1, 7, 10840, 16352 };
|
|
|
|
const auto kWeb = std::array{ 2496, 739222, 1025907 };
|
|
|
|
|
|
|
|
const auto detectBrowser = [&]() -> std::optional<Type> {
|
|
|
|
if (device.contains("edg/")
|
|
|
|
|| device.contains("edgios/")
|
|
|
|
|| device.contains("edga/")) {
|
|
|
|
return Type::Edge;
|
|
|
|
} else if (device.contains("chrome")) {
|
|
|
|
return Type::Chrome;
|
|
|
|
} else if (device.contains("safari")) {
|
|
|
|
return Type::Safari;
|
|
|
|
} else if (device.contains("firefox")) {
|
|
|
|
return Type::Firefox;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
const auto detectDesktop = [&]() -> std::optional<Type> {
|
|
|
|
if (platform.contains("windows") || system.contains("windows")) {
|
|
|
|
return Type::Windows;
|
|
|
|
} else if (platform.contains("macos") || system.contains("macos")) {
|
|
|
|
return Type::Mac;
|
|
|
|
} else if (platform.contains("ubuntu")
|
|
|
|
|| system.contains("ubuntu")
|
|
|
|
|| platform.contains("unity")
|
|
|
|
|| system.contains("unity")) {
|
|
|
|
return Type::Ubuntu;
|
|
|
|
} else if (platform.contains("linux") || system.contains("linux")) {
|
|
|
|
return Type::Linux;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (ranges::contains(kAndroid, apiId)) {
|
|
|
|
return Type::Android;
|
|
|
|
} else if (ranges::contains(kDesktop, apiId)) {
|
|
|
|
return detectDesktop().value_or(Type::Linux);
|
|
|
|
} else if (ranges::contains(kMac, apiId)) {
|
|
|
|
return Type::Mac;
|
|
|
|
} else if (ranges::contains(kWeb, apiId)) {
|
|
|
|
return detectBrowser().value_or(Type::Web);
|
|
|
|
} else if (device.contains("chromebook")) {
|
|
|
|
return Type::Other;
|
|
|
|
} else if (const auto browser = detectBrowser()) {
|
|
|
|
return *browser;
|
|
|
|
} else if (device.contains("iphone")) {
|
|
|
|
return Type::iPhone;
|
|
|
|
} else if (device.contains("ipad")) {
|
|
|
|
return Type::iPad;
|
|
|
|
} else if (ranges::contains(kiOS, apiId)) {
|
|
|
|
return Type::iPhone;
|
|
|
|
} else if (const auto desktop = detectDesktop()) {
|
|
|
|
return *desktop;
|
|
|
|
} else if (platform.contains("android") || system.contains("android")) {
|
|
|
|
return Type::Android;
|
|
|
|
} else if (platform.contains("ios") || system.contains("ios")) {
|
|
|
|
return Type::iPhone;
|
|
|
|
}
|
|
|
|
return Type::Other;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] style::color ColorForType(Type type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Windows:
|
|
|
|
case Type::Mac:
|
|
|
|
case Type::Other:
|
|
|
|
return st::historyPeer4UserpicBg; // blue
|
|
|
|
case Type::Ubuntu:
|
|
|
|
return st::historyPeer8UserpicBg; // orange
|
|
|
|
case Type::Linux:
|
|
|
|
return st::historyPeer5UserpicBg; // purple
|
|
|
|
case Type::iPhone:
|
|
|
|
case Type::iPad:
|
|
|
|
return st::historyPeer7UserpicBg; // sea
|
|
|
|
case Type::Android:
|
|
|
|
return st::historyPeer2UserpicBg; // green
|
|
|
|
case Type::Web:
|
|
|
|
case Type::Chrome:
|
|
|
|
case Type::Edge:
|
|
|
|
case Type::Firefox:
|
|
|
|
case Type::Safari:
|
|
|
|
return st::historyPeer6UserpicBg; // pink
|
|
|
|
}
|
|
|
|
Unexpected("Type in ColorForType.");
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const style::icon &IconForType(Type type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Windows: return st::sessionIconWindows;
|
|
|
|
case Type::Mac: return st::sessionIconMac;
|
|
|
|
case Type::Ubuntu: return st::sessionIconUbuntu;
|
|
|
|
case Type::Linux: return st::sessionIconLinux;
|
|
|
|
case Type::iPhone: return st::sessionIconiPhone;
|
|
|
|
case Type::iPad: return st::sessionIconiPad;
|
|
|
|
case Type::Android: return st::sessionIconAndroid;
|
|
|
|
case Type::Web: return st::sessionIconWeb;
|
|
|
|
case Type::Chrome: return st::sessionIconChrome;
|
|
|
|
case Type::Edge: return st::sessionIconEdge;
|
|
|
|
case Type::Firefox: return st::sessionIconFirefox;
|
|
|
|
case Type::Safari: return st::sessionIconSafari;
|
|
|
|
case Type::Other: return st::sessionIconOther;
|
|
|
|
}
|
|
|
|
Unexpected("Type in IconForType.");
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:06:41 +00:00
|
|
|
[[nodiscard]] const style::icon *IconBigForType(Type type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Web: return &st::sessionBigIconWeb;
|
|
|
|
case Type::Other: return &st::sessionBigIconOther;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::unique_ptr<Lottie::Icon> LottieForType(Type type) {
|
|
|
|
if (IconBigForType(type)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto path = [&] {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Windows: return "device_desktop_win";
|
|
|
|
case Type::Mac: return "device_desktop_mac";
|
|
|
|
case Type::Ubuntu: return "device_linux_ubuntu";
|
|
|
|
case Type::Linux: return "device_linux";
|
|
|
|
case Type::iPhone: return "device_phone_ios";
|
|
|
|
case Type::iPad: return "device_tablet_ios";
|
|
|
|
case Type::Android: return "device_phone_android";
|
|
|
|
case Type::Chrome: return "device_web_chrome";
|
|
|
|
case Type::Edge: return "device_web_edge";
|
|
|
|
case Type::Firefox: return "device_web_firefox";
|
|
|
|
case Type::Safari: return "device_web_safari";
|
|
|
|
}
|
|
|
|
Unexpected("Type in LottieForType.");
|
|
|
|
}();
|
|
|
|
const auto size = st::sessionBigLottieSize;
|
2022-04-01 11:53:23 +00:00
|
|
|
return Lottie::MakeIcon({
|
2021-11-30 12:06:41 +00:00
|
|
|
.path = u":/icons/settings/devices/"_q + path + u".lottie"_q,
|
|
|
|
.sizeOverride = QSize(size, size),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-30 08:36:12 +00:00
|
|
|
[[nodiscard]] QImage GenerateUserpic(Type type) {
|
2021-11-30 16:38:47 +00:00
|
|
|
const auto size = st::sessionListItem.photoSize;
|
2021-11-30 08:36:12 +00:00
|
|
|
const auto full = size * style::DevicePixelRatio();
|
|
|
|
const auto rect = QRect(0, 0, size, size);
|
|
|
|
|
|
|
|
auto result = QImage(full, full, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
result.fill(Qt::transparent);
|
|
|
|
result.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
|
|
|
|
auto p = QPainter(&result);
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
p.setBrush(ColorForType(type));
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
IconForType(type).paintInCenter(p, rect);
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:06:41 +00:00
|
|
|
[[nodiscard]] not_null<Ui::RpWidget*> GenerateUserpicBig(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
rpl::producer<> shown,
|
|
|
|
Type type) {
|
|
|
|
const auto size = st::sessionBigUserpicSize;
|
|
|
|
const auto full = size * style::DevicePixelRatio();
|
|
|
|
const auto rect = QRect(0, 0, size, size);
|
|
|
|
|
|
|
|
const auto result = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
|
|
|
result->resize(rect.size());
|
|
|
|
struct State {
|
|
|
|
QImage background;
|
|
|
|
std::unique_ptr<Lottie::Icon> lottie;
|
|
|
|
QImage lottieFrame;
|
|
|
|
QImage colorizedFrame;
|
|
|
|
};
|
|
|
|
const auto state = result->lifetime().make_state<State>();
|
|
|
|
state->background = QImage(
|
|
|
|
full,
|
|
|
|
full,
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
state->background.fill(Qt::transparent);
|
|
|
|
state->background.setDevicePixelRatio(style::DevicePixelRatio());
|
|
|
|
state->colorizedFrame = state->lottieFrame = state->background;
|
|
|
|
|
|
|
|
auto p = QPainter(&state->background);
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
p.setBrush(ColorForType(type));
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawEllipse(rect);
|
|
|
|
if (const auto icon = IconBigForType(type)) {
|
|
|
|
icon->paintInCenter(p, rect);
|
|
|
|
}
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
if ((state->lottie = LottieForType(type))) {
|
|
|
|
std::move(
|
|
|
|
shown
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
state->lottie->animate(
|
|
|
|
[=] { result->update(); },
|
|
|
|
0,
|
2022-01-06 11:16:14 +00:00
|
|
|
state->lottie->framesCount() - 1);
|
2021-11-30 12:06:41 +00:00
|
|
|
}, result->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
result->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = QPainter(result);
|
|
|
|
p.drawImage(QPoint(0, 0), state->background);
|
|
|
|
if (state->lottie) {
|
|
|
|
state->lottieFrame.fill(Qt::black);
|
|
|
|
auto q = QPainter(&state->lottieFrame);
|
|
|
|
state->lottie->paintInCenter(q, result->rect());
|
|
|
|
q.end();
|
|
|
|
style::colorizeImage(
|
|
|
|
state->lottieFrame,
|
|
|
|
st::historyPeerUserpicFg->c,
|
|
|
|
&state->colorizedFrame);
|
|
|
|
p.drawImage(QPoint(0, 0), state->colorizedFrame);
|
|
|
|
|
|
|
|
}
|
|
|
|
}, result->lifetime());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SessionInfoBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
const EntryData &data,
|
|
|
|
Fn<void(uint64)> terminate) {
|
|
|
|
box->setWidth(st::boxWideWidth);
|
|
|
|
|
|
|
|
const auto shown = box->lifetime().make_state<rpl::event_stream<>>();
|
|
|
|
box->setShowFinishedCallback([=] {
|
|
|
|
shown->fire({});
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto userpicWrap = box->addRow(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(box, st::sessionBigUserpicSize),
|
|
|
|
st::sessionBigCoverPadding);
|
|
|
|
const auto big = GenerateUserpicBig(
|
|
|
|
userpicWrap,
|
|
|
|
shown->events(),
|
|
|
|
TypeFromEntry(data));
|
|
|
|
userpicWrap->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](QSize size) {
|
|
|
|
big->move((size.width() - big->width()) / 2, 0);
|
|
|
|
}, userpicWrap->lifetime());
|
|
|
|
|
|
|
|
const auto nameWrap = box->addRow(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
box,
|
|
|
|
st::sessionBigName.maxHeight));
|
|
|
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
nameWrap,
|
|
|
|
rpl::single(data.name),
|
|
|
|
st::sessionBigName);
|
|
|
|
nameWrap->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
name->resizeToWidth(width);
|
|
|
|
name->move((width - name->width()) / 2, 0);
|
|
|
|
}, name->lifetime());
|
|
|
|
|
|
|
|
const auto dateWrap = box->addRow(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
box,
|
|
|
|
st::sessionDateLabel.style.font->height),
|
|
|
|
style::margins(0, 0, 0, st::sessionDateSkip));
|
|
|
|
const auto date = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
dateWrap,
|
|
|
|
rpl::single(
|
|
|
|
langDateTimeFull(base::unixtime::parse(data.activeTime))),
|
|
|
|
st::sessionDateLabel);
|
|
|
|
rpl::combine(
|
|
|
|
dateWrap->widthValue(),
|
|
|
|
date->widthValue()
|
|
|
|
) | rpl::start_with_next([=](int outer, int inner) {
|
|
|
|
date->move((outer - inner) / 2, 0);
|
|
|
|
}, date->lifetime());
|
|
|
|
|
|
|
|
using namespace Settings;
|
|
|
|
const auto container = box->verticalLayout();
|
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container, st::sessionSubtitleSkip);
|
|
|
|
AddSubsectionTitle(container, tr::lng_sessions_info());
|
|
|
|
|
|
|
|
const auto add = [&](rpl::producer<QString> label, QString value) {
|
|
|
|
if (value.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
rpl::single(value),
|
|
|
|
st::boxLabel),
|
|
|
|
st::boxRowPadding + st::sessionValuePadding);
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
std::move(label),
|
|
|
|
st::sessionValueLabel),
|
|
|
|
(st::boxRowPadding
|
|
|
|
+ style::margins{ 0, 0, 0, st::sessionValueSkip }));
|
|
|
|
};
|
|
|
|
add(tr::lng_sessions_application(), data.info);
|
|
|
|
add(tr::lng_sessions_system(), data.system);
|
|
|
|
add(tr::lng_sessions_ip(), data.ip);
|
|
|
|
add(tr::lng_sessions_location(), data.location);
|
|
|
|
AddSkip(container, st::sessionValueSkip);
|
|
|
|
if (!data.location.isEmpty()) {
|
|
|
|
AddDividerText(container, tr::lng_sessions_location_about());
|
|
|
|
}
|
|
|
|
|
|
|
|
box->addButton(tr::lng_about_done(), [=] { box->closeBox(); });
|
|
|
|
if (const auto hash = data.hash) {
|
|
|
|
box->addLeftButton(tr::lng_sessions_terminate(), [=] {
|
|
|
|
const auto weak = Ui::MakeWeak(box.get());
|
|
|
|
terminate(hash);
|
|
|
|
if (weak) {
|
|
|
|
box->closeBox();
|
|
|
|
}
|
|
|
|
}, st::attentionBoxButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
Row::Row(not_null<RowDelegate*> delegate, const EntryData &data)
|
|
|
|
: PeerListRow(data.hash)
|
|
|
|
, _delegate(delegate)
|
|
|
|
, _location(st::defaultTextStyle, LocationAndDate(data))
|
|
|
|
, _type(TypeFromEntry(data))
|
|
|
|
, _data(data)
|
|
|
|
, _userpic(GenerateUserpic(_type)) {
|
|
|
|
setCustomStatus(_data.info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::update(const EntryData &data) {
|
|
|
|
_data = data;
|
|
|
|
setCustomStatus(_data.info);
|
|
|
|
refreshName(st::sessionListItem);
|
|
|
|
_location.setText(st::defaultTextStyle, LocationAndDate(_data));
|
2021-11-30 16:58:53 +00:00
|
|
|
_type = TypeFromEntry(_data);
|
|
|
|
_userpic = GenerateUserpic(_type);
|
2021-11-30 16:38:47 +00:00
|
|
|
_delegate->rowUpdateRow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::updateName(const QString &name) {
|
|
|
|
_data.name = name;
|
|
|
|
refreshName(st::sessionListItem);
|
|
|
|
_delegate->rowUpdateRow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
EntryData Row::data() const {
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Row::generateName() {
|
|
|
|
return _data.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Row::generateShortName() {
|
|
|
|
return generateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintRoundImageCallback Row::generatePaintUserpicCallback() {
|
|
|
|
return [=](
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2021-11-30 16:38:47 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int outerWidth,
|
|
|
|
int size) {
|
|
|
|
p.drawImage(x, y, _userpic);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
int Row::elementsCount() const {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Row::elementGeometry(int element, int outerWidth) const {
|
|
|
|
switch (element) {
|
|
|
|
case 1: {
|
|
|
|
return QRect(
|
|
|
|
st::sessionListItem.namePosition.x(),
|
|
|
|
st::sessionLocationTop,
|
|
|
|
outerWidth,
|
|
|
|
st::normalFont->height);
|
|
|
|
} break;
|
|
|
|
case 2: {
|
|
|
|
const auto size = QSize(
|
2021-11-30 16:58:53 +00:00
|
|
|
st::sessionTerminate.width,
|
|
|
|
st::sessionTerminate.height);
|
|
|
|
const auto right = st::sessionTerminateSkip;
|
|
|
|
const auto top = st::sessionTerminateTop;
|
2021-11-30 16:38:47 +00:00
|
|
|
const auto left = outerWidth - right - size.width();
|
|
|
|
return QRect(QPoint(left, top), size);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Row::elementDisabled(int element) const {
|
|
|
|
return !id() || (element == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Row::elementOnlySelect(int element) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::elementAddRipple(
|
|
|
|
int element,
|
|
|
|
QPoint point,
|
|
|
|
Fn<void()> updateCallback) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::elementsStopLastRipple() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Row::elementsPaint(
|
|
|
|
Painter &p,
|
|
|
|
int outerWidth,
|
|
|
|
bool selected,
|
|
|
|
int selectedElement) {
|
|
|
|
if (id()) {
|
|
|
|
const auto geometry = elementGeometry(2, outerWidth);
|
2021-11-30 16:58:53 +00:00
|
|
|
const auto position = geometry.topLeft()
|
|
|
|
+ st::sessionTerminate.iconPosition;
|
2021-11-30 16:38:47 +00:00
|
|
|
const auto &icon = (selectedElement == 2)
|
2021-11-30 16:58:53 +00:00
|
|
|
? st::sessionTerminate.iconOver
|
|
|
|
: st::sessionTerminate.icon;
|
|
|
|
icon.paint(p, position.x(), position.y(), outerWidth);
|
2021-11-30 16:38:47 +00:00
|
|
|
}
|
|
|
|
p.setFont(st::msgFont);
|
|
|
|
p.setPen(st::sessionInfoFg);
|
|
|
|
const auto locationLeft = st::sessionListItem.namePosition.x();
|
|
|
|
const auto available = outerWidth - locationLeft;
|
|
|
|
_location.drawLeftElided(
|
|
|
|
p,
|
|
|
|
locationLeft,
|
|
|
|
st::sessionLocationTop,
|
|
|
|
available,
|
|
|
|
outerWidth);
|
|
|
|
}
|
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
class SessionsContent : public Ui::RpWidget {
|
|
|
|
public:
|
2021-11-25 20:52:06 +00:00
|
|
|
SessionsContent(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Window::SessionController*> controller);
|
2020-09-05 14:33:53 +00:00
|
|
|
|
|
|
|
void setupContent();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Full {
|
2021-11-30 16:38:47 +00:00
|
|
|
EntryData current;
|
|
|
|
std::vector<EntryData> incomplete;
|
|
|
|
std::vector<EntryData> list;
|
2020-09-05 14:33:53 +00:00
|
|
|
};
|
|
|
|
class Inner;
|
2021-11-30 16:38:47 +00:00
|
|
|
class ListController;
|
2020-09-05 14:33:53 +00:00
|
|
|
|
|
|
|
void shortPollSessions();
|
2020-09-18 19:04:18 +00:00
|
|
|
void parse(const Api::Authorizations::List &list);
|
2020-09-05 14:33:53 +00:00
|
|
|
|
|
|
|
void terminate(Fn<void()> terminateRequest, QString message);
|
|
|
|
void terminateOne(uint64 hash);
|
|
|
|
void terminateAll();
|
|
|
|
|
2021-11-26 13:01:37 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
2020-09-08 15:01:12 +00:00
|
|
|
const not_null<Api::Authorizations*> _authorizations;
|
2020-09-05 14:33:53 +00:00
|
|
|
|
|
|
|
rpl::variable<bool> _loading = false;
|
|
|
|
Full _data;
|
|
|
|
|
|
|
|
object_ptr<Inner> _inner;
|
2022-02-27 08:23:20 +00:00
|
|
|
QPointer<Ui::BoxContent> _terminateBox;
|
2020-09-05 14:33:53 +00:00
|
|
|
|
|
|
|
base::Timer _shortPollTimer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
class SessionsContent::ListController final
|
|
|
|
: public PeerListController
|
|
|
|
, public RowDelegate
|
|
|
|
, public base::has_weak_ptr {
|
2018-11-20 10:03:44 +00:00
|
|
|
public:
|
2021-11-30 16:38:47 +00:00
|
|
|
explicit ListController(not_null<Main::Session*> session);
|
2018-11-20 10:03:44 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
Main::Session &session() const override;
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
void rowElementClicked(not_null<PeerListRow*> row, int element) override;
|
|
|
|
|
|
|
|
void rowUpdateRow(not_null<Row*> row) override;
|
|
|
|
|
|
|
|
void showData(gsl::span<const EntryData> items);
|
2018-11-20 10:03:44 +00:00
|
|
|
rpl::producer<int> itemsCount() const;
|
2021-11-26 13:01:37 +00:00
|
|
|
rpl::producer<uint64> terminateRequests() const;
|
|
|
|
[[nodiscard]] rpl::producer<EntryData> showRequests() const;
|
2018-11-20 10:03:44 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
[[nodiscard]] static std::unique_ptr<ListController> Add(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
style::margins margins = {});
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
private:
|
2021-11-16 16:48:40 +00:00
|
|
|
void subscribeToCustomDeviceModel();
|
2020-09-11 12:28:49 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
2021-11-26 13:01:37 +00:00
|
|
|
rpl::event_stream<uint64> _terminateRequests;
|
2018-11-20 10:03:44 +00:00
|
|
|
rpl::event_stream<int> _itemsCount;
|
2021-11-26 13:01:37 +00:00
|
|
|
rpl::event_stream<EntryData> _showRequests;
|
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
};
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
class SessionsContent::Inner : public Ui::RpWidget {
|
2018-11-20 10:03:44 +00:00
|
|
|
public:
|
2021-11-25 20:52:06 +00:00
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<int> ttlDays);
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
void showData(const Full &data);
|
2021-11-26 13:01:37 +00:00
|
|
|
[[nodiscard]] rpl::producer<EntryData> showRequests() const;
|
|
|
|
[[nodiscard]] rpl::producer<uint64> terminateOne() const;
|
|
|
|
[[nodiscard]] rpl::producer<> terminateAll() const;
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setupContent();
|
|
|
|
|
2021-11-25 20:52:06 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
2021-11-30 16:38:47 +00:00
|
|
|
std::unique_ptr<ListController> _current;
|
2019-11-02 17:06:47 +00:00
|
|
|
QPointer<Ui::SettingsButton> _terminateAll;
|
2021-11-30 16:38:47 +00:00
|
|
|
std::unique_ptr<ListController> _incomplete;
|
|
|
|
std::unique_ptr<ListController> _list;
|
2021-11-25 20:52:06 +00:00
|
|
|
rpl::variable<int> _ttlDays;
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
};
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
//, location(st::sessionInfoStyle, LocationAndDate(entry))
|
2021-11-30 08:36:12 +00:00
|
|
|
|
2021-11-25 20:52:06 +00:00
|
|
|
SessionsContent::SessionsContent(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Window::SessionController*> controller)
|
2021-11-26 13:01:37 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _authorizations(&controller->session().api().authorizations())
|
2021-11-25 20:52:06 +00:00
|
|
|
, _inner(this, controller, _authorizations->ttlDays())
|
2019-07-25 18:55:11 +00:00
|
|
|
, _shortPollTimer([=] { shortPollSessions(); }) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::setupContent() {
|
2018-06-03 19:52:23 +00:00
|
|
|
_inner->resize(width(), st::noContactsHeight);
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
_inner->heightValue(
|
|
|
|
) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
resize(width(), height);
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
2021-11-26 13:01:37 +00:00
|
|
|
_inner->showRequests(
|
|
|
|
) | rpl::start_with_next([=](const EntryData &data) {
|
|
|
|
_controller->show(Box(
|
|
|
|
SessionInfoBox,
|
|
|
|
data,
|
|
|
|
[=](uint64 hash) { terminateOne(hash); }));
|
|
|
|
}, lifetime());
|
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
_inner->terminateOne(
|
|
|
|
) | rpl::start_with_next([=](uint64 hash) {
|
|
|
|
terminateOne(hash);
|
|
|
|
}, lifetime());
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
_inner->terminateAll(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
terminateAll();
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-09-05 09:54:23 +00:00
|
|
|
_loading.changes(
|
|
|
|
) | rpl::start_with_next([=](bool value) {
|
2020-09-05 14:33:53 +00:00
|
|
|
_inner->setVisible(!value);
|
2020-09-05 09:54:23 +00:00
|
|
|
}, lifetime());
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2020-09-08 15:01:12 +00:00
|
|
|
_authorizations->listChanges(
|
|
|
|
) | rpl::start_with_next([=](const Api::Authorizations::List &list) {
|
2020-09-18 19:04:18 +00:00
|
|
|
parse(list);
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_loading = true;
|
|
|
|
shortPollSessions();
|
|
|
|
}
|
2020-09-08 15:01:12 +00:00
|
|
|
|
2020-09-18 19:04:18 +00:00
|
|
|
void SessionsContent::parse(const Api::Authorizations::List &list) {
|
2020-10-01 15:09:36 +00:00
|
|
|
if (list.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-18 19:04:18 +00:00
|
|
|
_data = Full();
|
|
|
|
for (const auto &auth : list) {
|
2021-11-30 16:38:47 +00:00
|
|
|
if (!auth.hash) {
|
|
|
|
_data.current = auth;
|
|
|
|
} else if (auth.incomplete) {
|
|
|
|
_data.incomplete.push_back(auth);
|
2020-09-18 19:04:18 +00:00
|
|
|
} else {
|
2021-11-30 16:38:47 +00:00
|
|
|
_data.list.push_back(auth);
|
2020-09-18 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-08 15:01:12 +00:00
|
|
|
|
2020-09-18 19:04:18 +00:00
|
|
|
_loading = false;
|
2020-09-08 15:01:12 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
ranges::sort(_data.list, std::greater<>(), &EntryData::activeTime);
|
|
|
|
ranges::sort(_data.incomplete, std::greater<>(), &EntryData::activeTime);
|
2020-09-08 15:01:12 +00:00
|
|
|
|
2020-09-18 19:04:18 +00:00
|
|
|
_inner->showData(_data);
|
2020-09-08 15:01:12 +00:00
|
|
|
|
2020-09-18 19:04:18 +00:00
|
|
|
_shortPollTimer.callOnce(kSessionsShortPollTimeout);
|
2016-11-18 13:34:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::resizeEvent(QResizeEvent *e) {
|
|
|
|
RpWidget::resizeEvent(e);
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
_inner->resize(width(), _inner->height());
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::paintEvent(QPaintEvent *e) {
|
|
|
|
RpWidget::paintEvent(e);
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
Painter p(this);
|
|
|
|
|
2020-09-05 09:54:23 +00:00
|
|
|
if (_loading.current()) {
|
2016-11-18 13:34:58 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2018-11-20 10:03:44 +00:00
|
|
|
p.drawText(
|
|
|
|
QRect(0, 0, width(), st::noContactsHeight),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_contacts_loading(tr::now),
|
2018-11-20 10:03:44 +00:00
|
|
|
style::al_center);
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::shortPollSessions() {
|
2020-09-18 19:04:18 +00:00
|
|
|
const auto left = kSessionsShortPollTimeout
|
|
|
|
- (crl::now() - _authorizations->lastReceivedTime());
|
|
|
|
if (left > 0) {
|
|
|
|
parse(_authorizations->list());
|
|
|
|
_shortPollTimer.cancel();
|
|
|
|
_shortPollTimer.callOnce(left);
|
|
|
|
} else {
|
|
|
|
_authorizations->reload();
|
|
|
|
}
|
2018-11-20 10:03:44 +00:00
|
|
|
update();
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::terminate(Fn<void()> terminateRequest, QString message) {
|
2020-09-05 10:08:00 +00:00
|
|
|
if (_terminateBox) {
|
|
|
|
_terminateBox->deleteLater();
|
|
|
|
}
|
2018-11-20 10:03:44 +00:00
|
|
|
const auto callback = crl::guard(this, [=] {
|
|
|
|
if (_terminateBox) {
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
}
|
2020-09-05 10:08:00 +00:00
|
|
|
terminateRequest();
|
|
|
|
});
|
2022-02-27 08:23:20 +00:00
|
|
|
auto box = Ui::MakeConfirmBox({
|
|
|
|
.text = message,
|
|
|
|
.confirmed = callback,
|
|
|
|
.confirmText = tr::lng_settings_reset_button(),
|
|
|
|
.confirmStyle = &st::attentionBoxButton,
|
|
|
|
});
|
2022-02-23 04:43:33 +00:00
|
|
|
_terminateBox = Ui::MakeWeak(box.data());
|
|
|
|
_controller->show(std::move(box), Ui::LayerOption::KeepOther);
|
2020-09-05 10:08:00 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::terminateOne(uint64 hash) {
|
2020-09-08 15:01:12 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2020-09-05 10:08:00 +00:00
|
|
|
auto callback = [=] {
|
2020-09-08 15:01:12 +00:00
|
|
|
auto done = crl::guard(weak, [=](const MTPBool &result) {
|
2021-02-16 22:25:57 +00:00
|
|
|
if (mtpIsFalse(result)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-30 16:38:47 +00:00
|
|
|
const auto removeByHash = [&](std::vector<EntryData> &list) {
|
2018-11-20 10:03:44 +00:00
|
|
|
list.erase(
|
2021-11-26 13:01:37 +00:00
|
|
|
ranges::remove(
|
|
|
|
list,
|
|
|
|
hash,
|
2021-11-30 16:38:47 +00:00
|
|
|
[](const EntryData &entry) { return entry.hash; }),
|
2018-11-20 10:03:44 +00:00
|
|
|
end(list));
|
|
|
|
};
|
|
|
|
removeByHash(_data.incomplete);
|
|
|
|
removeByHash(_data.list);
|
|
|
|
_inner->showData(_data);
|
2020-09-08 15:01:12 +00:00
|
|
|
});
|
2021-03-12 12:48:00 +00:00
|
|
|
auto fail = crl::guard(weak, [=](const MTP::Error &error) {
|
2020-09-08 15:01:12 +00:00
|
|
|
});
|
|
|
|
_authorizations->requestTerminate(
|
|
|
|
std::move(done),
|
|
|
|
std::move(fail),
|
|
|
|
hash);
|
2020-09-05 10:08:00 +00:00
|
|
|
};
|
|
|
|
terminate(std::move(callback), tr::lng_settings_reset_one_sure(tr::now));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::terminateAll() {
|
2020-09-08 15:01:12 +00:00
|
|
|
const auto weak = Ui::MakeWeak(this);
|
2020-09-05 10:08:00 +00:00
|
|
|
auto callback = [=] {
|
2020-09-08 15:01:12 +00:00
|
|
|
const auto reset = crl::guard(weak, [=] {
|
|
|
|
_authorizations->cancelCurrentRequest();
|
2020-12-15 14:23:41 +00:00
|
|
|
_authorizations->reload();
|
2020-09-08 15:01:12 +00:00
|
|
|
});
|
|
|
|
_authorizations->requestTerminate(
|
|
|
|
[=](const MTPBool &result) { reset(); },
|
2021-03-12 12:48:00 +00:00
|
|
|
[=](const MTP::Error &result) { reset(); });
|
2020-09-05 09:54:23 +00:00
|
|
|
_loading = true;
|
2020-09-05 10:08:00 +00:00
|
|
|
};
|
|
|
|
terminate(std::move(callback), tr::lng_settings_reset_sure(tr::now));
|
2015-04-02 10:33:19 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:52:06 +00:00
|
|
|
SessionsContent::Inner::Inner(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
rpl::producer<int> ttlDays)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _controller(controller)
|
|
|
|
, _ttlDays(std::move(ttlDays)) {
|
2018-11-20 10:03:44 +00:00
|
|
|
setupContent();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::Inner::setupContent() {
|
2018-11-20 10:03:44 +00:00
|
|
|
using namespace Settings;
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2021-11-16 16:48:40 +00:00
|
|
|
const auto header = AddSubsectionTitle(
|
|
|
|
content,
|
|
|
|
tr::lng_sessions_header());
|
|
|
|
const auto rename = Ui::CreateChild<Ui::LinkButton>(
|
|
|
|
content,
|
|
|
|
tr::lng_settings_rename_device(tr::now),
|
|
|
|
st::defaultLinkButton);
|
|
|
|
rpl::combine(
|
|
|
|
content->sizeValue(),
|
|
|
|
header->positionValue()
|
|
|
|
) | rpl::start_with_next([=](QSize outer, QPoint position) {
|
|
|
|
const auto x = st::sessionTerminateSkip
|
|
|
|
+ st::sessionTerminate.iconPosition.x();
|
|
|
|
const auto y = st::settingsSubsectionTitlePadding.top()
|
|
|
|
+ st::settingsSubsectionTitle.style.font->ascent
|
|
|
|
- st::defaultLinkButton.font->ascent;
|
|
|
|
rename->moveToRight(x, y, outer.width());
|
|
|
|
}, rename->lifetime());
|
|
|
|
rename->setClickedCallback([=] {
|
2022-02-23 04:43:33 +00:00
|
|
|
_controller->show(Box(RenameBox), Ui::LayerOption::KeepOther);
|
2021-11-16 16:48:40 +00:00
|
|
|
});
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
const auto session = &_controller->session();
|
|
|
|
_current = ListController::Add(
|
|
|
|
content,
|
|
|
|
session,
|
2021-11-30 08:36:12 +00:00
|
|
|
style::margins{ 0, 0, 0, st::sessionCurrentSkip });
|
2018-11-20 10:03:44 +00:00
|
|
|
const auto terminateWrap = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
const auto terminateInner = terminateWrap->entity();
|
|
|
|
_terminateAll = terminateInner->add(
|
2021-11-30 08:36:12 +00:00
|
|
|
CreateButton(
|
2018-11-20 10:03:44 +00:00
|
|
|
terminateInner,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_sessions_terminate_all(),
|
2022-02-25 13:11:49 +00:00
|
|
|
st::infoBlockButton,
|
|
|
|
{ .icon = &st::infoIconBlock }));
|
2018-11-20 10:03:44 +00:00
|
|
|
AddSkip(terminateInner);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddDividerText(terminateInner, tr::lng_sessions_terminate_all_about());
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
const auto incompleteWrap = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
const auto incompleteInner = incompleteWrap->entity();
|
2021-11-30 08:36:12 +00:00
|
|
|
AddSkip(incompleteInner, st::sessionSubtitleSkip);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(incompleteInner, tr::lng_sessions_incomplete());
|
2021-11-30 16:38:47 +00:00
|
|
|
_incomplete = ListController::Add(incompleteInner, session);
|
2018-11-20 10:03:44 +00:00
|
|
|
AddSkip(incompleteInner);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddDividerText(incompleteInner, tr::lng_sessions_incomplete_about());
|
2018-11-20 10:03:44 +00:00
|
|
|
|
|
|
|
const auto listWrap = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
const auto listInner = listWrap->entity();
|
2021-11-30 08:36:12 +00:00
|
|
|
AddSkip(listInner, st::sessionSubtitleSkip);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(listInner, tr::lng_sessions_other_header());
|
2021-11-30 16:38:47 +00:00
|
|
|
_list = ListController::Add(listInner, session);
|
2018-11-20 10:03:44 +00:00
|
|
|
AddSkip(listInner);
|
2021-11-30 08:36:12 +00:00
|
|
|
AddDividerText(listInner, tr::lng_sessions_about_apps());
|
2018-11-20 10:03:44 +00:00
|
|
|
|
2021-11-25 20:52:06 +00:00
|
|
|
const auto ttlWrap = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
const auto ttlInner = ttlWrap->entity();
|
2021-11-30 08:36:12 +00:00
|
|
|
AddSkip(ttlInner, st::sessionSubtitleSkip);
|
2021-11-25 20:52:06 +00:00
|
|
|
AddSubsectionTitle(ttlInner, tr::lng_settings_terminate_title());
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
|
|
|
ttlInner,
|
|
|
|
tr::lng_settings_terminate_if(),
|
2022-02-13 13:30:43 +00:00
|
|
|
_ttlDays.value() | rpl::map(SelfDestructionBox::DaysLabel),
|
|
|
|
st::settingsButtonNoIcon
|
2021-11-25 20:52:06 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
_controller->show(Box<SelfDestructionBox>(
|
|
|
|
&_controller->session(),
|
|
|
|
SelfDestructionBox::Type::Sessions,
|
|
|
|
_ttlDays.value()));
|
|
|
|
});
|
|
|
|
|
|
|
|
AddSkip(ttlInner);
|
|
|
|
|
2018-11-20 10:03:44 +00:00
|
|
|
const auto placeholder = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_sessions_other_desc(),
|
2018-11-20 10:03:44 +00:00
|
|
|
st::boxDividerLabel),
|
|
|
|
st::settingsDividerLabelPadding))->setDuration(0);
|
|
|
|
|
|
|
|
terminateWrap->toggleOn(
|
|
|
|
rpl::combine(
|
|
|
|
_incomplete->itemsCount(),
|
|
|
|
_list->itemsCount(),
|
|
|
|
(_1 + _2) > 0));
|
|
|
|
incompleteWrap->toggleOn(_incomplete->itemsCount() | rpl::map(_1 > 0));
|
|
|
|
listWrap->toggleOn(_list->itemsCount() | rpl::map(_1 > 0));
|
2021-11-25 20:52:06 +00:00
|
|
|
ttlWrap->toggleOn(_list->itemsCount() | rpl::map(_1 > 0));
|
2018-11-20 10:03:44 +00:00
|
|
|
placeholder->toggleOn(_list->itemsCount() | rpl::map(_1 == 0));
|
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
void SessionsContent::Inner::showData(const Full &data) {
|
2018-11-20 10:03:44 +00:00
|
|
|
_current->showData({ &data.current, &data.current + 1 });
|
|
|
|
_list->showData(data.list);
|
|
|
|
_incomplete->showData(data.incomplete);
|
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
rpl::producer<> SessionsContent::Inner::terminateAll() const {
|
2020-06-21 16:25:29 +00:00
|
|
|
return _terminateAll->clicks() | rpl::to_empty;
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2020-09-05 14:33:53 +00:00
|
|
|
rpl::producer<uint64> SessionsContent::Inner::terminateOne() const {
|
2018-11-20 10:03:44 +00:00
|
|
|
return rpl::merge(
|
2021-11-26 13:01:37 +00:00
|
|
|
_incomplete->terminateRequests(),
|
|
|
|
_list->terminateRequests());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<EntryData> SessionsContent::Inner::showRequests() const {
|
|
|
|
return rpl::merge(
|
2021-11-30 12:06:41 +00:00
|
|
|
_current->showRequests(),
|
2021-11-26 13:01:37 +00:00
|
|
|
_incomplete->showRequests(),
|
|
|
|
_list->showRequests());
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
SessionsContent::ListController::ListController(
|
|
|
|
not_null<Main::Session*> session)
|
|
|
|
: _session(session) {
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
Main::Session &SessionsContent::ListController::session() const {
|
|
|
|
return *_session;
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::subscribeToCustomDeviceModel() {
|
2021-11-16 16:48:40 +00:00
|
|
|
Core::App().settings().deviceModelChanges(
|
|
|
|
) | rpl::start_with_next([=](const QString &model) {
|
2021-11-30 16:38:47 +00:00
|
|
|
for (auto i = 0; i != delegate()->peerListFullRowsCount(); ++i) {
|
|
|
|
const auto row = delegate()->peerListRowAt(i);
|
|
|
|
if (!row->id()) {
|
|
|
|
static_cast<Row*>(row.get())->updateName(model);
|
2021-11-16 16:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::prepare() {
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::rowClicked(
|
|
|
|
not_null<PeerListRow*> row) {
|
|
|
|
_showRequests.fire_copy(static_cast<Row*>(row.get())->data());
|
2021-11-26 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::rowElementClicked(
|
|
|
|
not_null<PeerListRow*> row,
|
|
|
|
int element) {
|
2021-11-30 16:58:53 +00:00
|
|
|
if (element == 2) {
|
2021-11-30 16:38:47 +00:00
|
|
|
if (const auto hash = static_cast<Row*>(row.get())->data().hash) {
|
|
|
|
_terminateRequests.fire_copy(hash);
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 10:03:44 +00:00
|
|
|
}
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::rowUpdateRow(not_null<Row*> row) {
|
|
|
|
delegate()->peerListUpdateRow(row);
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
void SessionsContent::ListController::showData(
|
|
|
|
gsl::span<const EntryData> items) {
|
|
|
|
auto index = 0;
|
|
|
|
auto positions = base::flat_map<uint64, int>();
|
|
|
|
positions.reserve(items.size());
|
|
|
|
for (const auto &entry : items) {
|
|
|
|
const auto id = entry.hash;
|
|
|
|
positions.emplace(id, index++);
|
|
|
|
if (const auto row = delegate()->peerListFindRow(id)) {
|
|
|
|
static_cast<Row*>(row)->update(entry);
|
2018-11-20 10:03:44 +00:00
|
|
|
} else {
|
2021-11-30 16:38:47 +00:00
|
|
|
delegate()->peerListAppendRow(
|
|
|
|
std::make_unique<Row>(this, entry));
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-30 16:38:47 +00:00
|
|
|
for (auto i = 0; i != delegate()->peerListFullRowsCount();) {
|
|
|
|
const auto row = delegate()->peerListRowAt(i);
|
|
|
|
if (positions.contains(row->id())) {
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
delegate()->peerListRemoveRow(row);
|
|
|
|
}
|
|
|
|
delegate()->peerListSortRows([&](
|
|
|
|
const PeerListRow &a,
|
|
|
|
const PeerListRow &b) {
|
|
|
|
return positions[a.id()] < positions[b.id()];
|
|
|
|
});
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
_itemsCount.fire(delegate()->peerListFullRowsCount());
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
rpl::producer<int> SessionsContent::ListController::itemsCount() const {
|
|
|
|
return _itemsCount.events_starting_with(
|
|
|
|
delegate()->peerListFullRowsCount());
|
2020-09-11 12:28:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
rpl::producer<uint64> SessionsContent::ListController::terminateRequests() const {
|
|
|
|
return _terminateRequests.events();
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
2020-09-05 14:33:53 +00:00
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
rpl::producer<EntryData> SessionsContent::ListController::showRequests() const {
|
|
|
|
return _showRequests.events();
|
2021-11-26 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:38:47 +00:00
|
|
|
auto SessionsContent::ListController::Add(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
style::margins margins)
|
|
|
|
-> std::unique_ptr<ListController> {
|
|
|
|
auto &lifetime = container->lifetime();
|
|
|
|
const auto delegate = lifetime.make_state<
|
|
|
|
PeerListContentDelegateSimple
|
|
|
|
>();
|
|
|
|
auto controller = std::make_unique<ListController>(session);
|
|
|
|
controller->setStyleOverrides(&st::sessionList);
|
|
|
|
const auto content = container->add(
|
|
|
|
object_ptr<PeerListContent>(
|
|
|
|
container,
|
|
|
|
controller.get()),
|
|
|
|
margins);
|
|
|
|
delegate->setContent(content);
|
|
|
|
controller->setDelegate(delegate);
|
|
|
|
return controller;
|
2021-11-26 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 20:52:06 +00:00
|
|
|
SessionsBox::SessionsBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: _controller(controller) {
|
2020-09-05 14:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SessionsBox::prepare() {
|
|
|
|
setTitle(tr::lng_sessions_other_header());
|
|
|
|
|
|
|
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
|
|
|
|
|
|
|
const auto w = st::boxWideWidth;
|
|
|
|
|
|
|
|
const auto content = setInnerWidget(
|
2021-11-25 20:52:06 +00:00
|
|
|
object_ptr<SessionsContent>(this, _controller),
|
2020-09-05 14:33:53 +00:00
|
|
|
st::sessionsScroll);
|
|
|
|
content->resize(w, st::noContactsHeight);
|
|
|
|
content->setupContent();
|
|
|
|
|
|
|
|
setDimensions(w, st::sessionsHeight);
|
|
|
|
}
|
2020-09-05 14:48:15 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
Sessions::Sessions(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: Section(parent) {
|
|
|
|
setupContent(controller);
|
|
|
|
}
|
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
rpl::producer<QString> Sessions::title() {
|
2022-04-01 11:53:23 +00:00
|
|
|
return tr::lng_settings_sessions_title();
|
|
|
|
}
|
|
|
|
|
2020-09-05 14:48:15 +00:00
|
|
|
void Sessions::setupContent(not_null<Window::SessionController*> controller) {
|
|
|
|
const auto container = Ui::CreateChild<Ui::VerticalLayout>(this);
|
2021-11-29 13:29:45 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySkip);
|
2020-09-05 14:48:15 +00:00
|
|
|
const auto content = container->add(
|
2021-11-25 20:52:06 +00:00
|
|
|
object_ptr<SessionsContent>(container, controller));
|
2020-09-05 14:48:15 +00:00
|
|
|
content->setupContent();
|
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, container);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|