Browse Source

Improved drafts sync

master
Igor Zhukov 8 years ago
parent
commit
2a4c68827f
  1. 2
      app/js/app.js
  2. 28
      app/js/controllers.js
  3. 9
      app/js/lib/ng_utils.js
  4. 2
      webogram.sublime-project

2
app/js/app.js

@ -42,7 +42,7 @@ angular.module('myApp', [
StorageProvider.setPrefix('t_') StorageProvider.setPrefix('t_')
} }
$routeProvider.when('/', {templateUrl: templateUrl('welcome'), controller: 'AppWelcomeController'}) $routeProvider.when('/', {template: '', controller: 'AppWelcomeController'})
$routeProvider.when('/login', {templateUrl: templateUrl('login'), controller: 'AppLoginController'}) $routeProvider.when('/login', {templateUrl: templateUrl('login'), controller: 'AppLoginController'})
$routeProvider.when('/im', {templateUrl: templateUrl('im'), controller: 'AppIMController', reloadOnSearch: false}) $routeProvider.when('/im', {templateUrl: templateUrl('im'), controller: 'AppIMController', reloadOnSearch: false})
$routeProvider.otherwise({redirectTo: '/'}) $routeProvider.otherwise({redirectTo: '/'})

28
app/js/controllers.js

@ -2158,7 +2158,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$on('history_need_more', showMoreHistory) $scope.$on('history_need_more', showMoreHistory)
$rootScope.$watch('idle.isIDLE', function (newVal) { $rootScope.$watch('idle.isIDLE', function (newVal) {
if (!newVal && $scope.curDialog && $scope.curDialog.peerID && !$scope.historyFilter.mediaType && !$scope.historyState.skipped) { if (!newVal &&
$scope.curDialog &&
$scope.curDialog.peerID &&
!$scope.historyFilter.mediaType &&
!$scope.historyState.skipped) {
AppMessagesManager.readHistory($scope.curDialog.peerID) AppMessagesManager.readHistory($scope.curDialog.peerID)
} }
if (!newVal) { if (!newVal) {
@ -2217,6 +2221,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.toggleSlash = toggleSlash $scope.toggleSlash = toggleSlash
$rootScope.$watch('idle.isIDLE', function (newVal) { $rootScope.$watch('idle.isIDLE', function (newVal) {
if ($rootScope.idle.initial) {
return
}
if (newVal && $scope.curDialog.peerID) { if (newVal && $scope.curDialog.peerID) {
DraftsManager.syncDraft($scope.curDialog.peerID) DraftsManager.syncDraft($scope.curDialog.peerID)
} }
@ -2365,11 +2372,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
function resetDraft (newPeer, prevPeer) { function resetDraft (newPeer, prevPeer) {
if (prevPeer) { var prevPeerID = prevPeer ? AppPeersManager.getPeerID(prevPeer) : 0
var prevPeerID = AppPeersManager.getPeerID(prevPeer) if (prevPeerID) {
if (prevPeerID) { $scope.$broadcast('ui_message_before_send')
$timeout(function () {
DraftsManager.syncDraft(prevPeerID) DraftsManager.syncDraft(prevPeerID)
} resetDraft()
})
return
} }
updateMentions() updateMentions()
@ -2565,9 +2575,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return cancelEvent($event) return cancelEvent($event)
} }
function onMessageChange (newVal) { function onMessageChange (newVal, prevVal, a) {
// console.log('ctrl text changed', newVal) // console.log('ctrl text changed', newVal, prevVal);
// console.trace('ctrl text changed', newVal) if (newVal === '' && prevVal === '') {
return
}
if (newVal && newVal.length) { if (newVal && newVal.length) {
if (!$scope.historyFilter.mediaType && !$scope.historyState.skipped) { if (!$scope.historyFilter.mediaType && !$scope.historyState.skipped) {

9
app/js/lib/ng_utils.js

@ -1001,7 +1001,8 @@ angular.module('izhukov.utils', [])
}) })
.service('IdleManager', function ($rootScope, $window, $timeout) { .service('IdleManager', function ($rootScope, $window, $timeout) {
$rootScope.idle = {isIDLE: false}
$rootScope.idle = {isIDLE: false, initial: true}
var toPromise var toPromise
var started = false var started = false
@ -1031,7 +1032,7 @@ angular.module('izhukov.utils', [])
$($window).on(visibilityChange + ' blur focus keydown mousedown touchstart', onEvent) $($window).on(visibilityChange + ' blur focus keydown mousedown touchstart', onEvent)
setTimeout(function () { setTimeout(function () {
onEvent({type: 'blur'}) onEvent({type: 'blur', fake_initial: true})
}, 0) }, 0)
} }
} }
@ -1066,6 +1067,10 @@ angular.module('izhukov.utils', [])
}, 10) }, 10)
} }
if (e && !e.fake_initial) {
delete $rootScope.idle.initial;
}
if ($rootScope.idle.isIDLE == isIDLE) { if ($rootScope.idle.isIDLE == isIDLE) {
return return
} }

2
webogram.sublime-project vendored

@ -4,7 +4,7 @@
{ {
"follow_symlinks": true, "follow_symlinks": true,
"path": ".", "path": ".",
"folder_exclude_patterns": ["*dist*", "node_modules", "releases", ".tx", "css"], "folder_exclude_patterns": ["*dist*", ".publish", "node_modules", "releases", ".tx", "css"],
"file_exclude_patterns": ["*.zip", "templates.js"] "file_exclude_patterns": ["*.zip", "templates.js"]
} }
] ]

Loading…
Cancel
Save