diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 307b7997e..be2a71f02 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -44,11 +44,25 @@ constexpr auto kSmallDelayMs = 5; } // namespace -ApiWrap::ApiWrap() -: _messageDataResolveDelayed([this] { resolveMessageDatas(); }) +ApiWrap::ApiWrap(gsl::not_null 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; } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 086a6a479..513f22270 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -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 *getChatsFromMessagesChats(const MTPmessages_Chats &chats) { @@ -36,10 +38,11 @@ inline const MTPVector *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 session); + void start(); void applyUpdates(const MTPUpdates &updates, uint64 sentMessageRandomId = 0); using RequestMessageDataCallback = base::lambda; @@ -121,6 +124,9 @@ private: void stickerSetDisenabled(mtpRequestId requestId); void stickersSaveOrder(); + gsl::not_null _session; + mtpRequestId _changelogSubscription = 0; + MessageDataRequests _messageDataRequests; QMap _channelMessageDataRequests; SingleQueuedInvokation _messageDataResolveDelayed; diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 80eaafed6..ceab0a689 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -155,7 +155,7 @@ QString AuthSessionData::getSoundPath(const QString &key) const { AuthSession::AuthSession(UserId userId) : _userId(userId) , _autoLockTimer([this] { checkAutoLock(); }) -, _api(std::make_unique()) +, _api(std::make_unique(this)) , _calls(std::make_unique()) , _downloader(std::make_unique()) , _notifications(std::make_unique(this)) { @@ -167,6 +167,7 @@ AuthSession::AuthSession(UserId userId) _shouldLockAt = 0; notifications().updateAll(); }); + _api->start(); } bool AuthSession::Exists() { diff --git a/Telegram/SourceFiles/base/observer.h b/Telegram/SourceFiles/base/observer.h index 2989ab870..66c6146db 100644 --- a/Telegram/SourceFiles/base/observer.h +++ b/Telegram/SourceFiles/base/observer.h @@ -229,10 +229,14 @@ private: break; } } while (_current); + } + bool destroyMeIfEmpty() const { if (empty()) { _observable->_data.reset(); + return true; } + return false; } CommonObservable *_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); diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 8872ff417..48cda4d77 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -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); diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 042979477..b6b68bd4e 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -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() { diff --git a/Telegram/SourceFiles/lang/lang_keys.cpp b/Telegram/SourceFiles/lang/lang_keys.cpp index 33d500108..56c888af2 100644 --- a/Telegram/SourceFiles/lang/lang_keys.cpp +++ b/Telegram/SourceFiles/lang/lang_keys.cpp @@ -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) { diff --git a/Telegram/SourceFiles/lang/lang_keys.h b/Telegram/SourceFiles/lang/lang_keys.h index 655edde80..542e183f9 100644 --- a/Telegram/SourceFiles/lang/lang_keys.h +++ b/Telegram/SourceFiles/lang/lang_keys.h @@ -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(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index da585be15..8fae85145 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -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); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 8247d66b9..bce2168fc 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -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(); diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index b06fb3567..a6a17a978 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -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(); diff --git a/Telegram/SourceFiles/messenger.h b/Telegram/SourceFiles/messenger.h index c5a8410a5..ebe077fee 100644 --- a/Telegram/SourceFiles/messenger.h +++ b/Telegram/SourceFiles/messenger.h @@ -147,7 +147,6 @@ public: void killDownloadSessionsStop(MTP::DcId dcId); void checkLocalTime(); - void checkMapVersion(); void setupPasscode(); void clearPasscode(); base::Observable &passcodedChanged() { diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 8cd9ccfc2..c92e96518 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -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(MTP_int(ApiId), MTP_string(deviceModel), MTP_string(systemVersion), MTP_string(cApiAppVersion()), MTP_string(systemLangCode), MTP_string(langPack), MTP_string(cloudLangCode), mtpRequest()); + initWrapper = MTPInitConnection(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); } diff --git a/Telegram/SourceFiles/passcodewidget.cpp b/Telegram/SourceFiles/passcodewidget.cpp index 492d02ad6..eb123c5df 100644 --- a/Telegram/SourceFiles/passcodewidget.cpp +++ b/Telegram/SourceFiles/passcodewidget.cpp @@ -77,8 +77,6 @@ void PasscodeWidget::onSubmit() { } else { App::wnd()->setupIntro(); } - - App::app()->checkMapVersion(); } else { cSetPasscodeBadTries(cPasscodeBadTries() + 1); cSetPasscodeLastTry(getms(true)); diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index bb93c2c0d..610dc0c58 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -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 = {