From 0e531b27a961a904a10f19ca99e2cac72345aa98 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 7 Oct 2016 20:35:38 +0300 Subject: [PATCH] Fixed drafts position in conversations --- app/js/controllers.js | 5 ++++- app/js/messages_manager.js | 25 +++++++------------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 19752a05..29f4838c 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -782,12 +782,15 @@ angular.module('myApp.controllers', ['myApp.i18n']) deleteDialog(dialog.peerID) }) - $scope.$on('draft_updated', function (e, draftUpdate) { + $scope.$on('dialog_draft', function (e, draftUpdate) { var curDialog, i for (i = 0; i < $scope.dialogs.length; i++) { curDialog = $scope.dialogs[i] if (curDialog.peerID == draftUpdate.peerID) { curDialog.draft = draftUpdate.draft + if (draftUpdate.index) { + curDialog.index = draftUpdate.index + } if (i > 0 && draftUpdate.draft) { $scope.dialogs.splice(i, 1) $scope.dialogs.unshift(curDialog) diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 8db25f9b..232a37ab 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -3156,23 +3156,6 @@ angular.module('myApp.services') }) } break - - case 'updateDraftMessage': - var peerID = AppPeersManager.getPeerID(update.peer) - var draft = DraftsManager.saveDraft(peerID, update.draft) - - var dialog = getDialogByPeerID(peerID)[0] - if (dialog) { - if (dialog && draft && draft.date) { - dialog.index = generateDialogIndex(draft.date) - pushDialogToStorage(dialog) - } - $rootScope.$broadcast('dialog_draft', { - peerID: peerID, - draft: draft - }) - } - break } }) @@ -3236,10 +3219,16 @@ angular.module('myApp.services') var dialog = getDialogByPeerID(peerID)[0] if (dialog) { + var newIndex if (dialog && draft && draft.date) { - dialog.index = generateDialogIndex(draft.date) + newIndex = dialog.index = generateDialogIndex(draft.date) pushDialogToStorage(dialog) } + $rootScope.$broadcast('dialog_draft', { + peerID: peerID, + draft: draft, + index: dialog && dialog.index + }) } })