mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved other authorizations api request to separated file.
This commit is contained in:
parent
0c4c4b2fcf
commit
6ac5f32796
9 changed files with 300 additions and 153 deletions
|
@ -192,6 +192,8 @@ nice_target_sources(Telegram ${src_loc}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${style_files}
|
${style_files}
|
||||||
|
|
||||||
|
api/api_authorizations.cpp
|
||||||
|
api/api_authorizations.h
|
||||||
api/api_bot.cpp
|
api/api_bot.cpp
|
||||||
api/api_bot.h
|
api/api_bot.h
|
||||||
api/api_chat_filters.cpp
|
api/api_chat_filters.cpp
|
||||||
|
|
161
Telegram/SourceFiles/api/api_authorizations.cpp
Normal file
161
Telegram/SourceFiles/api/api_authorizations.cpp
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
/*
|
||||||
|
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 "api/api_authorizations.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "base/unixtime.h"
|
||||||
|
#include "core/changelogs.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto TestApiId = 17349;
|
||||||
|
constexpr auto DesktopApiId = 2040;
|
||||||
|
|
||||||
|
Authorizations::Entry ParseEntry(const MTPDauthorization &data) {
|
||||||
|
auto result = Authorizations::Entry();
|
||||||
|
|
||||||
|
result.hash = data.is_current() ? 0 : data.vhash().v;
|
||||||
|
result.incomplete = data.is_password_pending();
|
||||||
|
|
||||||
|
const auto apiId = data.vapi_id().v;
|
||||||
|
const auto isTest = (apiId == TestApiId);
|
||||||
|
const auto isDesktop = (apiId == DesktopApiId) || isTest;
|
||||||
|
|
||||||
|
const auto appName = isDesktop
|
||||||
|
? QString("Telegram Desktop%1").arg(isTest ? " (GitHub)" : QString())
|
||||||
|
: qs(data.vapp_name());// +qsl(" for ") + qs(d.vplatform());
|
||||||
|
const auto appVer = [&] {
|
||||||
|
const auto version = qs(data.vapp_version());
|
||||||
|
if (isDesktop) {
|
||||||
|
const auto verInt = version.toInt();
|
||||||
|
if (version == QString::number(verInt)) {
|
||||||
|
return Core::FormatVersionDisplay(verInt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (const auto index = version.indexOf('('); index >= 0) {
|
||||||
|
return version.mid(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}();
|
||||||
|
|
||||||
|
result.name = QString("%1%2")
|
||||||
|
.arg(appName)
|
||||||
|
.arg(appVer.isEmpty() ? QString() : (' ' + appVer));
|
||||||
|
|
||||||
|
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);
|
||||||
|
//}
|
||||||
|
|
||||||
|
result.activeTime = data.vdate_active().v
|
||||||
|
? data.vdate_active().v
|
||||||
|
: data.vdate_created().v;
|
||||||
|
result.info = QString("%1, %2%3")
|
||||||
|
.arg(qs(data.vdevice_model()))
|
||||||
|
.arg(platform.isEmpty() ? QString() : platform + ' ')
|
||||||
|
.arg(qs(data.vsystem_version()));
|
||||||
|
result.ip = qs(data.vip())
|
||||||
|
+ (country.isEmpty()
|
||||||
|
? QString()
|
||||||
|
: QString::fromUtf8(" \xe2\x80\x93 ") + country);
|
||||||
|
if (!result.hash) {
|
||||||
|
result.active = tr::lng_status_online(tr::now);
|
||||||
|
} else {
|
||||||
|
const auto now = QDateTime::currentDateTime();
|
||||||
|
const auto lastTime = base::unixtime::parse(result.activeTime);
|
||||||
|
const auto nowDate = now.date();
|
||||||
|
const auto lastDate = lastTime.date();
|
||||||
|
if (lastDate == nowDate) {
|
||||||
|
result.active = lastTime.toString(cTimeFormat());
|
||||||
|
} else if (lastDate.year() == nowDate.year()
|
||||||
|
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
||||||
|
result.active = langDayOfWeek(lastDate);
|
||||||
|
} else {
|
||||||
|
result.active = lastDate.toString(qsl("d.MM.yy"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Authorizations::Authorizations(not_null<ApiWrap*> api)
|
||||||
|
: _api(&api->instance()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Authorizations::reload() {
|
||||||
|
if (_requestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_requestId = _api.request(MTPaccount_GetAuthorizations(
|
||||||
|
)).done([=](const MTPaccount_Authorizations &result) {
|
||||||
|
_requestId = 0;
|
||||||
|
result.match([&](const MTPDaccount_authorizations &auths) {
|
||||||
|
_list = (
|
||||||
|
auths.vauthorizations().v
|
||||||
|
) | ranges::view::transform([](const MTPAuthorization &d) {
|
||||||
|
return ParseEntry(d.c_authorization());
|
||||||
|
}) | ranges::to<List>;
|
||||||
|
_listChanges.fire({});
|
||||||
|
});
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
_requestId = 0;
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Authorizations::cancelCurrentRequest() {
|
||||||
|
_api.request(base::take(_requestId)).cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Authorizations::requestTerminate(
|
||||||
|
Fn<void(const MTPBool &result)> &&done,
|
||||||
|
Fn<void(const RPCError &error)> &&fail,
|
||||||
|
std::optional<uint64> hash) {
|
||||||
|
auto request = hash
|
||||||
|
? MTPaccount_ResetAuthorization(MTP_long(*hash))
|
||||||
|
: MTPaccount_ResetAuthorization();
|
||||||
|
_api.request(std::move(request))
|
||||||
|
.done(std::move(done))
|
||||||
|
.fail(std::move(fail))
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
Authorizations::List Authorizations::list() const {
|
||||||
|
return _list;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Authorizations::listChanges() const
|
||||||
|
-> rpl::producer<Authorizations::List> {
|
||||||
|
return rpl::single(
|
||||||
|
list()
|
||||||
|
) | rpl::then(
|
||||||
|
_listChanges.events() | rpl::map([=] { return list(); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<int> Authorizations::totalChanges() const {
|
||||||
|
return rpl::single(
|
||||||
|
total()
|
||||||
|
) | rpl::then(
|
||||||
|
_listChanges.events() | rpl::map([=] { return total(); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
int Authorizations::total() const {
|
||||||
|
return ranges::count_if(
|
||||||
|
_list,
|
||||||
|
ranges::not_fn(&Entry::incomplete));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Api
|
50
Telegram/SourceFiles/api/api_authorizations.h
Normal file
50
Telegram/SourceFiles/api/api_authorizations.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
|
class ApiWrap;
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
|
||||||
|
class Authorizations final {
|
||||||
|
public:
|
||||||
|
explicit Authorizations(not_null<ApiWrap*> api);
|
||||||
|
|
||||||
|
struct Entry {
|
||||||
|
uint64 hash = 0;
|
||||||
|
|
||||||
|
bool incomplete = false;
|
||||||
|
TimeId activeTime = 0;
|
||||||
|
QString name, active, info, ip;
|
||||||
|
};
|
||||||
|
using List = std::vector<Entry>;
|
||||||
|
|
||||||
|
void reload();
|
||||||
|
void cancelCurrentRequest();
|
||||||
|
void requestTerminate(
|
||||||
|
Fn<void(const MTPBool &result)> &&done,
|
||||||
|
Fn<void(const RPCError &error)> &&fail,
|
||||||
|
std::optional<uint64> hash = std::nullopt);
|
||||||
|
|
||||||
|
[[nodiscard]] List list() const;
|
||||||
|
[[nodiscard]] rpl::producer<List> listChanges() const;
|
||||||
|
[[nodiscard]] int total() const;
|
||||||
|
[[nodiscard]] rpl::producer<int> totalChanges() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MTP::Sender _api;
|
||||||
|
mtpRequestId _requestId = 0;
|
||||||
|
|
||||||
|
List _list;
|
||||||
|
rpl::event_stream<> _listChanges;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Api
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
|
||||||
|
#include "api/api_authorizations.h"
|
||||||
#include "api/api_hash.h"
|
#include "api/api_hash.h"
|
||||||
#include "api/api_media.h"
|
#include "api/api_media.h"
|
||||||
#include "api/api_sending.h"
|
#include "api/api_sending.h"
|
||||||
|
@ -186,6 +187,7 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
||||||
//, _feedReadTimer([=] { readFeeds(); }) // #feed
|
//, _feedReadTimer([=] { readFeeds(); }) // #feed
|
||||||
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
||||||
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
, _updateNotifySettingsTimer([=] { sendNotifySettingsUpdates(); })
|
||||||
|
, _authorizations(std::make_unique<Api::Authorizations>(this))
|
||||||
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
, _selfDestruct(std::make_unique<Api::SelfDestruct>(this))
|
||||||
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this))
|
, _sensitiveContent(std::make_unique<Api::SensitiveContent>(this))
|
||||||
, _globalPrivacy(std::make_unique<Api::GlobalPrivacy>(this)) {
|
, _globalPrivacy(std::make_unique<Api::GlobalPrivacy>(this)) {
|
||||||
|
@ -5221,6 +5223,10 @@ auto ApiWrap::blockedPeersSlice() -> rpl::producer<BlockedPeersSlice> {
|
||||||
: (_blockedPeersChanges.events() | rpl::type_erased());
|
: (_blockedPeersChanges.events() | rpl::type_erased());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Api::Authorizations &ApiWrap::authorizations() {
|
||||||
|
return *_authorizations;
|
||||||
|
}
|
||||||
|
|
||||||
Api::SelfDestruct &ApiWrap::selfDestruct() {
|
Api::SelfDestruct &ApiWrap::selfDestruct() {
|
||||||
return *_selfDestruct;
|
return *_selfDestruct;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ struct CloudPasswordState;
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
|
||||||
class Updates;
|
class Updates;
|
||||||
|
class Authorizations;
|
||||||
class SelfDestruct;
|
class SelfDestruct;
|
||||||
class SensitiveContent;
|
class SensitiveContent;
|
||||||
class GlobalPrivacy;
|
class GlobalPrivacy;
|
||||||
|
@ -453,6 +454,7 @@ public:
|
||||||
void reloadBlockedPeers();
|
void reloadBlockedPeers();
|
||||||
rpl::producer<BlockedPeersSlice> blockedPeersSlice();
|
rpl::producer<BlockedPeersSlice> blockedPeersSlice();
|
||||||
|
|
||||||
|
[[nodiscard]] Api::Authorizations &authorizations();
|
||||||
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
[[nodiscard]] Api::SelfDestruct &selfDestruct();
|
||||||
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
[[nodiscard]] Api::SensitiveContent &sensitiveContent();
|
||||||
[[nodiscard]] Api::GlobalPrivacy &globalPrivacy();
|
[[nodiscard]] Api::GlobalPrivacy &globalPrivacy();
|
||||||
|
@ -815,6 +817,7 @@ private:
|
||||||
std::optional<BlockedPeersSlice> _blockedPeersSlice;
|
std::optional<BlockedPeersSlice> _blockedPeersSlice;
|
||||||
rpl::event_stream<BlockedPeersSlice> _blockedPeersChanges;
|
rpl::event_stream<BlockedPeersSlice> _blockedPeersChanges;
|
||||||
|
|
||||||
|
const std::unique_ptr<Api::Authorizations> _authorizations;
|
||||||
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
const std::unique_ptr<Api::SelfDestruct> _selfDestruct;
|
||||||
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
const std::unique_ptr<Api::SensitiveContent> _sensitiveContent;
|
||||||
const std::unique_ptr<Api::GlobalPrivacy> _globalPrivacy;
|
const std::unique_ptr<Api::GlobalPrivacy> _globalPrivacy;
|
||||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/sessions_box.h"
|
#include "boxes/sessions_box.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "api/api_authorizations.h"
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
|
@ -42,6 +44,17 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Entry {
|
struct Entry {
|
||||||
|
Entry() = default;
|
||||||
|
Entry(const Api::Authorizations::Entry &entry)
|
||||||
|
: hash(entry.hash)
|
||||||
|
, incomplete(entry.incomplete)
|
||||||
|
, activeTime(entry.activeTime)
|
||||||
|
, name(entry.name)
|
||||||
|
, active(entry.active)
|
||||||
|
, info(entry.info)
|
||||||
|
, ip(entry.ip) {
|
||||||
|
};
|
||||||
|
|
||||||
uint64 hash = 0;
|
uint64 hash = 0;
|
||||||
|
|
||||||
bool incomplete = false;
|
bool incomplete = false;
|
||||||
|
@ -57,18 +70,15 @@ private:
|
||||||
class Inner;
|
class Inner;
|
||||||
class List;
|
class List;
|
||||||
|
|
||||||
static Entry ParseEntry(const MTPDauthorization &data);
|
|
||||||
static void ResizeEntry(Entry &entry);
|
static void ResizeEntry(Entry &entry);
|
||||||
void shortPollSessions();
|
void shortPollSessions();
|
||||||
|
|
||||||
void got(const MTPaccount_Authorizations &result);
|
|
||||||
|
|
||||||
void terminate(Fn<void()> terminateRequest, QString message);
|
void terminate(Fn<void()> terminateRequest, QString message);
|
||||||
void terminateOne(uint64 hash);
|
void terminateOne(uint64 hash);
|
||||||
void terminateAll();
|
void terminateAll();
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
MTP::Sender _api;
|
const not_null<Api::Authorizations*> _authorizations;
|
||||||
|
|
||||||
rpl::variable<bool> _loading = false;
|
rpl::variable<bool> _loading = false;
|
||||||
Full _data;
|
Full _data;
|
||||||
|
@ -77,7 +87,6 @@ private:
|
||||||
QPointer<ConfirmBox> _terminateBox;
|
QPointer<ConfirmBox> _terminateBox;
|
||||||
|
|
||||||
base::Timer _shortPollTimer;
|
base::Timer _shortPollTimer;
|
||||||
mtpRequestId _shortPollRequest = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,7 +135,7 @@ private:
|
||||||
|
|
||||||
SessionsContent::SessionsContent(QWidget*, not_null<Main::Session*> session)
|
SessionsContent::SessionsContent(QWidget*, not_null<Main::Session*> session)
|
||||||
: _session(session)
|
: _session(session)
|
||||||
, _api(&_session->mtp())
|
, _authorizations(&_session->api().authorizations())
|
||||||
, _inner(this)
|
, _inner(this)
|
||||||
, _shortPollTimer([=] { shortPollSessions(); }) {
|
, _shortPollTimer([=] { shortPollSessions(); }) {
|
||||||
}
|
}
|
||||||
|
@ -160,6 +169,31 @@ void SessionsContent::setupContent() {
|
||||||
_inner->setVisible(!value);
|
_inner->setVisible(!value);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
_authorizations->listChanges(
|
||||||
|
) | rpl::start_with_next([=](const Api::Authorizations::List &list) {
|
||||||
|
_data = Full();
|
||||||
|
for (const auto auth : list) {
|
||||||
|
auto entry = Entry(auth);
|
||||||
|
ResizeEntry(entry);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_loading = false;
|
||||||
|
|
||||||
|
ranges::sort(_data.list, std::greater<>(), &Entry::activeTime);
|
||||||
|
ranges::sort(_data.incomplete, std::greater<>(), &Entry::activeTime);
|
||||||
|
|
||||||
|
_inner->showData(_data);
|
||||||
|
|
||||||
|
_shortPollTimer.callOnce(kSessionsShortPollTimeout);
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
_loading = true;
|
_loading = true;
|
||||||
shortPollSessions();
|
shortPollSessions();
|
||||||
}
|
}
|
||||||
|
@ -185,120 +219,9 @@ void SessionsContent::paintEvent(QPaintEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionsContent::got(const MTPaccount_Authorizations &result) {
|
|
||||||
_shortPollRequest = 0;
|
|
||||||
_loading = false;
|
|
||||||
_data = Full();
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionsContent::Entry SessionsContent::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")) {
|
|
||||||
// deviceModel = qsl("OS X");
|
|
||||||
//} else if (systemVer == qstr("linux")) {
|
|
||||||
// deviceModel = qsl("Linux");
|
|
||||||
//}
|
|
||||||
if (appVer == QString::number(appVer.toInt())) {
|
|
||||||
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(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
//}
|
|
||||||
|
|
||||||
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 = tr::lng_status_online(tr::now);
|
|
||||||
result.activeWidth = st::sessionWhenFont->width(tr::lng_status_online(tr::now));
|
|
||||||
} else {
|
|
||||||
const auto now = QDateTime::currentDateTime();
|
|
||||||
const auto lastTime = base::unixtime::parse(result.activeTime);
|
|
||||||
const auto nowDate = now.date();
|
|
||||||
const auto lastDate = lastTime.date();
|
|
||||||
if (lastDate == nowDate) {
|
|
||||||
result.active = lastTime.toString(cTimeFormat());
|
|
||||||
} else if (lastDate.year() == nowDate.year()
|
|
||||||
&& lastDate.weekNumber() == nowDate.weekNumber()) {
|
|
||||||
result.active = langDayOfWeek(lastDate);
|
|
||||||
} else {
|
|
||||||
result.active = lastDate.toString(qsl("d.MM.yy"));
|
|
||||||
}
|
|
||||||
result.activeWidth = st::sessionWhenFont->width(result.active);
|
|
||||||
}
|
|
||||||
|
|
||||||
ResizeEntry(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SessionsContent::ResizeEntry(Entry &entry) {
|
void SessionsContent::ResizeEntry(Entry &entry) {
|
||||||
|
entry.activeWidth = st::sessionWhenFont->width(entry.active);
|
||||||
|
|
||||||
const auto available = st::boxWideWidth
|
const auto available = st::boxWideWidth
|
||||||
- st::sessionPadding.left()
|
- st::sessionPadding.left()
|
||||||
- st::sessionTerminateSkip;
|
- st::sessionTerminateSkip;
|
||||||
|
@ -325,13 +248,7 @@ void SessionsContent::ResizeEntry(Entry &entry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionsContent::shortPollSessions() {
|
void SessionsContent::shortPollSessions() {
|
||||||
if (_shortPollRequest) {
|
_authorizations->reload();
|
||||||
return;
|
|
||||||
}
|
|
||||||
_shortPollRequest = _api.request(MTPaccount_GetAuthorizations(
|
|
||||||
)).done([=](const MTPaccount_Authorizations &result) {
|
|
||||||
got(result);
|
|
||||||
}).send();
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,10 +273,9 @@ void SessionsContent::terminate(Fn<void()> terminateRequest, QString message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionsContent::terminateOne(uint64 hash) {
|
void SessionsContent::terminateOne(uint64 hash) {
|
||||||
|
const auto weak = Ui::MakeWeak(this);
|
||||||
auto callback = [=] {
|
auto callback = [=] {
|
||||||
_api.request(MTPaccount_ResetAuthorization(
|
auto done = crl::guard(weak, [=](const MTPBool &result) {
|
||||||
MTP_long(hash)
|
|
||||||
)).done([=](const MTPBool &result) {
|
|
||||||
_inner->terminatingOne(hash, false);
|
_inner->terminatingOne(hash, false);
|
||||||
const auto getHash = [](const Entry &entry) {
|
const auto getHash = [](const Entry &entry) {
|
||||||
return entry.hash;
|
return entry.hash;
|
||||||
|
@ -372,24 +288,29 @@ void SessionsContent::terminateOne(uint64 hash) {
|
||||||
removeByHash(_data.incomplete);
|
removeByHash(_data.incomplete);
|
||||||
removeByHash(_data.list);
|
removeByHash(_data.list);
|
||||||
_inner->showData(_data);
|
_inner->showData(_data);
|
||||||
}).fail([=](const RPCError &error) {
|
});
|
||||||
|
auto fail = crl::guard(weak, [=](const RPCError &error) {
|
||||||
_inner->terminatingOne(hash, false);
|
_inner->terminatingOne(hash, false);
|
||||||
}).send();
|
});
|
||||||
|
_authorizations->requestTerminate(
|
||||||
|
std::move(done),
|
||||||
|
std::move(fail),
|
||||||
|
hash);
|
||||||
_inner->terminatingOne(hash, true);
|
_inner->terminatingOne(hash, true);
|
||||||
};
|
};
|
||||||
terminate(std::move(callback), tr::lng_settings_reset_one_sure(tr::now));
|
terminate(std::move(callback), tr::lng_settings_reset_one_sure(tr::now));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionsContent::terminateAll() {
|
void SessionsContent::terminateAll() {
|
||||||
|
const auto weak = Ui::MakeWeak(this);
|
||||||
auto callback = [=] {
|
auto callback = [=] {
|
||||||
_api.request(MTPauth_ResetAuthorizations(
|
const auto reset = crl::guard(weak, [=] {
|
||||||
)).done([=](const MTPBool &result) {
|
_authorizations->cancelCurrentRequest();
|
||||||
_api.request(base::take(_shortPollRequest)).cancel();
|
|
||||||
shortPollSessions();
|
shortPollSessions();
|
||||||
}).fail([=](const RPCError &result) {
|
});
|
||||||
_api.request(base::take(_shortPollRequest)).cancel();
|
_authorizations->requestTerminate(
|
||||||
shortPollSessions();
|
[=](const MTPBool &result) { reset(); },
|
||||||
}).send();
|
[=](const RPCError &result) { reset(); });
|
||||||
_loading = true;
|
_loading = true;
|
||||||
};
|
};
|
||||||
terminate(std::move(callback), tr::lng_settings_reset_sure(tr::now));
|
terminate(std::move(callback), tr::lng_settings_reset_sure(tr::now));
|
||||||
|
|
|
@ -98,20 +98,6 @@ std::map<int, const char*> BetaLogs() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
QString FormatVersionDisplay(int version) {
|
|
||||||
return QString::number(version / 1000000)
|
|
||||||
+ '.' + QString::number((version % 1000000) / 1000)
|
|
||||||
+ ((version % 1000)
|
|
||||||
? ('.' + QString::number(version % 1000))
|
|
||||||
: QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FormatVersionPrecise(int version) {
|
|
||||||
return QString::number(version / 1000000)
|
|
||||||
+ '.' + QString::number((version % 1000000) / 1000)
|
|
||||||
+ '.' + QString::number(version % 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Changelogs::Changelogs(not_null<Main::Session*> session, int oldVersion)
|
Changelogs::Changelogs(not_null<Main::Session*> session, int oldVersion)
|
||||||
|
@ -216,4 +202,18 @@ void Changelogs::addBetaLog(int changeVersion, const char *changes) {
|
||||||
addLocalLog(log);
|
addLocalLog(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString FormatVersionDisplay(int version) {
|
||||||
|
return QString::number(version / 1000000)
|
||||||
|
+ '.' + QString::number((version % 1000000) / 1000)
|
||||||
|
+ ((version % 1000)
|
||||||
|
? ('.' + QString::number(version % 1000))
|
||||||
|
: QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FormatVersionPrecise(int version) {
|
||||||
|
return QString::number(version / 1000000)
|
||||||
|
+ '.' + QString::number((version % 1000000) / 1000)
|
||||||
|
+ '.' + QString::number(version % 1000);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
|
@ -15,6 +15,9 @@ class Session;
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
[[nodiscard]] QString FormatVersionDisplay(int version);
|
||||||
|
[[nodiscard]] QString FormatVersionPrecise(int version);
|
||||||
|
|
||||||
class Changelogs : public base::has_weak_ptr, private base::Subscriber {
|
class Changelogs : public base::has_weak_ptr, private base::Subscriber {
|
||||||
public:
|
public:
|
||||||
Changelogs(not_null<Main::Session*> session, int oldVersion);
|
Changelogs(not_null<Main::Session*> session, int oldVersion);
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "core/changelogs.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
|
@ -448,7 +449,7 @@ bool UnpackUpdate(const QString &filepath) {
|
||||||
|
|
||||||
// create tdata/version file
|
// create tdata/version file
|
||||||
tempDir.mkdir(QDir(tempDirPath + qsl("/tdata")).absolutePath());
|
tempDir.mkdir(QDir(tempDirPath + qsl("/tdata")).absolutePath());
|
||||||
std::wstring versionString = ((version % 1000) ? QString("%1.%2.%3").arg(int(version / 1000000)).arg(int((version % 1000000) / 1000)).arg(int(version % 1000)) : QString("%1.%2").arg(int(version / 1000000)).arg(int((version % 1000000) / 1000))).toStdWString();
|
std::wstring versionString = FormatVersionDisplay(version).toStdWString();
|
||||||
|
|
||||||
const auto versionNum = VersionInt(version);
|
const auto versionNum = VersionInt(version);
|
||||||
const auto versionLen = VersionInt(versionString.size() * sizeof(VersionChar));
|
const auto versionLen = VersionInt(versionString.size() * sizeof(VersionChar));
|
||||||
|
|
Loading…
Add table
Reference in a new issue