From 48f393afc52549605c9b712255df92a60f892a07 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 13 Nov 2014 15:35:07 +0300 Subject: [PATCH] Added migrate to HTTPS modal --- app/js/controllers.js | 5 +-- app/js/i18n.js | 6 ++-- app/js/lib/config.js | 3 +- app/js/locales/en-us.json | 3 +- app/js/services.js | 44 +++++++++++++++++++++++-- app/partials/desktop/confirm_modal.html | 1 + 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 47601d17..4803b225 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -34,7 +34,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) return; } if (location.protocol == 'http:' && - (location.host == 'zhukov.github.io' || location.host == 'web.telegram.org')) { + Config.App.domains.indexOf(location.hostname) != -1) { location = 'https://web.telegram.org'; } }); @@ -300,7 +300,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) ChangelogNotifyService.checkUpdate(); }) - .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager) { + .controller('AppIMController', function ($scope, $location, $routeParams, $modal, $rootScope, $modalStack, MtpApiManager, AppUsersManager, AppChatsManager, ContactsSelectService, ChangelogNotifyService, ErrorService, AppRuntimeManager, HttpsMigrateService) { $scope.$on('$routeUpdate', updateCurDialog); @@ -428,6 +428,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) } ChangelogNotifyService.checkUpdate(); + HttpsMigrateService.start(); }) .controller('AppImDialogsController', function ($scope, $location, $q, $timeout, $routeParams, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, PhonebookContactsService, ErrorService) { diff --git a/app/js/i18n.js b/app/js/i18n.js index 197fc73a..8fa346b5 100644 --- a/app/js/i18n.js +++ b/app/js/i18n.js @@ -22,8 +22,10 @@ angular.module('myApp.i18n', ['izhukov.utils']) } function parseMarkdownString(msgstr, msgid) { - msgstr = msgstr.replace(/\*\*(.+?)\*\*/g, "$1") - .replace(/\n/g, "
"); + msgstr = msgstr + .replace(/\*\*(.+?)\*\*/g, "$1") + .replace(/\n| /g, "
"); + return msgstr; } diff --git a/app/js/lib/config.js b/app/js/lib/config.js index dd2ff437..08c5284f 100644 --- a/app/js/lib/config.js +++ b/app/js/lib/config.js @@ -21,7 +21,8 @@ Config = window.Config || {}; Config.App = { id: 2496, hash: '8da85b0d5bfe62527e5b244c209159c3', - version: '0.3.4' + version: '0.3.4', + domains: ['web.telegram.org', 'zhukov.github.io'] }; Config.Modes = { diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 5d3bda33..fe498b05 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -127,7 +127,8 @@ "confirm_modal_forward_to_peer": "Forward to {peer}?", "confirm_modal_send_to_peer": "Send to {peer}?", "confirm_modal_share_file_peer": "Share with {peer}?", - "confirm_modal_apply_lang_with_reload_md": "Language preference was saved.\nReload the App now?", + "confirm_modal_apply_lang_with_reload_md": "Reload the App to apply language?", + "confirm_modal_migrate_to_https_md": "Telegram Web now supports additional SSL encryption. Would you like to switch to HTTPS?\nThe HTTP version will be disabled soon.", "confirm_modal_are_u_sure": "Are you sure?", "confirm_modal_logout_submit": "Log Out", diff --git a/app/js/services.js b/app/js/services.js index 628417b0..6516490b 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -3813,12 +3813,12 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) }, selectContact: function (options) { return select (false, options); - }, + } } }) -.service('ChangelogNotifyService', function (Storage, $rootScope, $http, $modal) { +.service('ChangelogNotifyService', function (Storage, $rootScope, $modal) { function versionCompare (ver1, ver2) { if (typeof ver1 !== 'string') { @@ -3882,3 +3882,43 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) showChangelog: showChangelog } }) + +.service('HttpsMigrateService', function (ErrorService, Storage) { + + var started = false; + + function check () { + Storage.get('https_dismiss').then(function (ts) { + if (!ts || tsNow() > ts + 43200000) { + ErrorService.confirm({ + type: 'MIGRATE_TO_HTTPS' + }).then(function () { + var popup; + try { + popup = window.open('https://web.telegram.org', '_blank'); + } catch (e) {} + if (!popup) { + location = 'https://web.telegram.org'; + } + }, function () { + Storage.set({https_dismiss: tsNow()}); + }); + } + }); + } + + function start () { + if (started || + location.protocol != 'http:' || + Config.App.domains.indexOf(location.hostname) == -1) { + return; + } + started = true; + setTimeout(check, 120000); + } + + return { + start: start, + check: check + } +}) diff --git a/app/partials/desktop/confirm_modal.html b/app/partials/desktop/confirm_modal.html index 7990cd6e..52c36171 100644 --- a/app/partials/desktop/confirm_modal.html +++ b/app/partials/desktop/confirm_modal.html @@ -36,6 +36,7 @@
+