Switch to the server side changelogs.

This commit is contained in:
John Preston 2017-06-05 16:33:45 +03:00
parent d9785f6071
commit 5d0e89db5d
15 changed files with 41 additions and 65 deletions

View file

@ -44,11 +44,25 @@ constexpr auto kSmallDelayMs = 5;
} // namespace
ApiWrap::ApiWrap()
: _messageDataResolveDelayed([this] { resolveMessageDatas(); })
ApiWrap::ApiWrap(gsl::not_null<AuthSession*> session)
: _session(session)
, _messageDataResolveDelayed([this] { resolveMessageDatas(); })
, _webPagesTimer([this] { resolveWebPages(); })
, _draftsSaveTimer([this] { saveDraftsToCloud(); }) {
}
void ApiWrap::start() {
Window::Theme::Background()->start();
auto oldVersion = Local::oldMapVersion();
if (oldVersion > 0 && oldVersion < AppVersion) {
_changelogSubscription = subscribe(_session->data().moreChatsLoaded(), [this, oldVersion] {
auto oldVersionString = qsl("%1.%2.%3").arg(oldVersion / 1000000).arg((oldVersion % 1000000) / 1000).arg(oldVersion % 1000);
request(MTPhelp_GetAppChangelog(MTP_string(oldVersionString))).done([this](const MTPUpdates &result) {
applyUpdates(result);
}).send();
unsubscribe(base::take(_changelogSubscription));
});
}
}
void ApiWrap::applyUpdates(const MTPUpdates &updates, uint64 sentMessageRandomId) {
@ -625,7 +639,7 @@ void ApiWrap::requestSelfParticipant(ChannelData *channel) {
} break;
case mtpc_channelParticipantCreator: {
auto &d = p.vparticipant.c_channelParticipantCreator();
channel->inviter = AuthSession::CurrentUserId();
channel->inviter = _session->userId();
channel->inviteDate = date(MTP_int(channel->date));
} break;
case mtpc_channelParticipantModerator: {
@ -1197,7 +1211,7 @@ PeerData *ApiWrap::notifySettingReceived(MTPInputNotifyPeer notifyPeer, const MT
}
} break;
}
AuthSession::Current().notifications().checkDelayed();
_session->notifications().checkDelayed();
return requestedPeer;
}

View file

@ -24,6 +24,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "core/single_timer.h"
#include "mtproto/sender.h"
class AuthSession;
namespace Api {
inline const MTPVector<MTPChat> *getChatsFromMessagesChats(const MTPmessages_Chats &chats) {
@ -36,10 +38,11 @@ inline const MTPVector<MTPChat> *getChatsFromMessagesChats(const MTPmessages_Cha
} // namespace Api
class ApiWrap : private MTP::Sender {
class ApiWrap : private MTP::Sender, private base::Subscriber {
public:
ApiWrap();
ApiWrap(gsl::not_null<AuthSession*> session);
void start();
void applyUpdates(const MTPUpdates &updates, uint64 sentMessageRandomId = 0);
using RequestMessageDataCallback = base::lambda<void(ChannelData*, MsgId)>;
@ -121,6 +124,9 @@ private:
void stickerSetDisenabled(mtpRequestId requestId);
void stickersSaveOrder();
gsl::not_null<AuthSession*> _session;
mtpRequestId _changelogSubscription = 0;
MessageDataRequests _messageDataRequests;
QMap<ChannelData*, MessageDataRequests> _channelMessageDataRequests;
SingleQueuedInvokation _messageDataResolveDelayed;

View file

@ -155,7 +155,7 @@ QString AuthSessionData::getSoundPath(const QString &key) const {
AuthSession::AuthSession(UserId userId)
: _userId(userId)
, _autoLockTimer([this] { checkAutoLock(); })
, _api(std::make_unique<ApiWrap>())
, _api(std::make_unique<ApiWrap>(this))
, _calls(std::make_unique<Calls::Instance>())
, _downloader(std::make_unique<Storage::Downloader>())
, _notifications(std::make_unique<Window::Notifications::System>(this)) {
@ -167,6 +167,7 @@ AuthSession::AuthSession(UserId userId)
_shouldLockAt = 0;
notifications().updateAll();
});
_api->start();
}
bool AuthSession::Exists() {

View file

@ -229,10 +229,14 @@ private:
break;
}
} while (_current);
}
bool destroyMeIfEmpty() const {
if (empty()) {
_observable->_data.reset();
return true;
}
return false;
}
CommonObservable<EventType, Handler> *_observable = nullptr;
@ -282,6 +286,9 @@ private:
this->notifyEnumerate([this, &event]() {
this->_current->handler(event);
});
if (this->destroyMeIfEmpty()) {
return;
}
}
_handling = false;
UnregisterActiveObservable(&this->_callHandlers);
@ -329,6 +336,9 @@ private:
this->notifyEnumerate([this]() {
this->_current->handler();
});
if (this->destroyMeIfEmpty()) {
return;
}
}
_handling = false;
UnregisterActiveObservable(&this->_callHandlers);

View file

