Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Improved drafts sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukov committed Jul 7, 2016
1 parent 37eaf46 commit 2a4c688
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/js/app.js
Expand Up @@ -42,7 +42,7 @@ angular.module('myApp', [
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('/im', {templateUrl: templateUrl('im'), controller: 'AppIMController', reloadOnSearch: false})
$routeProvider.otherwise({redirectTo: '/'})
Expand Down
28 changes: 20 additions & 8 deletions app/js/controllers.js
Expand Up @@ -2158,7 +2158,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$on('history_need_more', showMoreHistory)

$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)
}
if (!newVal) {
Expand Down Expand Up @@ -2217,6 +2221,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.toggleSlash = toggleSlash

$rootScope.$watch('idle.isIDLE', function (newVal) {
if ($rootScope.idle.initial) {
return
}
if (newVal && $scope.curDialog.peerID) {
DraftsManager.syncDraft($scope.curDialog.peerID)
}
Expand Down Expand Up @@ -2365,11 +2372,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}

function resetDraft (newPeer, prevPeer) {
if (prevPeer) {
var prevPeerID = AppPeersManager.getPeerID(prevPeer)
if (prevPeerID) {
var prevPeerID = prevPeer ? AppPeersManager.getPeerID(prevPeer) : 0
if (prevPeerID) {
$scope.$broadcast('ui_message_before_send')
$timeout(function () {
DraftsManager.syncDraft(prevPeerID)
}
resetDraft()
})
return
}

updateMentions()
Expand Down Expand Up @@ -2565,9 +2575,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return cancelEvent($event)
}

function onMessageChange (newVal) {
// console.log('ctrl text changed', newVal)
// console.trace('ctrl text changed', newVal)
function onMessageChange (newVal, prevVal, a) {
// console.log('ctrl text changed', newVal, prevVal);
if (newVal === '' && prevVal === '') {
return
}

if (newVal && newVal.length) {
if (!$scope.historyFilter.mediaType && !$scope.historyState.skipped) {
Expand Down
9 changes: 7 additions & 2 deletions app/js/lib/ng_utils.js
Expand Up @@ -1001,7 +1001,8 @@ angular.module('izhukov.utils', [])
})

.service('IdleManager', function ($rootScope, $window, $timeout) {
$rootScope.idle = {isIDLE: false}

$rootScope.idle = {isIDLE: false, initial: true}

var toPromise
var started = false
Expand Down Expand Up @@ -1031,7 +1032,7 @@ angular.module('izhukov.utils', [])
$($window).on(visibilityChange + ' blur focus keydown mousedown touchstart', onEvent)

setTimeout(function () {
onEvent({type: 'blur'})
onEvent({type: 'blur', fake_initial: true})
}, 0)
}
}
Expand Down Expand Up @@ -1066,6 +1067,10 @@ angular.module('izhukov.utils', [])
}, 10)
}

if (e && !e.fake_initial) {
delete $rootScope.idle.initial;
}

if ($rootScope.idle.isIDLE == isIDLE) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion webogram.sublime-project
Expand Up @@ -4,7 +4,7 @@
{
"follow_symlinks": true,
"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"]
}
]
Expand Down

0 comments on commit 2a4c688

Please sign in to comment.