diff --git a/app/js/controllers.js b/app/js/controllers.js index 29f4838c..27897dee 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -736,9 +736,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) ) }) - $scope.dialogs.sort(function (d1, d2) { - return d2.index - d1.index - }) + sortDialogs() if (newPeer) { delete $scope.isEmpty.dialogs @@ -757,6 +755,12 @@ angular.module('myApp.controllers', ['myApp.i18n']) } } + function sortDialogs() { + $scope.dialogs.sort(function (d1, d2) { + return d2.index - d1.index + }) + } + $scope.$on('dialog_top', function (e, dialog) { var curDialog, i for (i = 0; i < $scope.dialogs.length; i++) { @@ -791,10 +795,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) if (draftUpdate.index) { curDialog.index = draftUpdate.index } - if (i > 0 && draftUpdate.draft) { - $scope.dialogs.splice(i, 1) - $scope.dialogs.unshift(curDialog) - } + sortDialogs(); break } } diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 232a37ab..9fe7c2b8 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -3219,15 +3219,26 @@ angular.module('myApp.services') var dialog = getDialogByPeerID(peerID)[0] if (dialog) { - var newIndex - if (dialog && draft && draft.date) { - newIndex = dialog.index = generateDialogIndex(draft.date) - pushDialogToStorage(dialog) + var topDate + if (draft && draft.date) { + topDate = draft.date + } else { + var channelID = AppPeersManager.isChannel(peerID) ? -peerID : 0 + var topDate = getMessage(dialog.top_message).date + if (channelID) { + var channel = AppChatsManager.getChat(channelID) + if (!topDate || channel.date && channel.date > topDate) { + topDate = channel.date + } + } } + dialog.index = generateDialogIndex(topDate) + pushDialogToStorage(dialog) + $rootScope.$broadcast('dialog_draft', { peerID: peerID, draft: draft, - index: dialog && dialog.index + index: dialog.index }) } })