Browse Source

Fixed pinned messages bugs

master
Igor Zhukov 7 years ago
parent
commit
550f8ae781
  1. 25
      app/js/controllers.js
  2. 26
      app/js/messages_manager.js
  3. 6
      app/js/services.js

25
app/js/controllers.js

@ -790,15 +790,20 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -790,15 +790,20 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
$scope.$on('dialog_top', function (e, dialog) {
var curDialog, i
for (i = 0; i < $scope.dialogs.length; i++) {
var curDialog, i, wrappedDialog
var len = $scope.dialogs.length
for (i = 0; i < len; i++) {
curDialog = $scope.dialogs[i]
if (curDialog.peerID == dialog.peerID) {
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog)
wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog)
$scope.dialogs.splice(i, 1, wrappedDialog)
break
}
}
sortDialogs()
if (wrappedDialog == $scope.dialogs[len - 1]) {
$scope.dialogs.splice(len - 1, 1)
}
})
$scope.$on('dialog_flush', function (e, update) {
var curDialog, i
@ -989,8 +994,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -989,8 +994,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (dialogsResult.dialogs.length) {
angular.forEach(dialogsResult.dialogs, function (dialog) {
if ($scope.canSend &&
AppPeersManager.isChannel(dialog.peerID) &&
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
AppPeersManager.isChannel(dialog.peerID) &&
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
return
}
var wrapDialog = searchMessages ? undefined : dialog
@ -1056,8 +1061,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1056,8 +1061,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
angular.forEach(dialogsResult.dialogs, function (dialog) {
if ($scope.canSend &&
AppPeersManager.isChannel(dialog.peerID) &&
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
AppPeersManager.isChannel(dialog.peerID) &&
!AppChatsManager.hasRights(-dialog.peerID, 'send')) {
return
}
var wrapDialog = searchMessages ? undefined : dialog
@ -1066,7 +1071,11 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -1066,7 +1071,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (searchMessages) {
wrappedDialog.unreadCount = -1
} else {
peersInDialogs[dialog.peerID] = true
if (peersInDialogs[dialog.peerID]) {
return
} else {
peersInDialogs[dialog.peerID] = true
}
}
if (searchMessages &&

26
app/js/messages_manager.js

@ -219,11 +219,14 @@ angular.module('myApp.services') @@ -219,11 +219,14 @@ angular.module('myApp.services')
var offsetID = 0
var offsetPeerID = 0
var offsetIndex = 0
var flags = 0
if (dialogsOffsetDate) {
offsetDate = dialogsOffsetDate + ServerTimeManager.serverTimeOffset
offsetIndex = dialogsOffsetDate * 0x10000
flags |= 1
}
return MtpApiManager.invokeApi('messages.getDialogs', {
flags: flags,
offset_date: offsetDate,
offset_id: AppMessagesIDsManager.getMessageLocalID(offsetID),
offset_peer: AppPeersManager.getInputPeerByID(offsetPeerID),
@ -284,15 +287,22 @@ angular.module('myApp.services') @@ -284,15 +287,22 @@ angular.module('myApp.services')
}
function pushDialogToStorage (dialog, offsetDate) {
if (offsetDate && (!dialogsOffsetDate || offsetDate < dialogsOffsetDate)) {
dialogsOffsetDate = offsetDate
}
var dialogs = dialogsStorage.dialogs
var pos = getDialogByPeerID(dialog.peerID)[1]
if (pos !== undefined) {
dialogs.splice(pos, 1)
}
if (offsetDate &&
!dialog.pFlags.pinned &&
(!dialogsOffsetDate || offsetDate < dialogsOffsetDate)) {
if (pos !== undefined) {
// So the dialog jumped to the last position
return false
}
dialogsOffsetDate = offsetDate
}
var index = dialog.index
var i
var len = dialogs.length
@ -301,7 +311,8 @@ angular.module('myApp.services') @@ -301,7 +311,8 @@ angular.module('myApp.services')
}
else if (index >= dialogs[0].index) {
dialogs.unshift(dialog)
}else {
}
else {
for (i = 0; i < len; i++) {
if (index > dialogs[i].index) {
dialogs.splice(i, 0, dialog)
@ -3462,17 +3473,18 @@ angular.module('myApp.services') @@ -3462,17 +3473,18 @@ angular.module('myApp.services')
var updatedDialogs = {}
var hasUpdated = false
angular.forEach(dialogsResult.dialogs, function (dialog) {
var peerID = AppPeersManager.getPeerID(dialog.peer)
if (dialog.top_message) {
var wasBefore = getDialogByPeerID(dialog.peerID).length > 0
var wasBefore = getDialogByPeerID(peerID).length > 0
saveConversation(dialog)
if (wasBefore) {
clearDialogCache(dialog.top_message)
$rootScope.$broadcast('dialog_top', dialog)
} else {
updatedDialogs[dialog.peerID] = dialog
updatedDialogs[peerID] = dialog
hasUpdated = true
}
} else {
var peerID = AppPeersManager.getPeerID(dialog.peer)
var foundDialog = getDialogByPeerID(peerID)
if (foundDialog.length) {
dialogsStorage.dialogs.splice(foundDialog[1], 1)

6
app/js/services.js

@ -3381,9 +3381,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -3381,9 +3381,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}
if (update._ == 'updateNewMessage' ||
update._ == 'updateEditMessage' ||
update._ == 'updateNewChannelMessage' ||
update._ == 'updateEditChannelMessage') {
update._ == 'updateEditMessage' ||
update._ == 'updateNewChannelMessage' ||
update._ == 'updateEditChannelMessage') {
var message = update.message
var toPeerID = AppPeersManager.getPeerID(message.to_id)
var fwdHeader = message.fwd_from || {}

Loading…
Cancel
Save