Browse Source

Fixed draft bugs

Closes #1231
Closes #1240
Closes #1200
master
Igor Zhukov 8 years ago
parent
commit
2d202443e1
  1. 21
      app/js/controllers.js
  2. 12
      app/js/directives_mobile.js
  3. 4
      app/js/lib/ng_utils.js
  4. 27
      app/js/messages_manager.js
  5. 23
      app/js/services.js

21
app/js/controllers.js

@ -2258,14 +2258,14 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2258,14 +2258,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
do {
AppMessagesManager.sendText($scope.curDialog.peerID, text.substr(0, 4096), options)
text = text.substr(4096)
options = angular.copy(options)
delete options.clearDraft
} while (text.length)
}
fwdsSend()
if (forceDraft == $scope.curDialog.peer) {
forceDraft = false
} else {
DraftsManager.changeDraft($scope.curDialog.peerID)
}
resetDraft()
@ -2430,7 +2430,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2430,7 +2430,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
function applyDraftAttachment (e, attachment) {
console.log('apply draft attach', attachment)
console.log(dT(), 'apply draft attach', attachment)
if (!attachment || !attachment._) {
return
}
@ -2452,6 +2452,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2452,6 +2452,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}, 1000)
}
else if (attachment._ == 'fwd_messages') {
forceDraft = $scope.curDialog.peer
$timeout(function () {
$scope.draftMessage.fwdMessages = attachment.id
$scope.$broadcast('ui_peer_reply')
@ -2726,7 +2727,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2726,7 +2727,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$broadcast('ui_message_send')
fwdsSend()
resetDraft()
replyClear(true)
}
delete $scope.draftMessage.sticker
}
@ -2735,7 +2736,15 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2735,7 +2736,15 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (!command) {
return
}
AppMessagesManager.sendText($scope.curDialog.peerID, command)
AppMessagesManager.sendText($scope.curDialog.peerID, command, {
clearDraft: true
})
if (forceDraft == $scope.curDialog.peer) {
forceDraft = false
}
fwdsSend()
resetDraft()
delete $scope.draftMessage.sticker
delete $scope.draftMessage.text
@ -2764,8 +2773,6 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -2764,8 +2773,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (forceDraft == $scope.curDialog.peer) {
forceDraft = false
} else {
DraftsManager.changeDraft($scope.curDialog.peerID)
}
fwdsSend()

12
app/js/directives_mobile.js

@ -321,17 +321,7 @@ angular.module('myApp.directives') @@ -321,17 +321,7 @@ angular.module('myApp.directives')
}
}
function updateBottomizer () {
return
$(historyMessagesEl).css({marginTop: 0})
var marginTop = scrollableWrap.offsetHeight
- historyMessagesEl.offsetHeight
- 20
if (historyMessagesEl.offsetHeight > 0 && marginTop > 0) {
$(historyMessagesEl).css({marginTop: marginTop})
}
}
function updateBottomizer () {}
$($window).on('resize', updateSizes)

4
app/js/lib/ng_utils.js

@ -76,8 +76,10 @@ angular.module('izhukov.utils', []) @@ -76,8 +76,10 @@ angular.module('izhukov.utils', [])
return fileWriteData(fileWriter, fromFileEntry).then(function () {
return fileWriter
}, function (error) {
return $q.reject(error)
try {
fileWriter.truncate(0)
} catch (e) {}
return $q.reject(error)
})
})
}

27
app/js/messages_manager.js

@ -1429,6 +1429,13 @@ angular.module('myApp.services') @@ -1429,6 +1429,13 @@ angular.module('myApp.services')
}]
}
}
else if (updates.updates) {
angular.forEach(updates.updates, function (update) {
if (update._ == 'updateDraftMessage') {
update.local = true
}
})
}
ApiUpdatesManager.processUpdateMessage(updates)
}, function (error) {
toggleError(true)
@ -1450,14 +1457,9 @@ angular.module('myApp.services') @@ -1450,14 +1457,9 @@ angular.module('myApp.services')
// message.send()
// }, 5000)
ApiUpdatesManager.processUpdateMessage({
_: 'updateShort',
update: {
_: 'updateDraftMessage',
peer: AppPeersManager.getOutputPeer(peerID),
draft: {_: 'draftMessageEmpty'}
if (options.clearDraft) {
DraftsManager.clearDraft(peerID)
}
})
pendingByRandomID[randomIDS] = [peerID, messageID]
}
@ -1817,6 +1819,13 @@ angular.module('myApp.services') @@ -1817,6 +1819,13 @@ angular.module('myApp.services')
}, sentRequestOptions)
}
apiPromise.then(function (updates) {
if (updates.updates) {
angular.forEach(updates.updates, function (update) {
if (update._ == 'updateDraftMessage') {
update.local = true
}
})
}
ApiUpdatesManager.processUpdateMessage(updates)
}, function (error) {
toggleError(true)
@ -1834,6 +1843,10 @@ angular.module('myApp.services') @@ -1834,6 +1843,10 @@ angular.module('myApp.services')
setZeroTimeout(message.send)
if (options.clearDraft) {
DraftsManager.clearDraft(peerID)
}
pendingByRandomID[randomIDS] = [peerID, messageID]
}

23
app/js/services.js

@ -4643,7 +4643,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4643,7 +4643,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return
}
var peerID = AppPeersManager.getPeerID(update.peer)
saveDraft(peerID, update.draft, {notify: true})
saveDraft(peerID, update.draft, {notify: true, local: update.local})
})
return {
@ -4651,6 +4651,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4651,6 +4651,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
getServerDraft: getServerDraft,
saveDraft: saveDraft,
changeDraft: changeDraft,
clearDraft: clearDraft,
syncDraft: syncDraft
}
@ -4700,7 +4701,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4700,7 +4701,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
$rootScope.$broadcast('draft_updated', {
peerID: peerID,
draft: draft,
local: options.sync
local: options.local
})
}
@ -4733,6 +4734,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4733,6 +4734,22 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
}
function clearDraft (peerID, alsoSync) {
changeDraft(peerID)
ApiUpdatesManager.processUpdateMessage({
_: 'updateShort',
update: {
_: 'updateDraftMessage',
peer: AppPeersManager.getOutputPeer(peerID),
draft: {_: 'draftMessageEmpty'},
local: true
}
})
if (alsoSync) {
syncDraft(peerID)
}
}
function draftsAreEqual (draft1, draft2) {
var isEmpty1 = isEmptyDraft(draft1)
var isEmpty2 = isEmptyDraft(draft2)
@ -4822,7 +4839,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -4822,7 +4839,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, {notify: true, sync: true})
saveDraft(peerID, draftObj, {notify: true, local: true})
})
})
}

Loading…
Cancel
Save