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

12
app/js/directives_mobile.js

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

4
app/js/lib/ng_utils.js

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

29
app/js/messages_manager.js

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

23
app/js/services.js

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

Loading…
Cancel
Save