diff --git a/app/js/controllers.js b/app/js/controllers.js index e53b02df..19752a05 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -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']) } 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']) }, 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']) $scope.$broadcast('ui_message_send') fwdsSend() - resetDraft() + replyClear(true) } delete $scope.draftMessage.sticker } @@ -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']) if (forceDraft == $scope.curDialog.peer) { forceDraft = false - } else { - DraftsManager.changeDraft($scope.curDialog.peerID) } fwdsSend() diff --git a/app/js/directives_mobile.js b/app/js/directives_mobile.js index afbbc356..c612a84a 100644 --- a/app/js/directives_mobile.js +++ b/app/js/directives_mobile.js @@ -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) diff --git a/app/js/lib/ng_utils.js b/app/js/lib/ng_utils.js index 693ad90e..ef10984d 100644 --- a/app/js/lib/ng_utils.js +++ b/app/js/lib/ng_utils.js @@ -76,8 +76,10 @@ angular.module('izhukov.utils', []) return fileWriteData(fileWriter, fromFileEntry).then(function () { return fileWriter }, function (error) { + try { + fileWriter.truncate(0) + } catch (e) {} return $q.reject(error) - fileWriter.truncate(0) }) }) } diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 8b1f455d..8db25f9b 100644 --- a/app/js/messages_manager.js +++ b/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) }, function (error) { toggleError(true) @@ -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') }, 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') setZeroTimeout(message.send) + if (options.clearDraft) { + DraftsManager.clearDraft(peerID) + } + pendingByRandomID[randomIDS] = [peerID, messageID] } diff --git a/app/js/services.js b/app/js/services.js index 6564f965..62b90ff2 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -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']) getServerDraft: getServerDraft, saveDraft: saveDraft, changeDraft: changeDraft, + clearDraft: clearDraft, syncDraft: syncDraft } @@ -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']) } } + 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']) } 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}) }) }) }