Browse Source

Fixed search with filter from cache

master
Igor Zhukov 9 years ago
parent
commit
3b5fe8e73b
  1. 25
      app/js/messages_manager.js

25
app/js/messages_manager.js

@ -704,16 +704,20 @@ angular.module('myApp.services')
} }
function getSearch (peerID, query, inputFilter, maxID, limit) { function getSearch (peerID, query, inputFilter, maxID, limit) {
peerID = peerID ? parseInt(peerID) : 0
var foundMsgs = [] var foundMsgs = []
var useSearchCache = !query var useSearchCache = !query
var newSearchFilter = {peer: peerID, filter: inputFilter} var newSearchFilter = {peer: peerID, filter: inputFilter}
var sameSearchCache = useSearchCache && angular.equals(lastSearchFilter, newSearchFilter) var sameSearchCache = useSearchCache && angular.equals(lastSearchFilter, newSearchFilter)
if (useSearchCache && !sameSearchCache) { if (useSearchCache && !sameSearchCache) {
// console.warn(dT(), 'new search filter', lastSearchFilter, newSearchFilter)
lastSearchFilter = newSearchFilter lastSearchFilter = newSearchFilter
lastSearchResults = [] lastSearchResults = []
} }
// console.log(dT(), 'search', useSearchCache, sameSearchCache, lastSearchResults, maxID)
if (peerID && !maxID && !query) { if (peerID && !maxID && !query) {
var historyStorage = historiesStorage[peerID] var historyStorage = historiesStorage[peerID]
@ -766,11 +770,11 @@ angular.module('myApp.services')
} }
} }
// console.log(dT(), sameSearchCache, foundMsgs, lastSearchResults) // console.warn(dT(), 'before append', foundMsgs)
if (foundMsgs.length < neededLimit && lastSearchResults.length && sameSearchCache) { if (foundMsgs.length < neededLimit && lastSearchResults.length && sameSearchCache) {
var minID = foundMsgs.length ? foundMsgs[foundMsgs.length - 1] : 0xFFFFFFFF var minID = foundMsgs.length ? foundMsgs[foundMsgs.length - 1] : false
for (var i = 0; i < lastSearchResults.length; i++) { for (var i = 0; i < lastSearchResults.length; i++) {
if (lastSearchResults[i] < minID) { if (minID === false || lastSearchResults[i] < minID) {
foundMsgs.push(lastSearchResults[i]) foundMsgs.push(lastSearchResults[i])
if (foundMsgs.length >= neededLimit) { if (foundMsgs.length >= neededLimit) {
break break
@ -778,7 +782,7 @@ angular.module('myApp.services')
} }
} }
} }
// console.log(dT(), foundMsgs) // console.warn(dT(), 'after append', foundMsgs)
} }
if (foundMsgs.length || limit == 1000) { if (foundMsgs.length || limit == 1000) {
@ -795,20 +799,15 @@ angular.module('myApp.services')
var apiPromise var apiPromise
if (peerID || !query) { if (peerID || !query) {
var flags = 0
if (AppPeersManager.isChannel(peerID) &&
!AppPeersManager.isMegagroup(peerID)) {
flags |= 1
}
apiPromise = MtpApiManager.invokeApi('messages.search', { apiPromise = MtpApiManager.invokeApi('messages.search', {
flags: flags, flags: 0,
peer: AppPeersManager.getInputPeerByID(peerID), peer: AppPeersManager.getInputPeerByID(peerID),
q: query || '', q: query || '',
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, filter: inputFilter || {_: 'inputMessagesFilterEmpty'},
min_date: 0, min_date: 0,
max_date: 0, max_date: 0,
limit: limit || 20, limit: limit || 20,
max_id: maxID || 0 max_id: AppMessagesIDsManager.getMessageLocalID(maxID) || 0
}, { }, {
timeout: 300, timeout: 300,
noErrorBox: true noErrorBox: true
@ -855,9 +854,11 @@ angular.module('myApp.services')
foundMsgs.push(message.mid) foundMsgs.push(message.mid)
}) })
if (useSearchCache) { if (useSearchCache &&
(!maxID || sameSearchCache && lastSearchResults.indexOf(maxID) >= 0)) {
lastSearchResults = listMergeSorted(lastSearchResults, foundMsgs) lastSearchResults = listMergeSorted(lastSearchResults, foundMsgs)
} }
// console.log(dT(), 'after API', foundMsgs, lastSearchResults)
return { return {
count: foundCount, count: foundCount,

Loading…
Cancel
Save