Browse Source

Improved drafts handling

Fixed bug with isIdle in Fx
master
Igor Zhukov 9 years ago
parent
commit
25681537c7
  1. 10
      app/js/controllers.js
  2. 16
      app/js/lib/ng_utils.js
  3. 16
      app/js/services.js

10
app/js/controllers.js

@ -2225,12 +2225,16 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2225,12 +2225,16 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return
}
if (newVal && $scope.curDialog.peerID) {
DraftsManager.syncDraft($scope.curDialog.peerID)
$scope.$broadcast('ui_message_before_send')
$timeout(function () {
DraftsManager.syncDraft($scope.curDialog.peerID)
})
}
})
$scope.$on('draft_updated', function (e, draftUpdate) {
if (draftUpdate.peerID == $scope.curDialog.peerID) {
if (draftUpdate.peerID == $scope.curDialog.peerID &&
!draftUpdate.local) {
getDraft()
}
})
@ -2373,7 +2377,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2373,7 +2377,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
function resetDraft (newPeer, prevPeer) {
var prevPeerID = prevPeer ? AppPeersManager.getPeerID(prevPeer) : 0
if (prevPeerID) {
if (newPeer != prevPeer && prevPeerID) {
$scope.$broadcast('ui_message_before_send')
$timeout(function () {
DraftsManager.syncDraft(prevPeerID)

16
app/js/lib/ng_utils.js

@ -1005,6 +1005,7 @@ angular.module('izhukov.utils', []) @@ -1005,6 +1005,7 @@ angular.module('izhukov.utils', [])
$rootScope.idle = {isIDLE: false, initial: true}
var toPromise
var debouncePromise
var started = false
var hidden = 'hidden'
@ -1067,22 +1068,25 @@ angular.module('izhukov.utils', []) @@ -1067,22 +1068,25 @@ angular.module('izhukov.utils', [])
}, 10)
}
var debounceTimeout = $rootScope.idle.initial ? 0 : 1000;
if (e && !e.fake_initial) {
delete $rootScope.idle.initial;
}
$timeout.cancel(debouncePromise)
if ($rootScope.idle.isIDLE == isIDLE) {
return
}
// console.log('IDLE changed', isIDLE)
$rootScope.$apply(function () {
debouncePromise = $timeout(function () {
// console.log(dT(), 'IDLE changed', isIDLE)
$rootScope.idle.isIDLE = isIDLE
})
if (isIDLE && e.type == 'timeout') {
$($window).on('mousemove', onEvent)
}
}, debounceTimeout)
if (isIDLE && e.type == 'timeout') {
$($window).on('mousemove', onEvent)
}
}
})

16
app/js/services.js

@ -4480,7 +4480,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4480,7 +4480,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return
}
var peerID = AppPeersManager.getPeerID(update.peer)
saveDraft(peerID, update.draft, true)
saveDraft(peerID, update.draft, {notify: true})
})
return {
@ -4526,18 +4526,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4526,18 +4526,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return false
}
function saveDraft (peerID, apiDraft, notify) {
if (notify) {
console.warn(dT(), 'save draft', peerID, apiDraft, notify)
}
function saveDraft (peerID, apiDraft, options) {
options = options || {}
var draft = processApiDraft(apiDraft)
cachedServerDrafts[peerID] = draft
if (notify) {
if (options.notify) {
console.warn(dT(), 'save draft', peerID, apiDraft, options)
changeDraft(peerID, draft)
$rootScope.$broadcast('draft_updated', {
peerID: peerID,
draft: draft
draft: draft,
local: options.sync
})
}
@ -4659,7 +4659,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4659,7 +4659,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
MtpApiManager.invokeApi('messages.saveDraft', params).then(function () {
draftObj.date = tsNow(true) + ServerTimeManager.serverTimeOffset
saveDraft(peerID, draftObj, true)
saveDraft(peerID, draftObj, {notify: true, sync: true})
})
})
}

Loading…
Cancel
Save