From b9af8fe0251aa458c2940c04c7d9c4b5477a9732 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 1 Aug 2014 00:03:51 +0100 Subject: [PATCH] Fixed scroll to found message --- app/js/controllers.js | 2 +- app/js/services.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index cc94cb80..84fb9d35 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -221,7 +221,7 @@ angular.module('myApp.controllers', []) $scope.$on('history_focus', function (e, peerData) { $modalStack.dismissAll(); if (peerData.peerString == $scope.curDialog.peer && peerData.messageID == $scope.curDialog.messageID) { - $scope.$broadcast('ui_history_focus'); + $scope.$broadcast(peerData.messageID ? 'ui_history_change_scroll' : 'ui_history_focus'); } else { $location.url('/im?p=' + peerData.peerString + (peerData.messageID ? '&m=' + peerData.messageID : '')); } diff --git a/app/js/services.js b/app/js/services.js index bdc63ea9..8fb7656b 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -1806,15 +1806,18 @@ angular.module('myApp.services', []) } function regroupWrappedHistory (history, limit) { + if (!history || !history.length) { + return; + } var start = 0, len = history.length, end = len, i, curDay, prevDay, curMessage, prevMessage; if (limit > 0) { - end = limit; + end = Math.min(limit, len); } else if (limit < 0) { - start = end + limit; + start = Math.max(0, end + limit); } for (i = start; i < end; i++) {