@ -117,8 +117,8 @@ void SessionsBox::gotAuthorizations(const MTPaccount_Authorizations &result) {
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());
} else {
appVer = QString();
//} else {
// appVer = QString();
}
} else {
appName = qs(d.vapp_name);// +qsl(" for ") + qs(d.vplatform);

View file

@ -289,9 +289,6 @@ inline const char *cApiSystemVersion() {
return "Linux";
#endif
}
inline QString cApiAppVersion() {
return QString::number(AppVersion);
}
extern QString gKeyFile;
inline const QString &cDataFile() {

View file

@ -22,20 +22,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "lang/lang_file_parser.h"
//#define NEW_VER_TAG lt_link
//#define NEW_VER_TAG_VALUE "https://telegram.org/blog/desktop-1-0"
QString langNewVersionText() {
#ifdef NEW_VER_TAG
return lng_new_version_text(NEW_VER_TAG, QString::fromUtf8(NEW_VER_TAG_VALUE));
#else // NEW_VER_TAG
return lang(lng_new_version_text);
#endif // NEW_VER_TAG
}
#undef NEW_VER_TAG_VALUE
#undef NEW_VER_TAG
bool langFirstNameGoesSecond() {
auto fullname = lang(lng_full_name__tagged);
for (auto begin = fullname.constData(), ch = begin, end = ch + fullname.size(); ch != end; ++ch) {

View file

@ -124,6 +124,4 @@ inline QString langDateTimeFull(const QDateTime &date) {
return lng_mediaview_date_time(lt_date, langDayOfMonthFull(date.date()), lt_time, date.time().toString(cTimeFormat()));
}
QString langNewVersionText();
bool langFirstNameGoesSecond();

View file

@ -303,12 +303,6 @@ void MainWindow::serviceNotification(const TextWithEntities &message, const MTPM
_main->serviceNotification(message, media, date);
}
void MainWindow::serviceNotificationLocal(QString text) {
EntitiesInText entities;
textParseEntities(text, _historyTextNoMonoOptions.flags, &entities);
serviceNotification({ text, entities });
}
void MainWindow::showDelayedServiceMsgs() {
for (auto &delayed : base::take(_delayedServiceMsgs)) {
serviceNotification(delayed.message, delayed.media, delayed.date, true);

View file

@ -92,7 +92,6 @@ public:
void setupIntro();
void setupMain(const MTPUser *user = nullptr);
void serviceNotification(const TextWithEntities &message, const MTPMessageMedia &media = MTP_messageMediaEmpty(), int32 date = 0, bool force = false);
void serviceNotificationLocal(QString text);
void sendServiceHistoryRequest();
void showDelayedServiceMsgs();

View file

@ -165,10 +165,6 @@ Messenger::Messenger() : QObject()
QNetworkProxyFactory::setUseSystemConfiguration(true);
#endif // !TDESKTOP_DISABLE_NETWORK_PROXY
if (state != Local::ReadMapPassNeeded) {
checkMapVersion();
}
_window->updateIsActive(Global::OnlineFocusTimeout());
if (!Shortcuts::errors().isEmpty()) {
@ -695,25 +691,6 @@ void Messenger::uploadProfilePhoto(const QImage &tosend, const PeerId &peerId) {
App::uploader()->uploadMedia(newId, ready);
}
void Messenger::checkMapVersion() {
if (Local::oldMapVersion() < AppVersion) {
if (Local::oldMapVersion()) {
QString versionFeatures;
if ((cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1001003) {
versionFeatures = QString::fromUtf8("\xE2\x80\x94 Improved video messages playback.\n\xE2\x80\x94 Video and audio messages now play one after another.");
} else if (!(cAlphaVersion() || cBetaVersion()) && Local::oldMapVersion() < 1001000) {
versionFeatures = langNewVersionText();
} else {
versionFeatures = lang(lng_new_version_minor).trimmed();
}
if (!versionFeatures.isEmpty()) {
versionFeatures = lng_new_version_wrap(lt_version, QString::fromLatin1(AppVersionStr.c_str()), lt_changes, versionFeatures, lt_link, qsl("https://desktop.telegram.org/changelog"));
_window->serviceNotificationLocal(versionFeatures);
}
}
}
}
void Messenger::setupPasscode() {
_window->setupPasscode();
_passcodedChanged.notify();

View file

@ -147,7 +147,6 @@ public:
void killDownloadSessionsStop(MTP::DcId dcId);
void checkLocalTime();
void checkMapVersion();
void setupPasscode();
void clearPasscode();
base::Observable<void> &passcodedChanged() {

View file

@ -785,7 +785,7 @@ void ConnectionPrivate::tryToSend() {
auto langPack = "tdesktop";
auto deviceModel = (_dcType == DcType::Cdn) ? "n/a" : cApiDeviceModel();
auto systemVersion = (_dcType == DcType::Cdn) ? "n/a" : cApiSystemVersion();
initWrapper = MTPInitConnection<mtpRequest>(MTP_int(ApiId), MTP_string(deviceModel), MTP_string(systemVersion), MTP_string(cApiAppVersion()), MTP_string(systemLangCode), MTP_string(langPack), MTP_string(cloudLangCode), mtpRequest());
initWrapper = MTPInitConnection<mtpRequest>(MTP_int(ApiId), MTP_string(deviceModel), MTP_string(systemVersion), MTP_string(str_const_toString(AppVersionStr)), MTP_string(systemLangCode), MTP_string(langPack), MTP_string(cloudLangCode), mtpRequest());
initSizeInInts = (initWrapper.innerLength() >> 2) + 2;
initSize = initSizeInInts * sizeof(mtpPrime);
}

View file

@ -77,8 +77,6 @@ void PasscodeWidget::onSubmit() {
} else {
App::wnd()->setupIntro();
}
App::app()->checkMapVersion();
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));

View file

@ -122,9 +122,6 @@ void fillCodes() {
}
});
});
Codes.insert(qsl("newversiontext"), [] {
App::wnd()->serviceNotificationLocal(langNewVersionText());
});
auto audioFilters = qsl("Audio files (*.wav *.mp3);;") + FileDialog::AllFilesFilter();
auto audioKeys = {