Browse Source

Fixed conversation position after draft clear

master
Igor Zhukov 8 years ago
parent
commit
439ee9ecad
  1. 15
      app/js/controllers.js
  2. 21
      app/js/messages_manager.js

15
app/js/controllers.js

@ -736,9 +736,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
) )
}) })
$scope.dialogs.sort(function (d1, d2) { sortDialogs()
return d2.index - d1.index
})
if (newPeer) { if (newPeer) {
delete $scope.isEmpty.dialogs 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) { $scope.$on('dialog_top', function (e, dialog) {
var curDialog, i var curDialog, i
for (i = 0; i < $scope.dialogs.length; i++) { for (i = 0; i < $scope.dialogs.length; i++) {
@ -791,10 +795,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (draftUpdate.index) { if (draftUpdate.index) {
curDialog.index = draftUpdate.index curDialog.index = draftUpdate.index
} }
if (i > 0 && draftUpdate.draft) { sortDialogs();
$scope.dialogs.splice(i, 1)
$scope.dialogs.unshift(curDialog)
}
break break
} }
} }

21
app/js/messages_manager.js

@ -3219,15 +3219,26 @@ angular.module('myApp.services')
var dialog = getDialogByPeerID(peerID)[0] var dialog = getDialogByPeerID(peerID)[0]
if (dialog) { if (dialog) {
var newIndex var topDate
if (dialog && draft && draft.date) { if (draft && draft.date) {
newIndex = dialog.index = generateDialogIndex(draft.date) topDate = draft.date
pushDialogToStorage(dialog) } 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', { $rootScope.$broadcast('dialog_draft', {
peerID: peerID, peerID: peerID,
draft: draft, draft: draft,
index: dialog && dialog.index index: dialog.index
}) })
} }
}) })

Loading…
Cancel
Save