Browse Source

Fixed search messages bugs

Fixed unread count in search - Closes #455
master
Igor Zhukov 10 years ago
parent
commit
441e7ef1cd
  1. 58
      app/js/controllers.js
  2. 41
      app/js/directives.js
  3. 13
      app/js/services.js

58
app/js/controllers.js

@ -566,7 +566,7 @@ angular.module('myApp.controllers', [])
if (searchMessages) { if (searchMessages) {
searchTimeoutPromise = force ? $q.when() : $timeout(angular.noop, 500); searchTimeoutPromise = force ? $q.when() : $timeout(angular.noop, 500);
promise = searchTimeoutPromise.then(function () { promise = searchTimeoutPromise.then(function () {
return AppMessagesManager.getSearch({_: 'inputPeerEmpty'}, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID) return AppMessagesManager.getSearch({_: 'inputPeerEmpty'}, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID);
}); });
} else { } else {
promise = AppMessagesManager.getDialogs($scope.search.query, maxID); promise = AppMessagesManager.getDialogs($scope.search.query, maxID);
@ -585,7 +585,7 @@ angular.module('myApp.controllers', [])
dialogs.push({ dialogs.push({
peerID: peerID, peerID: peerID,
top_message: messageID, top_message: messageID,
unread_count: 0 unread_count: -1
}); });
}); });
@ -644,7 +644,8 @@ angular.module('myApp.controllers', [])
angular.forEach(dialogsResult.dialogs, function (dialog) { angular.forEach(dialogsResult.dialogs, function (dialog) {
peersInDialogs[dialog.peerID] = true; peersInDialogs[dialog.peerID] = true;
$scope.dialogs.push(AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count)); var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count);
$scope.dialogs.push(wrappedDialog);
}); });
delete $scope.isEmpty.dialogs; delete $scope.isEmpty.dialogs;
} }
@ -764,7 +765,11 @@ angular.module('myApp.controllers', [])
}, },
jump = 0, jump = 0,
moreJump = 0, moreJump = 0,
lessJump = 0; moreActive = false,
morePending = false,
lessJump = 0,
lessActive = false,
lessPending = false;
function applyDialogSelect (newDialog, oldDialog) { function applyDialogSelect (newDialog, oldDialog) {
var newPeer = newDialog.peer || $scope.curDialog.peer || ''; var newPeer = newDialog.peer || $scope.curDialog.peer || '';
@ -867,10 +872,12 @@ angular.module('myApp.controllers', [])
found = false, found = false,
history = historiesQueueFind(); history = historiesQueueFind();
for (i = 0; i < history.messages.length; i++) { if (history) {
if ($scope.curDialog.messageID == history.messages[i].id) { for (i = 0; i < history.messages.length; i++) {
found = true; if ($scope.curDialog.messageID == history.messages[i].id) {
break; found = true;
break;
}
} }
} }
@ -887,12 +894,19 @@ angular.module('myApp.controllers', [])
if (!hasLess) { if (!hasLess) {
return; return;
} }
if (moreActive) {
lessPending = true;
return;
}
lessPending = false;
lessActive = true;
var curJump = jump, var curJump = jump,
curLessJump = ++lessJump, curLessJump = ++lessJump,
limit = 0, limit = 0,
backLimit = 20; backLimit = 20;
AppMessagesManager.getHistory($scope.curDialog.inputPeer, minID, limit, backLimit).then(function (historyResult) { AppMessagesManager.getHistory($scope.curDialog.inputPeer, minID, limit, backLimit).then(function (historyResult) {
lessActive = false;
if (curJump != jump || curLessJump != lessJump) return; if (curJump != jump || curLessJump != lessJump) return;
var i, id; var i, id;
@ -916,6 +930,10 @@ angular.module('myApp.controllers', [])
minID = 0; minID = 0;
} }
$scope.skippedHistory = hasLess = minID > 0; $scope.skippedHistory = hasLess = minID > 0;
if (morePending) {
showMoreHistory();
}
}); });
} }
@ -923,6 +941,12 @@ angular.module('myApp.controllers', [])
if (!hasMore) { if (!hasMore) {
return; return;
} }
if (lessActive) {
morePending = true;
return;
}
morePending = false;
moreActive = true;
var curJump = jump, var curJump = jump,
curMoreJump = moreJump, curMoreJump = moreJump,
@ -933,6 +957,7 @@ angular.module('myApp.controllers', [])
: AppMessagesManager.getHistory($scope.curDialog.inputPeer, maxID, limit); : AppMessagesManager.getHistory($scope.curDialog.inputPeer, maxID, limit);
getMessagesPromise.then(function (historyResult) { getMessagesPromise.then(function (historyResult) {
moreActive = false;
if (curJump != jump || curMoreJump != moreJump) return; if (curJump != jump || curMoreJump != moreJump) return;
angular.forEach(historyResult.history, function (id) { angular.forEach(historyResult.history, function (id) {
@ -950,6 +975,10 @@ angular.module('myApp.controllers', [])
} }
$scope.$broadcast('ui_history_prepend'); $scope.$broadcast('ui_history_prepend');
} }
if (lessPending) {
showLessHistory();
}
}); });
}; };
@ -967,8 +996,8 @@ angular.module('myApp.controllers', [])
if ($scope.curDialog.messageID) { if ($scope.curDialog.messageID) {
maxID = parseInt($scope.curDialog.messageID); maxID = parseInt($scope.curDialog.messageID);
limit = 5; limit = 10;
backLimit = 5; backLimit = 10;
} }
else if (forceRecent) { else if (forceRecent) {
limit = 10; limit = 10;
@ -977,6 +1006,11 @@ angular.module('myApp.controllers', [])
limit = 20; limit = 20;
} }
moreActive = false;
morePending = false;
lessActive = false;
lessPending = false;
var curJump = ++jump, var curJump = ++jump,
inputMediaFilter = $scope.historyFilter.mediaType && {_: inputMediaFilters[$scope.historyFilter.mediaType]}, inputMediaFilter = $scope.historyFilter.mediaType && {_: inputMediaFilters[$scope.historyFilter.mediaType]},
getMessagesPromise = inputMediaFilter getMessagesPromise = inputMediaFilter
@ -1024,7 +1058,9 @@ angular.module('myApp.controllers', [])
delete $scope.historyUnreadAfter; delete $scope.historyUnreadAfter;
$scope.$broadcast('messages_unread_after'); $scope.$broadcast('messages_unread_after');
} }
$scope.$broadcast('messages_focus', $scope.curDialog.messageID || 0); onContentLoaded(function () {
$scope.$broadcast('messages_focus', $scope.curDialog.messageID || 0);
})
$scope.$broadcast('ui_history_change'); $scope.$broadcast('ui_history_change');
AppMessagesManager.readHistory($scope.curDialog.inputPeer); AppMessagesManager.readHistory($scope.curDialog.inputPeer);

