Improve in-app changelogs for alpha version.

This commit is contained in:
John Preston 2017-06-30 13:32:10 +03:00
parent 197cdc3928
commit 7b496b3741
2 changed files with 37 additions and 16 deletions

View File

@ -53,15 +53,39 @@ ApiWrap::ApiWrap(gsl::not_null<AuthSession*> session)
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, oldVersion](const MTPUpdates &result) {
requestAppChangelogs();
}
void ApiWrap::requestAppChangelogs() {
auto oldAppVersion = Local::oldMapVersion();
if (oldAppVersion > 0 && oldAppVersion < AppVersion) {
_changelogSubscription = subscribe(_session->data().moreChatsLoaded(), [this, oldAppVersion] {
auto oldVersionString = qsl("%1.%2.%3").arg(oldAppVersion / 1000000).arg((oldAppVersion % 1000000) / 1000).arg(oldAppVersion % 1000);
request(MTPhelp_GetAppChangelog(MTP_string(oldVersionString))).done([this, oldAppVersion](const MTPUpdates &result) {
applyUpdates(result);
auto addLocalChangelog = [this, oldVersion](int changeVersion, const char *changes) {
if (oldVersion < changeVersion) {
auto resultEmpty = true;
switch (result.type()) {
case mtpc_updateShortMessage:
case mtpc_updateShortChatMessage:
case mtpc_updateShort: resultEmpty = false; break;
case mtpc_updatesCombined: resultEmpty = result.c_updatesCombined().vupdates.v.isEmpty(); break;
case mtpc_updates: 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 && (cAlphaVersion() || cBetaVersion())) {
addLocalAlphaChangelogs(oldAppVersion);
}
}).send();
unsubscribe(base::take(_changelogSubscription));
});
}
}
void ApiWrap::addLocalAlphaChangelogs(int oldAppVersion) {
auto addLocalChangelog = [this, oldAppVersion](int changeVersion, const char *changes) {
if (oldAppVersion < changeVersion) {
auto changeVersionString = QString::number(changeVersion / 1000000) + '.' + QString::number((changeVersion % 1000000) / 1000) + ((changeVersion % 1000) ? ('.' + QString::number(changeVersion % 1000)) : QString());
auto text = qsl("New in version %1:\n\n").arg(changeVersionString) + QString::fromUtf8(changes).trimmed();
auto textWithEntities = TextWithEntities { text };
@ -69,14 +93,9 @@ void ApiWrap::start() {
App::main()->serviceNotification(textWithEntities, MTP_messageMediaEmpty(), unixtime());
}
};
if (cAlphaVersion() || cBetaVersion()) {
addLocalChangelog(1001008, "\xE2\x80\x94 Toggle night mode in the main menu.\n");
}
}).send();
unsubscribe(base::take(_changelogSubscription));
});
}
}
void ApiWrap::applyUpdates(const MTPUpdates &updates, uint64 sentMessageRandomId) {
App::main()->feedUpdates(updates, sentMessageRandomId);

View File

@ -101,6 +101,8 @@ private:
};
using MessageDataRequests = QMap<MsgId, MessageDataRequest>;
void requestAppChangelogs();
void addLocalAlphaChangelogs(int oldAppVersion);
void updatesReceived(const MTPUpdates &updates);
void checkQuitPreventFinished();