|
|
|
@ -12,34 +12,100 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
|
#include "mainwidget.h"
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "countries.h"
|
|
|
|
|
#include "auth_session.h"
|
|
|
|
|
#include "data/data_session.h"
|
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
|
#include "info/profile/info_profile_button.h"
|
|
|
|
|
#include "settings/settings_common.h"
|
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr auto kSessionsShortPollTimeout = 60 * TimeMs(1000);
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
class SessionsBox::List : public Ui::RpWidget {
|
|
|
|
|
public:
|
|
|
|
|
List(QWidget *parent);
|
|
|
|
|
|
|
|
|
|
void showData(gsl::span<const Entry> items);
|
|
|
|
|
rpl::producer<int> itemsCount() const;
|
|
|
|
|
rpl::producer<uint64> terminate() const;
|
|
|
|
|
|
|
|
|
|
void terminating(uint64 hash, bool terminating);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::vector<Entry> _items;
|
|
|
|
|
std::map<uint64, std::unique_ptr<Ui::IconButton>> _terminateButtons;
|
|
|
|
|
rpl::event_stream<uint64> _terminate;
|
|
|
|
|
rpl::event_stream<int> _itemsCount;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SessionsBox::Inner : public Ui::RpWidget {
|
|
|
|
|
public:
|
|
|
|
|
Inner(QWidget *parent);
|
|
|
|
|
|
|
|
|
|
void showData(const Full &data);
|
|
|
|
|
rpl::producer<uint64> terminateOne() const;
|
|
|
|
|
rpl::producer<> terminateAll() const;
|
|
|
|
|
|
|
|
|
|
void terminatingOne(uint64 hash, bool terminating);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setupContent();
|
|
|
|
|
|
|
|
|
|
QPointer<List> _current;
|
|
|
|
|
QPointer<Info::Profile::Button> _terminateAll;
|
|
|
|
|
QPointer<List> _incomplete;
|
|
|
|
|
QPointer<List> _list;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SessionsBox::SessionsBox(QWidget*)
|
|
|
|
|
: _shortPollTimer(this) {
|
|
|
|
|
: _shortPollTimer([=] { shortPollSessions(); }) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::prepare() {
|
|
|
|
|
setTitle(langFactory(lng_sessions_other_header));
|
|
|
|
|
|
|
|
|
|
addButton(langFactory(lng_close), [this] { closeBox(); });
|
|
|
|
|
addButton(langFactory(lng_close), [=] { closeBox(); });
|
|
|
|
|
|
|
|
|
|
setDimensions(st::boxWideWidth, st::sessionsHeight);
|
|
|
|
|
|
|
|
|
|
_inner = setInnerWidget(object_ptr<Inner>(this, &_list, &_current), st::sessionsScroll);
|
|
|
|
|
_inner = setInnerWidget(object_ptr<Inner>(this), st::sessionsScroll);
|
|
|
|
|
_inner->resize(width(), st::noContactsHeight);
|
|
|
|
|
|
|
|
|
|
connect(_inner, SIGNAL(oneTerminated()), this, SLOT(onOneTerminated()));
|
|
|
|
|
connect(_inner, SIGNAL(allTerminated()), this, SLOT(onAllTerminated()));
|
|
|
|
|
connect(_inner, SIGNAL(terminateAll()), this, SLOT(onTerminateAll()));
|
|
|
|
|
connect(App::wnd(), SIGNAL(checkNewAuthorization()), this, SLOT(onCheckNewAuthorization()));
|
|
|
|
|
connect(_shortPollTimer, SIGNAL(timeout()), this, SLOT(onShortPollAuthorizations()));
|
|
|
|
|
_inner->terminateOne(
|
|
|
|
|
) | rpl::start_with_next([=](uint64 hash) {
|
|
|
|
|
terminateOne(hash);
|
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
|
|
_inner->terminateAll(
|
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
|
terminateAll();
|
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
|
|
Auth().data().newAuthorizationChecks(
|
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
|
shortPollSessions();
|
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
|
|
MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
|
|
|
|
shortPollSessions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::setLoading(bool loading) {
|
|
|
|
@ -63,38 +129,60 @@ void SessionsBox::paintEvent(QPaintEvent *e) {
|
|
|
|
|
if (_loading) {
|
|
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
|
p.setPen(st::noContactsColor);
|
|
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
|
|
|
|
p.drawText(
|
|
|
|
|
QRect(0, 0, width(), st::noContactsHeight),
|
|
|
|
|
lang(lng_contacts_loading),
|
|
|
|
|
style::al_center);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
|
|
|
|
|
void SessionsBox::got(const MTPaccount_Authorizations &result) {
|
|
|
|
|
_shortPollRequest = 0;
|
|
|
|
|
setLoading(false);
|
|
|
|
|
_data = Full();
|
|
|
|
|
|
|
|
|
|
const auto availCurrent = st::boxWideWidth - st::sessionPadding.left() - st::sessionTerminateSkip;
|
|
|
|
|
const auto availOther = availCurrent - st::sessionTerminate.iconPosition.x();
|
|
|
|
|
const auto availInfo = availCurrent - st::sessionTerminate.width;
|
|
|
|
|
|
|
|
|
|
_list.clear();
|
|
|
|
|
if (result.type() != mtpc_account_authorizations) {
|
|
|
|
|
return;
|
|
|
|
|
result.match([&](const MTPDaccount_authorizations &data) {
|
|
|
|
|
const auto &list = data.vauthorizations.v;
|
|
|
|
|
for (const auto &auth : list) {
|
|
|
|
|
auth.match([&](const MTPDauthorization &data) {
|
|
|
|
|
auto entry = ParseEntry(data);
|
|
|
|
|
if (!entry.hash) {
|
|
|
|
|
_data.current = std::move(entry);
|
|
|
|
|
} else if (entry.incomplete) {
|
|
|
|
|
_data.incomplete.push_back(std::move(entry));
|
|
|
|
|
} else {
|
|
|
|
|
_data.list.push_back(std::move(entry));
|
|
|
|
|
}
|
|
|
|
|
auto &v = result.c_account_authorizations().vauthorizations.v;
|
|
|
|
|
_list.reserve(v.size());
|
|
|
|
|
|
|
|
|
|
const CountriesByISO2 &countries(countriesByISO2());
|
|
|
|
|
|
|
|
|
|
for_const (auto &auth, v) {
|
|
|
|
|
if (auth.type() != mtpc_authorization) {
|
|
|
|
|
continue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
auto &d = auth.c_authorization();
|
|
|
|
|
Data data;
|
|
|
|
|
data.hash = d.vhash.v;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QString appName, appVer = qs(d.vapp_version), systemVer = qs(d.vsystem_version), deviceModel = qs(d.vdevice_model);
|
|
|
|
|
if (d.vapi_id.v == 2040 || d.vapi_id.v == 17349) {
|
|
|
|
|
appName = (d.vapi_id.v == 2040) ? qstr("Telegram Desktop") : qstr("Telegram Desktop (GitHub)");
|
|
|
|
|
const auto getActiveTime = [](const Entry &entry) {
|
|
|
|
|
return entry.activeTime;
|
|
|
|
|
};
|
|
|
|
|
ranges::sort(_data.list, std::greater<>(), getActiveTime);
|
|
|
|
|
ranges::sort(_data.incomplete, std::greater<>(), getActiveTime);
|
|
|
|
|
|
|
|
|
|
_inner->showData(_data);
|
|
|
|
|
|
|
|
|
|
_shortPollTimer.callOnce(kSessionsShortPollTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionsBox::Entry SessionsBox::ParseEntry(const MTPDauthorization &data) {
|
|
|
|
|
auto result = Entry();
|
|
|
|
|
|
|
|
|
|
result.hash = data.is_current() ? 0 : data.vhash.v;
|
|
|
|
|
result.incomplete = data.is_password_pending();
|
|
|
|
|
|
|
|
|
|
auto appName = QString();
|
|
|
|
|
auto appVer = qs(data.vapp_version);
|
|
|
|
|
const auto systemVer = qs(data.vsystem_version);
|
|
|
|
|
const auto deviceModel = qs(data.vdevice_model);
|
|
|
|
|
const auto apiId = data.vapi_id.v;
|
|
|
|
|
if (apiId == 2040 || apiId == 17349) {
|
|
|
|
|
appName = (apiId == 2040)
|
|
|
|
|
? qstr("Telegram Desktop")
|
|
|
|
|
: qstr("Telegram Desktop (GitHub)");
|
|
|
|
|
//if (systemVer == qstr("windows")) {
|
|
|
|
|
// deviceModel = qsl("Windows");
|
|
|
|
|
//} else if (systemVer == qstr("os x")) {
|
|
|
|
@ -103,291 +191,358 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
|
|
|
|
|
// deviceModel = qsl("Linux");
|
|
|
|
|
//}
|
|
|
|
|
if (appVer == QString::number(appVer.toInt())) {
|
|
|
|
|
int32 ver = appVer.toInt();
|
|
|
|
|
appVer = QString("%1.%2").arg(ver / 1000000).arg((ver % 1000000) / 1000) + ((ver % 1000) ? ('.' + QString::number(ver % 1000)) : QString());
|
|
|
|
|
const auto ver = appVer.toInt();
|
|
|
|
|
appVer = QString("%1.%2"
|
|
|
|
|
).arg(ver / 1000000
|
|
|
|
|
).arg((ver % 1000000) / 1000)
|
|
|
|
|
+ ((ver % 1000)
|
|
|
|
|
? ('.' + QString::number(ver % 1000))
|
|
|
|
|
: QString());
|
|
|
|
|
//} else {
|
|
|
|
|
// appVer = QString();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
appName = qs(d.vapp_name);// +qsl(" for ") + qs(d.vplatform);
|
|
|
|
|
if (appVer.indexOf('(') >= 0) appVer = appVer.mid(appVer.indexOf('('));
|
|
|
|
|
appName = qs(data.vapp_name);// +qsl(" for ") + qs(d.vplatform);
|
|
|
|
|
if (appVer.indexOf('(') >= 0) {
|
|
|
|
|
appVer = appVer.mid(appVer.indexOf('('));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.name = appName;
|
|
|
|
|
if (!appVer.isEmpty()) {
|
|
|
|
|
result.name += ' ' + appVer;
|
|
|
|
|
}
|
|
|
|
|
data.name = appName;
|
|
|
|
|
if (!appVer.isEmpty()) data.name += ' ' + appVer;
|
|
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
|
|
|
|
|
|
|
|
|
QString country = qs(d.vcountry), platform = qs(d.vplatform);
|
|
|
|
|
//CountriesByISO2::const_iterator j = countries.constFind(country);
|
|
|
|
|
//if (j != countries.cend()) country = QString::fromUtf8(j.value()->name);
|
|
|
|
|
const auto country = qs(data.vcountry);
|
|
|
|
|
const auto platform = qs(data.vplatform);
|
|
|
|
|
//const auto &countries = countriesByISO2();
|
|
|
|
|
//const auto j = countries.constFind(country);
|
|
|
|
|
//if (j != countries.cend()) {
|
|
|
|
|
// country = QString::fromUtf8(j.value()->name);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
const auto active = data.activeTime = d.vdate_active.v
|
|
|
|
|
? d.vdate_active.v
|
|
|
|
|
: d.vdate_created.v;
|
|
|
|
|
|
|
|
|
|
data.info = qs(d.vdevice_model) + qstr(", ") + (platform.isEmpty() ? QString() : platform + ' ') + qs(d.vsystem_version);
|
|
|
|
|
data.ip = qs(d.vip) + (country.isEmpty() ? QString() : QString::fromUtf8(" \xe2\x80\x93 ") + country);
|
|
|
|
|
if (!data.hash || (d.vflags.v & 1)) {
|
|
|
|
|
data.active = lang(lng_sessions_header);
|
|
|
|
|
data.activeWidth = st::sessionWhenFont->width(lang(lng_sessions_header));
|
|
|
|
|
int32 availForName = availCurrent - st::sessionPadding.right() - data.activeWidth;
|
|
|
|
|
if (data.nameWidth > availForName) {
|
|
|
|
|
data.name = st::sessionNameFont->elided(data.name, availForName);
|
|
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
|
|
|
|
}
|
|
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
|
|
|
|
if (data.infoWidth > availCurrent) {
|
|
|
|
|
data.info = st::sessionInfoFont->elided(data.info, availCurrent);
|
|
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
|
|
|
|
}
|
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
|
|
|
|
if (data.ipWidth > availCurrent) {
|
|
|
|
|
data.ip = st::sessionInfoFont->elided(data.ip, availCurrent);
|
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
|
|
|
|
}
|
|
|
|
|
_current = data;
|
|
|
|
|
result.activeTime = data.vdate_active.v
|
|
|
|
|
? data.vdate_active.v
|
|
|
|
|
: data.vdate_created.v;
|
|
|
|
|
result.info = qs(data.vdevice_model) + qstr(", ") + (platform.isEmpty() ? QString() : platform + ' ') + qs(data.vsystem_version);
|
|
|
|
|
result.ip = qs(data.vip) + (country.isEmpty() ? QString() : QString::fromUtf8(" \xe2\x80\x93 ") + country);
|
|
|
|
|
if (!result.hash) {
|
|
|
|
|
result.active = lang(lng_status_online);
|
|
|
|
|
result.activeWidth = st::sessionWhenFont->width(lang(lng_status_online));
|
|
|
|
|
} else {
|
|
|
|
|
const auto now = QDateTime::currentDateTime();
|
|
|
|
|
const auto lastTime = ParseDateTime(active);
|
|
|
|
|
const auto lastTime = ParseDateTime(result.activeTime);
|
|
|
|
|
const auto nowDate = now.date();
|
|
|
|
|
const auto lastDate = lastTime.date();
|
|
|
|
|
QString dt;
|
|
|
|
|
if (lastDate == nowDate) {
|
|
|
|
|
data.active = lastTime.toString(cTimeFormat());
|
|
|
|
|
result.active = lastTime.toString(cTimeFormat());
|
|
|
|
|
} else if (lastDate.year() == nowDate.year()
|
|
|
|
|
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
|
|
|
|
data.active = langDayOfWeek(lastDate);
|
|
|
|
|
result.active = langDayOfWeek(lastDate);
|
|
|
|
|
} else {
|
|
|
|
|
data.active = lastDate.toString(qsl("d.MM.yy"));
|
|
|
|
|
result.active = lastDate.toString(qsl("d.MM.yy"));
|
|
|
|
|
}
|
|
|
|
|
data.activeWidth = st::sessionWhenFont->width(data.active);
|
|
|
|
|
int32 availForName = availOther - st::sessionPadding.right() - data.activeWidth;
|
|
|
|
|
if (data.nameWidth > availForName) {
|
|
|
|
|
data.name = st::sessionNameFont->elided(data.name, availForName);
|
|
|
|
|
data.nameWidth = st::sessionNameFont->width(data.name);
|
|
|
|
|
}
|
|
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
|
|
|
|
if (data.infoWidth > availInfo) {
|
|
|
|
|
data.info = st::sessionInfoFont->elided(data.info, availInfo);
|
|
|
|
|
data.infoWidth = st::sessionInfoFont->width(data.info);
|
|
|
|
|
}
|
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
|
|
|
|
if (data.ipWidth > availOther) {
|
|
|
|
|
data.ip = st::sessionInfoFont->elided(data.ip, availOther);
|
|
|
|
|
data.ipWidth = st::sessionInfoFont->width(data.ip);
|
|
|
|
|
result.activeWidth = st::sessionWhenFont->width(result.active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_list.push_back(data);
|
|
|
|
|
for (int32 i = _list.size(); i > 1;) {
|
|
|
|
|
--i;
|
|
|
|
|
if (_list.at(i).activeTime > _list.at(i - 1).activeTime) {
|
|
|
|
|
qSwap(_list[i], _list[i - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_inner->listUpdated();
|
|
|
|
|
ResizeEntry(result);
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
_shortPollTimer->start(SessionsShortPollTimeout);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::onOneTerminated() {
|
|
|
|
|
update();
|
|
|
|
|
void SessionsBox::ResizeEntry(Entry &entry) {
|
|
|
|
|
const auto available = st::boxWideWidth
|
|
|
|
|
- st::sessionPadding.left()
|
|
|
|
|
- st::sessionTerminateSkip;
|
|
|
|
|
const auto availableInList = available
|
|
|
|
|
- st::sessionTerminate.iconPosition.x();
|
|
|
|
|
const auto availableListInfo = available - st::sessionTerminate.width;
|
|
|
|
|
|
|
|
|
|
const auto resize = [](
|
|
|
|
|
const style::font &font,
|
|
|
|
|
QString &string,
|
|
|
|
|
int &stringWidth,
|
|
|
|
|
int available) {
|
|
|
|
|
stringWidth = font->width(string);
|
|
|
|
|
if (stringWidth > available) {
|
|
|
|
|
string = font->elided(string, available);
|
|
|
|
|
stringWidth = font->width(string);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const auto forName = entry.hash ? availableInList : available;
|
|
|
|
|
const auto forInfo = entry.hash ? availableListInfo : available;
|
|
|
|
|
resize(st::sessionNameFont, entry.name, entry.nameWidth, forName);
|
|
|
|
|
resize(st::sessionInfoFont, entry.info, entry.infoWidth, forInfo);
|
|
|
|
|
resize(st::sessionInfoFont, entry.ip, entry.ipWidth, available);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::onShortPollAuthorizations() {
|
|
|
|
|
if (!_shortPollRequest) {
|
|
|
|
|
_shortPollRequest = MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::onCheckNewAuthorization() {
|
|
|
|
|
onShortPollAuthorizations();
|
|
|
|
|
// _shortPollTimer.start(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::onAllTerminated() {
|
|
|
|
|
MTP::send(MTPaccount_GetAuthorizations(), rpcDone(&SessionsBox::gotAuthorizations));
|
|
|
|
|
void SessionsBox::shortPollSessions() {
|
|
|
|
|
if (_shortPollRequest) {
|
|
|
|
|
MTP::cancel(_shortPollRequest);
|
|
|
|
|
_shortPollRequest = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_shortPollRequest = request(MTPaccount_GetAuthorizations(
|
|
|
|
|
)).done([=](const MTPaccount_Authorizations &result) {
|
|
|
|
|
got(result);
|
|
|
|
|
}).send();
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::onTerminateAll() {
|
|
|
|
|
void SessionsBox::terminateOne(uint64 hash) {
|
|
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
|
|
|
|
const auto callback = crl::guard(this, [=] {
|
|
|
|
|
if (_terminateBox) {
|
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
|
}
|
|
|
|
|
request(MTPaccount_ResetAuthorization(
|
|
|
|
|
MTP_long(hash)
|
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
|
_inner->terminatingOne(hash, false);
|
|
|
|
|
const auto getHash = [](const Entry &entry) {
|
|
|
|
|
return entry.hash;
|
|
|
|
|
};
|
|
|
|
|
const auto removeByHash = [&](std::vector<Entry> &list) {
|
|
|
|
|
list.erase(
|
|
|
|
|
ranges::remove(list, hash, getHash),
|
|
|
|
|
end(list));
|
|
|
|
|
};
|
|
|
|
|
removeByHash(_data.incomplete);
|
|
|
|
|
removeByHash(_data.list);
|
|
|
|
|
_inner->showData(_data);
|
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
|
_inner->terminatingOne(hash, false);
|
|
|
|
|
}).send();
|
|
|
|
|
_inner->terminatingOne(hash, true);
|
|
|
|
|
});
|
|
|
|
|
_terminateBox = Ui::show(
|
|
|
|
|
Box<ConfirmBox>(
|
|
|
|
|
lang(lng_settings_reset_one_sure),
|
|
|
|
|
lang(lng_settings_reset_button),
|
|
|
|
|
st::attentionBoxButton,
|
|
|
|
|
callback),
|
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::terminateAll() {
|
|
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
|
|
|
|
const auto callback = crl::guard(this, [=] {
|
|
|
|
|
if (_terminateBox) {
|
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
|
}
|
|
|
|
|
request(MTPauth_ResetAuthorizations(
|
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
|
request(base::take(_shortPollRequest)).cancel();
|
|
|
|
|
shortPollSessions();
|
|
|
|
|
}).fail([=](const RPCError &result) {
|
|
|
|
|
request(base::take(_shortPollRequest)).cancel();
|
|
|
|
|
shortPollSessions();
|
|
|
|
|
}).send();
|
|
|
|
|
setLoading(true);
|
|
|
|
|
});
|
|
|
|
|
_terminateBox = Ui::show(
|
|
|
|
|
Box<ConfirmBox>(
|
|
|
|
|
lang(lng_settings_reset_sure),
|
|
|
|
|
lang(lng_settings_reset_button),
|
|
|
|
|
st::attentionBoxButton,
|
|
|
|
|
callback),
|
|
|
|
|
LayerOption::KeepOther);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionsBox::Inner::Inner(QWidget *parent, SessionsBox::List *list, SessionsBox::Data *current) : TWidget(parent)
|
|
|
|
|
, _list(list)
|
|
|
|
|
, _current(current)
|
|
|
|
|
, _terminateAll(this, lang(lng_sessions_terminate_all), st::sessionTerminateAllButton) {
|
|
|
|
|
connect(_terminateAll, SIGNAL(clicked()), this, SLOT(onTerminateAll()));
|
|
|
|
|
_terminateAll->hide();
|
|
|
|
|
SessionsBox::Inner::Inner(QWidget *parent)
|
|
|
|
|
: RpWidget(parent) {
|
|
|
|
|
setupContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::setupContent() {
|
|
|
|
|
using namespace Settings;
|
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
|
|
|
|
|
AddSubsectionTitle(content, lng_sessions_header);
|
|
|
|
|
_current = content->add(object_ptr<List>(content));
|
|
|
|
|
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(
|
|
|
|
|
object_ptr<Info::Profile::Button>(
|
|
|
|
|
terminateInner,
|
|
|
|
|
Lang::Viewer(lng_sessions_terminate_all),
|
|
|
|
|
st::terminateSessionsButton));
|
|
|
|
|
AddSkip(terminateInner);
|
|
|
|
|
AddDividerText(
|
|
|
|
|
terminateInner,
|
|
|
|
|
Lang::Viewer(lng_sessions_terminate_all_about));
|
|
|
|
|
|
|
|
|
|
const auto incompleteWrap = content->add(
|
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
|
content,
|
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
|
const auto incompleteInner = incompleteWrap->entity();
|
|
|
|
|
AddSkip(incompleteInner);
|
|
|
|
|
AddSubsectionTitle(incompleteInner, lng_sessions_incomplete);
|
|
|
|
|
_incomplete = incompleteInner->add(object_ptr<List>(incompleteInner));
|
|
|
|
|
AddSkip(incompleteInner);
|
|
|
|
|
AddDividerText(
|
|
|
|
|
incompleteInner,
|
|
|
|
|
Lang::Viewer(lng_sessions_incomplete_about));
|
|
|
|
|
|
|
|
|
|
const auto listWrap = content->add(
|
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
|
content,
|
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
|
const auto listInner = listWrap->entity();
|
|
|
|
|
AddSkip(listInner);
|
|
|
|
|
AddSubsectionTitle(listInner, lng_sessions_other_header);
|
|
|
|
|
_list = listInner->add(object_ptr<List>(listInner));
|
|
|
|
|
AddSkip(listInner);
|
|
|
|
|
|
|
|
|
|
const auto placeholder = content->add(
|
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
|
|
|
|
|
content,
|
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
|
content,
|
|
|
|
|
Lang::Viewer(lng_sessions_other_desc),
|
|
|
|
|
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));
|
|
|
|
|
placeholder->toggleOn(_list->itemsCount() | rpl::map(_1 == 0));
|
|
|
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::showData(const Full &data) {
|
|
|
|
|
_current->showData({ &data.current, &data.current + 1 });
|
|
|
|
|
_list->showData(data.list);
|
|
|
|
|
_incomplete->showData(data.incomplete);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rpl::producer<> SessionsBox::Inner::terminateAll() const {
|
|
|
|
|
return _terminateAll->clicks() | rpl::map([] {
|
|
|
|
|
return rpl::empty_value();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rpl::producer<uint64> SessionsBox::Inner::terminateOne() const {
|
|
|
|
|
return rpl::merge(
|
|
|
|
|
_incomplete->terminate(),
|
|
|
|
|
_list->terminate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::terminatingOne(uint64 hash, bool terminating) {
|
|
|
|
|
_incomplete->terminating(hash, terminating);
|
|
|
|
|
_list->terminating(hash, terminating);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionsBox::List::List(QWidget *parent) : RpWidget(parent) {
|
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::paintEvent(QPaintEvent *e) {
|
|
|
|
|
void SessionsBox::List::showData(gsl::span<const Entry> items) {
|
|
|
|
|
auto buttons = base::take(_terminateButtons);
|
|
|
|
|
_items.clear();
|
|
|
|
|
_items.insert(begin(_items), items.begin(), items.end());
|
|
|
|
|
for (const auto &entry : _items) {
|
|
|
|
|
const auto hash = entry.hash;
|
|
|
|
|
if (!hash) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const auto button = [&] {
|
|
|
|
|
const auto i = buttons.find(hash);
|
|
|
|
|
return _terminateButtons.emplace(
|
|
|
|
|
hash,
|
|
|
|
|
(i != end(buttons)
|
|
|
|
|
? std::move(i->second)
|
|
|
|
|
: std::make_unique<Ui::IconButton>(
|
|
|
|
|
this,
|
|
|
|
|
st::sessionTerminate))).first->second.get();
|
|
|
|
|
}();
|
|
|
|
|
button->setClickedCallback([=] {
|
|
|
|
|
_terminate.fire_copy(hash);
|
|
|
|
|
});
|
|
|
|
|
button->show();
|
|
|
|
|
button->moveToRight(
|
|
|
|
|
st::sessionTerminateSkip,
|
|
|
|
|
((_terminateButtons.size() - 1) * st::sessionHeight
|
|
|
|
|
+ st::sessionTerminateTop));
|
|
|
|
|
}
|
|
|
|
|
resizeToWidth(width());
|
|
|
|
|
_itemsCount.fire(_items.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rpl::producer<int> SessionsBox::List::itemsCount() const {
|
|
|
|
|
return _itemsCount.events_starting_with(_items.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rpl::producer<uint64> SessionsBox::List::terminate() const {
|
|
|
|
|
return _terminate.events();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::List::terminating(uint64 hash, bool terminating) {
|
|
|
|
|
const auto i = _terminateButtons.find(hash);
|
|
|
|
|
if (i != _terminateButtons.cend()) {
|
|
|
|
|
if (terminating) {
|
|
|
|
|
i->second->clearState();
|
|
|
|
|
i->second->hide();
|
|
|
|
|
} else {
|
|
|
|
|
i->second->show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SessionsBox::List::resizeGetHeight(int newWidth) {
|
|
|
|
|
return _items.size() * st::sessionHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::List::paintEvent(QPaintEvent *e) {
|
|
|
|
|
QRect r(e->rect());
|
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
|
|
p.fillRect(r, st::boxBg);
|
|
|
|
|
int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.iconPosition.x();// st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
|
|
|
|
|
int32 w = width();
|
|
|
|
|
p.setFont(st::linkFont);
|
|
|
|
|
const auto count = int(_items.size());
|
|
|
|
|
const auto from = floorclamp(r.y(), st::sessionHeight, 0, count);
|
|
|
|
|
const auto till = ceilclamp(
|
|
|
|
|
r.y() + r.height(),
|
|
|
|
|
st::sessionHeight,
|
|
|
|
|
0,
|
|
|
|
|
count);
|
|
|
|
|
|
|
|
|
|
if (_current->active.isEmpty() && _list->isEmpty()) {
|
|
|
|
|
p.setFont(st::noContactsFont->f);
|
|
|
|
|
p.setPen(st::noContactsColor->p);
|
|
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight), lang(lng_contacts_loading), style::al_center);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.translate(0, st::sessionCurrentPadding.top());
|
|
|
|
|
if (r.y() <= st::sessionCurrentHeight) {
|
|
|
|
|
p.setFont(st::sessionNameFont);
|
|
|
|
|
p.setPen(st::sessionNameFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top(), w, _current->name, _current->nameWidth);
|
|
|
|
|
|
|
|
|
|
p.setFont(st::sessionWhenFont);
|
|
|
|
|
p.setPen(st::sessionWhenFg);
|
|
|
|
|
p.drawTextRight(x, st::sessionPadding.top(), w, _current->active, _current->activeWidth);
|
|
|
|
|
|
|
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
|
p.setPen(st::boxTextFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, _current->info, _current->infoWidth);
|
|
|
|
|
p.setPen(st::sessionInfoFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, _current->ip, _current->ipWidth);
|
|
|
|
|
}
|
|
|
|
|
p.translate(0, st::sessionCurrentHeight - st::sessionCurrentPadding.top());
|
|
|
|
|
if (_list->isEmpty()) {
|
|
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
|
p.setPen(st::sessionInfoFg);
|
|
|
|
|
p.drawText(QRect(st::sessionPadding.left(), 0, width() - st::sessionPadding.left() - st::sessionPadding.right(), st::noContactsHeight), lang(lng_sessions_other_desc), style::al_topleft);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.setFont(st::linkFont->f);
|
|
|
|
|
int32 count = _list->size();
|
|
|
|
|
int32 from = floorclamp(r.y() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
|
|
|
|
|
int32 to = ceilclamp(r.y() + r.height() - st::sessionCurrentHeight, st::sessionHeight, 0, count);
|
|
|
|
|
const auto x = st::sessionPadding.left();
|
|
|
|
|
const auto y = st::sessionPadding.top();
|
|
|
|
|
const auto w = width();
|
|
|
|
|
const auto xact = st::sessionTerminateSkip
|
|
|
|
|
+ st::sessionTerminate.iconPosition.x();
|
|
|
|
|
p.translate(0, from * st::sessionHeight);
|
|
|
|
|
for (int32 i = from; i < to; ++i) {
|
|
|
|
|
const SessionsBox::Data &auth(_list->at(i));
|
|
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
|
const auto &entry = _items[i];
|
|
|
|
|
|
|
|
|
|
p.setFont(st::sessionNameFont);
|
|
|
|
|
p.setPen(st::sessionNameFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top(), w, auth.name, auth.nameWidth);
|
|
|
|
|
p.drawTextLeft(x, y, w, entry.name, entry.nameWidth);
|
|
|
|
|
|
|
|
|
|
p.setFont(st::sessionWhenFont);
|
|
|
|
|
p.setPen(st::sessionWhenFg);
|
|
|
|
|
p.drawTextRight(xact, st::sessionPadding.top(), w, auth.active, auth.activeWidth);
|
|
|
|
|
p.drawTextRight(xact, y, w, entry.active, entry.activeWidth);
|
|
|
|
|
|
|
|
|
|
const auto name = st::sessionNameFont->height;
|
|
|
|
|
p.setFont(st::sessionInfoFont);
|
|
|
|
|
p.setPen(st::boxTextFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, auth.info, auth.infoWidth);
|
|
|
|
|
p.drawTextLeft(x, y + name, w, entry.info, entry.infoWidth);
|
|
|
|
|
|
|
|
|
|
const auto info = st::sessionInfoFont->height;
|
|
|
|
|
p.setPen(st::sessionInfoFg);
|
|
|
|
|
p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, auth.ip, auth.ipWidth);
|
|
|
|
|
p.drawTextLeft(x, y + name + info, w, entry.ip, entry.ipWidth);
|
|
|
|
|
|
|
|
|
|
p.translate(0, st::sessionHeight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::onTerminate() {
|
|
|
|
|
for (auto i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) {
|
|
|
|
|
if (i.value()->isOver()) {
|
|
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
|
|
|
|
_terminateBox = Ui::show(Box<ConfirmBox>(lang(lng_settings_reset_one_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this, terminating = i.key()] {
|
|
|
|
|
if (_terminateBox) {
|
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
|
}
|
|
|
|
|
MTP::send(MTPaccount_ResetAuthorization(MTP_long(terminating)), rpcDone(&Inner::terminateDone, terminating), rpcFail(&Inner::terminateFail, terminating));
|
|
|
|
|
auto i = _terminateButtons.find(terminating);
|
|
|
|
|
if (i != _terminateButtons.cend()) {
|
|
|
|
|
i.value()->clearState();
|
|
|
|
|
i.value()->hide();
|
|
|
|
|
}
|
|
|
|
|
})), LayerOption::KeepOther);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::onTerminateAll() {
|
|
|
|
|
if (_terminateBox) _terminateBox->deleteLater();
|
|
|
|
|
_terminateBox = Ui::show(Box<ConfirmBox>(lang(lng_settings_reset_sure), lang(lng_settings_reset_button), st::attentionBoxButton, crl::guard(this, [this] {
|
|
|
|
|
if (_terminateBox) {
|
|
|
|
|
_terminateBox->closeBox();
|
|
|
|
|
_terminateBox = nullptr;
|
|
|
|
|
}
|
|
|
|
|
MTP::send(MTPauth_ResetAuthorizations(), rpcDone(&Inner::terminateAllDone), rpcFail(&Inner::terminateAllFail));
|
|
|
|
|
emit terminateAll();
|
|
|
|
|
})), LayerOption::KeepOther);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::terminateDone(uint64 hash, const MTPBool &result) {
|
|
|
|
|
for (int32 i = 0, l = _list->size(); i < l; ++i) {
|
|
|
|
|
if (_list->at(i).hash == hash) {
|
|
|
|
|
_list->removeAt(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
listUpdated();
|
|
|
|
|
emit oneTerminated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SessionsBox::Inner::terminateFail(uint64 hash, const RPCError &error) {
|
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
|
|
TerminateButtons::iterator i = _terminateButtons.find(hash);
|
|
|
|
|
if (i != _terminateButtons.end()) {
|
|
|
|
|
i.value()->show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::terminateAllDone(const MTPBool &result) {
|
|
|
|
|
emit allTerminated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SessionsBox::Inner::terminateAllFail(const RPCError &error) {
|
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
emit allTerminated();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::resizeEvent(QResizeEvent *e) {
|
|
|
|
|
_terminateAll->moveToLeft(st::sessionPadding.left(), st::sessionCurrentPadding.top() + st::sessionHeight + st::sessionCurrentPadding.bottom());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SessionsBox::Inner::listUpdated() {
|
|
|
|
|
if (_list->isEmpty()) {
|
|
|
|
|
_terminateAll->hide();
|
|
|
|
|
} else {
|
|
|
|
|
_terminateAll->show();
|
|
|
|
|
}
|
|
|
|
|
for (TerminateButtons::iterator i = _terminateButtons.begin(), e = _terminateButtons.end(); i != e; ++i) {
|
|
|
|
|
i.value()->move(0, -1);
|
|
|
|
|
}
|
|
|
|
|
for (int32 i = 0, l = _list->size(); i < l; ++i) {
|
|
|
|
|
TerminateButtons::iterator j = _terminateButtons.find(_list->at(i).hash);
|
|
|
|
|
if (j == _terminateButtons.cend()) {
|
|
|
|
|
j = _terminateButtons.insert(_list->at(i).hash, new Ui::IconButton(this, st::sessionTerminate));
|
|
|
|
|
connect(j.value(), SIGNAL(clicked()), this, SLOT(onTerminate()));
|
|
|
|
|
}
|
|
|
|
|
j.value()->moveToRight(st::sessionTerminateSkip, st::sessionCurrentHeight + i * st::sessionHeight + st::sessionTerminateTop, width());
|
|
|
|
|
j.value()->show();
|
|
|
|
|
}
|
|
|
|
|
for (TerminateButtons::iterator i = _terminateButtons.begin(); i != _terminateButtons.cend();) {
|
|
|
|
|
if (i.value()->y() >= 0) {
|
|
|
|
|
++i;
|
|
|
|
|
} else {
|
|
|
|
|
delete i.value();
|
|
|
|
|
i = _terminateButtons.erase(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resize(width(), _list->isEmpty() ? (st::sessionCurrentHeight + st::noContactsHeight) : (st::sessionCurrentHeight + _list->size() * st::sessionHeight));
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|