Improved photo view for holes in history

This commit is contained in:
Igor Zhukov 2014-04-16 16:11:02 -04:00
parent 8684ea54fc
commit f119683cee
2 changed files with 63 additions and 2 deletions

View File

@ -684,10 +684,12 @@ angular.module('myApp.services', [])
var sendFilePromise = $q.when(); var sendFilePromise = $q.when();
var tempID = -1; var tempID = -1;
var dialogsIndex = SearchIndexManager.createIndex(), var dialogsIndex = SearchIndexManager.createIndex(),
cachedResults = {query: false}; cachedResults = {query: false};
var lastSearchFilter = {},
lastSearchResults = [];
NotificationsManager.start(); NotificationsManager.start();
function getDialogs (query, maxID, limit) { function getDialogs (query, maxID, limit) {
@ -888,7 +890,14 @@ angular.module('myApp.services', [])
} }
function getSearch (inputPeer, query, inputFilter, maxID, limit) { function getSearch (inputPeer, query, inputFilter, maxID, limit) {
var foundMsgs = []; var foundMsgs = [],
useSearchCache = !query,
sameSearchCache = useSearchCache && angular.equals(lastSearchFilter, inputFilter);
if (useSearchCache && !sameSearchCache) {
lastSearchFilter = inputFilter;
lastSearchResults = [];
}
if (!maxID && !query) { if (!maxID && !query) {
var peerID = AppPeersManager.getPeerID(inputPeer), var peerID = AppPeersManager.getPeerID(inputPeer),
@ -927,9 +936,27 @@ angular.module('myApp.services', [])
} }
} }
} }
// console.log(dT(), sameSearchCache, foundMsgs, lastSearchResults);
if (foundMsgs.length < neededLimit && lastSearchResults.length && sameSearchCache) {
var minID = foundMsgs.length ? foundMsgs[foundMsgs.length - 1] : 0xFFFFFFFF;
for (var i = 0; i < lastSearchResults.length; i++) {
if (lastSearchResults[i] < minID) {
foundMsgs.push(lastSearchResults[i]);
if (foundMsgs.length >= neededLimit) {
break;
}
}
}
}
// console.log(dT(), foundMsgs);
} }
if (foundMsgs.length || limit == 1000) { if (foundMsgs.length || limit == 1000) {
if (useSearchCache) {
lastSearchResults = listMergeSorted(lastSearchResults, foundMsgs);
}
return $q.when({ return $q.when({
count: null, count: null,
history: foundMsgs history: foundMsgs
@ -958,6 +985,10 @@ angular.module('myApp.services', [])
foundMsgs.push(message.id); foundMsgs.push(message.id);
}); });
if (useSearchCache) {
lastSearchResults = listMergeSorted(lastSearchResults, foundMsgs);
}
return { return {
count: foundCount, count: foundCount,
history: foundMsgs history: foundMsgs

View File

@ -77,3 +77,33 @@ function safeReplaceObject (wasObject, newObject) {
} }
} }
function listMergeSorted (list1, list2) {
list1 = list1 || [];
list2 = list2 || [];
var result = angular.copy(list1);
var minID = list1.length ? list1[list1.length - 1] : 0xFFFFFFFF;
for (var i = 0; i < list2.length; i++) {
if (list2[i] < minID) {
result.push(list2[i]);
}
}
return result;
}
function listUniqSorted (list) {
list = list || [];
var resultList = [],
prev = false;
for (var i = 0; i < list.length; i++) {
if (list[i] !== prev) {
resultList.push(list[i])
}
prev = list[i];
}
return resultList;
}