41
app/js/directives.js

@ -629,10 +629,15 @@ angular.module('myApp.directives', ['myApp.filters'])
function changeScroll () { function changeScroll () {
var unreadSplit, focusMessage; var unreadSplit, focusMessage;
// console.log('change scroll'); // console.trace('change scroll');
if (focusMessage = $('.im_message_focus:visible', scrollableWrap)[0]) { if (focusMessage = $('.im_message_focus:visible', scrollableWrap)[0]) {
// console.log('change scroll focus', focusMessage.offsetTop); var ch = scrollableWrap.clientHeight,
scrollableWrap.scrollTop = Math.max(0, focusMessage.offsetTop - Math.floor(scrollableWrap.clientHeight / 2) + 26); st = scrollableWrap.scrollTop,
ot = focusMessage.offsetTop,
h = focusMessage.clientHeight;
if (!st || st + ch < ot || st > ot + h) {
scrollableWrap.scrollTop = Math.max(0, ot - Math.floor(ch / 2) + 26);
}
atBottom = false; atBottom = false;
} else if (unreadSplit = $('.im_message_unread_split:visible', scrollableWrap)[0]) { } else if (unreadSplit = $('.im_message_unread_split:visible', scrollableWrap)[0]) {
// console.log('change scroll unread', unreadSplit.offsetTop); // console.log('change scroll unread', unreadSplit.offsetTop);
@ -646,6 +651,7 @@ angular.module('myApp.directives', ['myApp.filters'])
updateScroller(); updateScroller();
$timeout(function () { $timeout(function () {
$(scrollableWrap).trigger('scroll'); $(scrollableWrap).trigger('scroll');
scrollTopInitial = scrollableWrap.scrollTop;
}); });
}; };
@ -689,7 +695,11 @@ angular.module('myApp.directives', ['myApp.filters'])
var upd = function () { var upd = function () {
$(scrollableWrap).removeClass('im_history_to_bottom'); $(scrollableWrap).removeClass('im_history_to_bottom');
$(scrollable).css({bottom: '', marginLeft: ''}); $(scrollable).css({bottom: '', marginLeft: ''});
scrollableWrap.scrollTop = st + scrollableWrap.scrollHeight - sh; if (scrollTopInitial >= 0) {
changeScroll();
} else {
scrollableWrap.scrollTop = st + scrollableWrap.scrollHeight - sh;
}
updateBottomizer(); updateBottomizer();
moreNotified = false; moreNotified = false;
@ -714,6 +724,10 @@ angular.module('myApp.directives', ['myApp.filters'])
updateBottomizer(); updateBottomizer();
lessNotified = false; lessNotified = false;
if (scrollTopInitial >= 0) {
changeScroll();
}
$timeout(function () { $timeout(function () {
if (scrollableWrap.scrollHeight != sh) { if (scrollableWrap.scrollHeight != sh) {
$(scrollableWrap).trigger('scroll'); $(scrollableWrap).trigger('scroll');
@ -751,23 +765,28 @@ angular.module('myApp.directives', ['myApp.filters'])
// updateSizes(); // updateSizes();
}); });
var atBottom = true; var atBottom = true,
scrollTopInitial = -1;
$(scrollableWrap).on('scroll', function (e) { $(scrollableWrap).on('scroll', function (e) {
if (!element.is(':visible') || if (!element.is(':visible') ||
$(scrollableWrap).hasClass('im_history_to_bottom') || $(scrollableWrap).hasClass('im_history_to_bottom') ||
curAnimation) { curAnimation) {
return; return;
} }
atBottom = scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight; var st = scrollableWrap.scrollTop;
atBottom = st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight;
if (!moreNotified && scrollableWrap.scrollTop <= 300) { if (scrollTopInitial >= 0 && scrollTopInitial != st) {
moreNotified = true; scrollTopInitial = -1;
$scope.$emit('history_need_more');
} }
else if (!lessNotified && scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
if (!lessNotified && st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) {
lessNotified = true; lessNotified = true;
$scope.$emit('history_need_less'); $scope.$emit('history_need_less');
} }
else if (!moreNotified && st <= 300) {
moreNotified = true;
$scope.$emit('history_need_more');
}
}); });
function updateSizes (heightOnly) { function updateSizes (heightOnly) {

13
app/js/services.js

@ -760,6 +760,8 @@ angular.module('myApp.services', [])
} }
}); });
var dateOrTimeFilter = $filter('dateOrTime');
midnightOffseted.setHours(0); midnightOffseted.setHours(0);
midnightOffseted.setMinutes(0); midnightOffseted.setMinutes(0);
midnightOffseted.setSeconds(0); midnightOffseted.setSeconds(0);
@ -1744,7 +1746,9 @@ angular.module('myApp.services', [])
} }
function wrapForDialog (msgID, unreadCount) { function wrapForDialog (msgID, unreadCount) {
if (messagesForDialogs[msgID] !== undefined) { var useCache = unreadCount != -1;
if (useCache && messagesForDialogs[msgID] !== undefined) {
return messagesForDialogs[msgID]; return messagesForDialogs[msgID];
} }
@ -1773,10 +1777,13 @@ angular.module('myApp.services', [])
message.richMessage = RichTextProcessor.wrapRichText(message.message.substr(0, 64), {noLinks: true, noLinebreaks: true}); message.richMessage = RichTextProcessor.wrapRichText(message.message.substr(0, 64), {noLinks: true, noLinebreaks: true});
} }
message.dateText = $filter('dateOrTime')(message.date); message.dateText = dateOrTimeFilter(message.date);
if (useCache) {
messagesForDialogs[msgID] = message;
}
return messagesForDialogs[msgID] = message; return message;
} }
function wrapForHistory (msgID) { function wrapForHistory (msgID) {

Loading…
Cancel
Save