tdesktop/Telegram/SourceFiles/core/changelogs.cpp

201 lines
5.1 KiB
C++
Raw Normal View History

/*
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 "core/changelogs.h"
#include "lang/lang_keys.h"
2020-06-15 16:25:02 +00:00
#include "core/application.h"
#include "main/main_domain.h"
#include "main/main_session.h"
#include "storage/storage_domain.h"
#include "data/data_session.h"
2022-01-24 16:33:30 +00:00
#include "base/qt/qt_common_adapters.h"
#include "mainwindow.h"
#include "apiwrap.h"
namespace Core {
namespace {
std::map<int, const char*> BetaLogs() {
return {
{
4004002,
"- Send photos and video files hidden by a spoiler effect.\n"
"- Set a public photo for those who are restricted to see "
"your profile photo in the Privacy Settings.\n"
"- Bug fixes and other minor improvements.\n"
},
{
4004003,
"- Support for anonymous numbers from the Fragment.com platform.\n"
"- Fix a crash in own profile photo updating.\n"
"- Bug fixes and other minor improvements.\n"
},
{
4005004,
"- Allow wide range of interface scale options.\n"
"- Show opened chat name in the window title.\n"
"- Bug fixes and other minor improvements.\n"
"- Fix updating on macOS older than 10.14.\n"
},
{
4005006,
"- Try enabling non-fractional scale "
"High DPI support on Windows and Linux.\n"
"- Experimental setting for fractional scale "
"High DPI support on Windows and Linux.\n"
"- Fix navigation to bottom problems in groups you didn't join.\n"
"- Fix a crash in chat export settings changes.\n"
"- Fix a crash in sending some of JPEG images.\n"
"- Fix CJK fonts on Windows.\n"
},
{
4005007,
"- Fix glitches after moving window to another screen.\n",
},
{
4005008,
"- Allow opening another account in a new window "
"(see Settings > Advanced > Experimental Settings).\n"
"- A lot of bugfixes for working with more than one window.\n"
}
};
};
} // namespace
2019-07-24 11:45:24 +00:00
Changelogs::Changelogs(not_null<Main::Session*> session, int oldVersion)
: _session(session)
, _oldVersion(oldVersion) {
_session->data().chatsListChanges(
) | rpl::filter([](Data::Folder *folder) {
return !folder;
}) | rpl::start_with_next([=] {
requestCloudLogs();
}, _chatsSubscription);
}
std::unique_ptr<Changelogs> Changelogs::Create(
2019-07-24 11:45:24 +00:00
not_null<Main::Session*> session) {
auto &local = Core::App().domain().local();
2020-06-15 16:25:02 +00:00
const auto oldVersion = local.oldVersion();
local.clearOldVersion();
return (oldVersion > 0 && oldVersion < AppVersion)
? std::make_unique<Changelogs>(session, oldVersion)
: nullptr;
}
void Changelogs::requestCloudLogs() {
_chatsSubscription.destroy();
const auto callback = [this](const MTPUpdates &result) {
_session->api().applyUpdates(result);
auto resultEmpty = true;
switch (result.type()) {
case mtpc_updateShortMessage:
case mtpc_updateShortChatMessage:
case mtpc_updateShort:
resultEmpty = false;
break;
case mtpc_updatesCombined:
2019-07-05 13:38:38 +00:00
resultEmpty = result.c_updatesCombined().vupdates().v.isEmpty();
break;
case mtpc_updates:
2019-07-05 13:38:38 +00:00
resultEmpty = result.c_updates().vupdates().v.isEmpty();
break;
case mtpc_updatesTooLong:
case mtpc_updateShortSentMessage:
LOG(("API Error: Bad updates type in app changelog."));
break;
}
if (resultEmpty) {
addLocalLogs();
}
};
_session->api().requestChangelog(
FormatVersionPrecise(_oldVersion),
crl::guard(this, callback));
}
void Changelogs::addLocalLogs() {
if (AppBetaVersion || cAlphaVersion()) {
addBetaLogs();
}
if (!_addedSomeLocal) {
const auto text = tr::lng_new_version_wrap(
tr::now,
lt_version,
QString::fromLatin1(AppVersionStr),
lt_changes,
2019-06-19 15:09:03 +00:00
tr::lng_new_version_minor(tr::now),
lt_link,
2021-02-04 16:42:32 +00:00
Core::App().changelogLink());
addLocalLog(text.trimmed());
}
}
void Changelogs::addLocalLog(const QString &text) {
auto textWithEntities = TextWithEntities{ text };
TextUtilities::ParseEntities(textWithEntities, TextParseLinks);
2019-02-11 12:50:35 +00:00
_session->data().serviceNotification(textWithEntities);
_addedSomeLocal = true;
};
void Changelogs::addBetaLogs() {
for (const auto &[version, changes] : BetaLogs()) {
addBetaLog(version, changes);
}
}
void Changelogs::addBetaLog(int changeVersion, const char *changes) {
if (_oldVersion >= changeVersion) {
return;
}
const auto text = [&] {
static const auto simple = u"\n- "_q;
static const auto separator = QString::fromUtf8("\n\xE2\x80\xA2 ");
auto result = QString::fromUtf8(changes).trimmed();
if (result.startsWith(base::StringViewMid(simple, 1))) {
2020-07-02 19:02:59 +00:00
result = separator.mid(1) + result.mid(simple.size() - 1);
}
return result.replace(simple, separator);
}();
const auto version = FormatVersionDisplay(changeVersion);
2022-11-29 21:46:36 +00:00
const auto log = u"New in version %1 beta:\n\n"_q.arg(version) + text;
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