diff --git a/README.md b/README.md index f9af24c5..2c561ef8 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Here are some screenshots of the interface: * Emoji keyboard * Send plain-text messages to user or group * Send files (photos or documents) via attach icon or drag'n'drop +* Desktop notifications ### Unsupported at the moment @@ -38,7 +39,6 @@ Here are some screenshots of the interface: * Secret chats * Create new group * Edit group photo/title/participants -* Desktop notifications * Settings * Edit profile/userpic * Contacts @@ -62,6 +62,13 @@ Install [node.js](http://nodejs.org/) and run `node server.js`. Open page http:/ #### Running as Chrome Packaged App It is possible to run this application in Chrome browser as a packaged app. In order to do this, open this URL in Chrome: `chrome://extensions/`, then tick "Developer mode" and press "Load unpacked extension...". Select the downloaded `app` folder and Webogram application should appear in the list. +Also it's necessary to replace following line in index.html: +`````` +with: +`````` + + +You can also download this application from Chrome Web Store: [chrome.google.com/webstore/detail/telegram-unofficial/clhhggbfdinjmjhajaheehoeibfljjno](https://chrome.google.com/webstore/detail/telegram-unofficial/clhhggbfdinjmjhajaheehoeibfljjno). This is more secure way to use app than plain HTTP in web, because sources are downloaded only once and via HTTPS. ### Third party libraries diff --git a/app/index.html b/app/index.html index 10a18abb..3ecffbef 100644 --- a/app/index.html +++ b/app/index.html @@ -21,6 +21,16 @@
+ + @@ -38,12 +48,12 @@ - + - - + + diff --git a/app/js/controllers.js b/app/js/controllers.js index 110e0743..5da74278 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -232,13 +232,14 @@ angular.module('myApp.controllers', []) }) - .controller('AppImHistoryController', function ($scope, $location, $timeout, $rootScope, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, IdleManager) { + .controller('AppImHistoryController', function ($scope, $location, $timeout, $rootScope, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, IdleManager, StatusManager) { $scope.$watch('curDialog.peer', applyDialogSelect); ApiUpdatesManager.attach(); IdleManager.start(); + StatusManager.start(); $scope.history = []; $scope.typing = {}; diff --git a/app/js/services.js b/app/js/services.js index 5262f54b..bee47a03 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -1807,14 +1807,17 @@ angular.module('myApp.services', []) $rootScope.idle = {isIDLE: false}; - var toPromise; + var toPromise, started = false; return { start: start }; function start () { - $($window).on('blur focus keydown mousedown touchstart', onEvent); + if (!started) { + started = true; + $($window).on('blur focus keydown mousedown touchstart', onEvent); + } } function onEvent (e) { @@ -1847,6 +1850,46 @@ angular.module('myApp.services', []) } }) +.service('StatusManager', function ($timeout, $rootScope, MtpApiManager, IdleManager) { + + var toPromise, lastOnlineUpdated = 0, started = false; + + return { + start: start + }; + + function start() { + if (!started) { + started = true; + $rootScope.$watch('idle.isIDLE', checkIDLE); + } + } + + function sendUpdateStatusReq(offline) { + var date = (1 * new Date()); + if (offline && !lastOnlineUpdated || + !offline && (date - lastOnlineUpdated) < 50000) { + return; + } + lastOnlineUpdated = offline ? 0 : date; + return MtpApiManager.invokeApi('account.updateStatus', { + offline: offline + }); + } + + function checkIDLE() { + toPromise && $timeout.cancel(toPromise); + if ($rootScope.idle.isIDLE) { + toPromise = $timeout(function () { + sendUpdateStatusReq(true); + }, 5000); + } else { + sendUpdateStatusReq(false); + toPromise = $timeout(checkIDLE, 60000); + } + } + +}) .service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, MtpApiManager, AppPeersManager, IdleManager) { @@ -1921,7 +1964,9 @@ angular.module('myApp.services', []) $($window).on('click', requestPermission); } - $($window).on('beforeunload', notificationsClear); + try { + $($window).on('beforeunload', notificationsClear); + } catch (e) {} } function requestPermission() { diff --git a/app/manifest.json b/app/manifest.json index 7a13a6bb..76cfc011 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,6 +1,6 @@ { "name": "Telegram UNOFFICIAL", - "version": "0.0.9", + "version": "0.0.10", "short_name": "Webogram", "manifest_version": 2, "app": {