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

16
app/js/lib/ng_utils.js

@ -1005,6 +1005,7 @@ angular.module('izhukov.utils', [])
$rootScope.idle = {isIDLE: false, initial: true} $rootScope.idle = {isIDLE: false, initial: true}
var toPromise var toPromise
var debouncePromise
var started = false var started = false
var hidden = 'hidden' var hidden = 'hidden'
@ -1067,22 +1068,25 @@ angular.module('izhukov.utils', [])
}, 10) }, 10)
} }
var debounceTimeout = $rootScope.idle.initial ? 0 : 1000;
if (e && !e.fake_initial) { if (e && !e.fake_initial) {
delete $rootScope.idle.initial; delete $rootScope.idle.initial;
} }
$timeout.cancel(debouncePromise)
if ($rootScope.idle.isIDLE == isIDLE) { if ($rootScope.idle.isIDLE == isIDLE) {
return return
} }
// console.log('IDLE changed', isIDLE) debouncePromise = $timeout(function () {
$rootScope.$apply(function () { // console.log(dT(), 'IDLE changed', isIDLE)
$rootScope.idle.isIDLE = 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'])
return return
} }
var peerID = AppPeersManager.getPeerID(update.peer) var peerID = AppPeersManager.getPeerID(update.peer)
saveDraft(peerID, update.draft, true) saveDraft(peerID, update.draft, {notify: true})
}) })
return { return {
@ -4526,18 +4526,18 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return false return false
} }
function saveDraft (peerID, apiDraft, notify) { function saveDraft (peerID, apiDraft, options) {
if (notify) { options = options || {}
console.warn(dT(), 'save draft', peerID, apiDraft, notify)
}
var draft = processApiDraft(apiDraft) var draft = processApiDraft(apiDraft)
cachedServerDrafts[peerID] = draft cachedServerDrafts[peerID] = draft
if (notify) { if (options.notify) {
console.warn(dT(), 'save draft', peerID, apiDraft, options)
changeDraft(peerID, draft) changeDraft(peerID, draft)
$rootScope.$broadcast('draft_updated', { $rootScope.$broadcast('draft_updated', {
peerID: peerID, peerID: peerID,
draft: draft draft: draft,
local: options.sync
}) })
} }
@ -4659,7 +4659,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
MtpApiManager.invokeApi('messages.saveDraft', params).then(function () { MtpApiManager.invokeApi('messages.saveDraft', params).then(function () {
draftObj.date = tsNow(true) + ServerTimeManager.serverTimeOffset draftObj.date = tsNow(true) + ServerTimeManager.serverTimeOffset
saveDraft(peerID, draftObj, true) saveDraft(peerID, draftObj, {notify: true, sync: true})
}) })
}) })
} }

Loading…
Cancel
Save