Select peers:
Fix infinity load bug Fix search peer by text Fix search Saved Messages
This commit is contained in:
parent
94db9c935e
commit
8a0f1ac794
@ -12,7 +12,7 @@ type PeerType = 'contacts' | 'dialogs';
|
|||||||
|
|
||||||
// TODO: правильная сортировка для addMembers, т.е. для peerType: 'contacts', потому что там идут сначала контакты - потом неконтакты, а должно всё сортироваться по имени
|
// TODO: правильная сортировка для addMembers, т.е. для peerType: 'contacts', потому что там идут сначала контакты - потом неконтакты, а должно всё сортироваться по имени
|
||||||
|
|
||||||
let loadedAllDialogs = false;
|
let loadedAllDialogs = false, loadAllDialogsPromise: Promise<any>;
|
||||||
export class AppSelectPeers {
|
export class AppSelectPeers {
|
||||||
public container = document.createElement('div');
|
public container = document.createElement('div');
|
||||||
public list = document.createElement('ul');
|
public list = document.createElement('ul');
|
||||||
@ -141,7 +141,9 @@ export class AppSelectPeers {
|
|||||||
|
|
||||||
private renderSaved() {
|
private renderSaved() {
|
||||||
if(!this.offsetIndex && this.folderID == 0 &&
|
if(!this.offsetIndex && this.folderID == 0 &&
|
||||||
(!this.query || 'saved messages'.includes(this.query.toLowerCase())) &&
|
(!this.query
|
||||||
|
|| 'saved messages'.includes(this.query.toLowerCase())
|
||||||
|
|| appUsersManager.getUser($rootScope.myID).sortName.includes(this.query.toLowerCase())) &&
|
||||||
this.peerType.includes('dialogs')) {
|
this.peerType.includes('dialogs')) {
|
||||||
this.renderResultsFunc([$rootScope.myID]);
|
this.renderResultsFunc([$rootScope.myID]);
|
||||||
}
|
}
|
||||||
@ -223,7 +225,7 @@ export class AppSelectPeers {
|
|||||||
const pageCount = appPhotosManager.windowH / 72 * 1.25 | 0;
|
const pageCount = appPhotosManager.windowH / 72 * 1.25 | 0;
|
||||||
const arr = this.cachedContacts.splice(0, pageCount);
|
const arr = this.cachedContacts.splice(0, pageCount);
|
||||||
this.renderResultsFunc(arr);
|
this.renderResultsFunc(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.cachedContacts.length) {
|
if(!this.cachedContacts.length) {
|
||||||
this.loadedWhat.contacts = true;
|
this.loadedWhat.contacts = true;
|
||||||
@ -235,26 +237,46 @@ export class AppSelectPeers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkForTriggers = () => {
|
||||||
|
this.scrollable.checkForTriggers();
|
||||||
|
};
|
||||||
|
|
||||||
private getMoreResults() {
|
private getMoreResults() {
|
||||||
const promises: Promise<any>[] = [];
|
const get = () => {
|
||||||
|
const promises: Promise<any>[] = [];
|
||||||
|
|
||||||
if(!loadedAllDialogs) {
|
if(!loadedAllDialogs && !loadAllDialogsPromise) {
|
||||||
promises.push(appMessagesManager.getConversationsAll());
|
loadAllDialogsPromise = appMessagesManager.getConversationsAll()
|
||||||
}
|
.then(() => {
|
||||||
|
loadedAllDialogs = true;
|
||||||
|
}, () => {
|
||||||
|
loadAllDialogsPromise = null;
|
||||||
|
});
|
||||||
|
|
||||||
if((this.peerType.includes('dialogs') || this.loadedWhat.contacts) && !this.loadedWhat.archived) { // to load non-contacts
|
promises.push(loadAllDialogsPromise);
|
||||||
promises.push(this.getMoreDialogs());
|
|
||||||
|
|
||||||
if(!this.loadedWhat.archived) {
|
|
||||||
return Promise.all(promises);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if((this.peerType.includes('dialogs') || this.loadedWhat.contacts) && !this.loadedWhat.archived) { // to load non-contacts
|
||||||
|
promises.push(this.getMoreDialogs());
|
||||||
|
|
||||||
|
if(!this.loadedWhat.archived) {
|
||||||
|
return promises;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.peerType.includes('contacts') && !this.loadedWhat.contacts) {
|
||||||
|
promises.push(this.getMoreContacts());
|
||||||
|
}
|
||||||
|
|
||||||
|
return promises;
|
||||||
|
};
|
||||||
|
|
||||||
if(this.peerType.includes('contacts') && !this.loadedWhat.contacts) {
|
const promises = get();
|
||||||
promises.push(this.getMoreContacts());
|
const promise = Promise.all(promises);
|
||||||
|
if(promises.length) {
|
||||||
|
promise.then(this.checkForTriggers);
|
||||||
}
|
}
|
||||||
|
return promise
|
||||||
return Promise.all(promises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderResults(peerIDs: number[]) {
|
private renderResults(peerIDs: number[]) {
|
||||||
|
@ -79,7 +79,11 @@ export default class AppForwardTab implements SliderTab {
|
|||||||
}, ['dialogs', 'contacts'], () => {
|
}, ['dialogs', 'contacts'], () => {
|
||||||
//console.log('forward rendered:', this.container.querySelector('.selector ul').childElementCount);
|
//console.log('forward rendered:', this.container.querySelector('.selector ul').childElementCount);
|
||||||
appSidebarRight.selectTab(AppSidebarRight.SLIDERITEMSIDS.forward);
|
appSidebarRight.selectTab(AppSidebarRight.SLIDERITEMSIDS.forward);
|
||||||
appSidebarRight.toggleSidebar(true);
|
appSidebarRight.toggleSidebar(true).then(() => {
|
||||||
|
if(this.selector) {
|
||||||
|
this.selector.checkForTriggers();
|
||||||
|
}
|
||||||
|
});
|
||||||
document.body.classList.add('is-forward-active');
|
document.body.classList.add('is-forward-active');
|
||||||
}, null, 'send');
|
}, null, 'send');
|
||||||
}
|
}
|
||||||
|
@ -516,11 +516,13 @@ export class AppMessagesManager {
|
|||||||
private cachedResults: {
|
private cachedResults: {
|
||||||
query: string,
|
query: string,
|
||||||
count: number,
|
count: number,
|
||||||
dialogs: Dialog[]
|
dialogs: Dialog[],
|
||||||
|
folderID: number
|
||||||
} = {
|
} = {
|
||||||
query: '',
|
query: '',
|
||||||
count: 0,
|
count: 0,
|
||||||
dialogs: []
|
dialogs: [],
|
||||||
|
folderID: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
private log = logger('MESSAGES'/* , LogLevels.error */);
|
private log = logger('MESSAGES'/* , LogLevels.error */);
|
||||||
@ -1900,27 +1902,23 @@ export class AppMessagesManager {
|
|||||||
let curDialogStorage = this.dialogsStorage.getFolder(folderID);
|
let curDialogStorage = this.dialogsStorage.getFolder(folderID);
|
||||||
|
|
||||||
if(query) {
|
if(query) {
|
||||||
if(!limit || this.cachedResults.query !== query) {
|
if(!limit || this.cachedResults.query !== query || this.cachedResults.folderID != folderID) {
|
||||||
this.cachedResults.query = query
|
this.cachedResults.query = query;
|
||||||
|
this.cachedResults.folderID = folderID;
|
||||||
|
|
||||||
const results = searchIndexManager.search(query, this.dialogsIndex);
|
const results = searchIndexManager.search(query, this.dialogsIndex);
|
||||||
|
|
||||||
this.cachedResults.dialogs = [];
|
this.cachedResults.dialogs = [];
|
||||||
/* for(const folderID in this.dialogsStorage) {
|
|
||||||
const dialogs = this.dialogsStorage[folderID];
|
|
||||||
dialogs.forEach(dialog => {
|
|
||||||
if(results[dialog.peerID]) {
|
|
||||||
this.cachedResults.dialogs.push(dialog);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} */
|
|
||||||
for(const peerID in this.dialogsStorage.dialogs) {
|
for(const peerID in this.dialogsStorage.dialogs) {
|
||||||
const dialog = this.dialogsStorage.dialogs[peerID];
|
const dialog = this.dialogsStorage.dialogs[peerID];
|
||||||
if(results[dialog.peerID]) {
|
if(results[dialog.peerID] && dialog.folder_id == folderID) {
|
||||||
this.cachedResults.dialogs.push(dialog);
|
this.cachedResults.dialogs.push(dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.cachedResults.dialogs.sort((d1, d2) => d2.index - d1.index);
|
||||||
|
|
||||||
this.cachedResults.count = this.cachedResults.dialogs.length;
|
this.cachedResults.count = this.cachedResults.dialogs.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,22 @@
|
|||||||
import Config from './config';
|
import Config from './config';
|
||||||
|
|
||||||
|
export type SearchIndex = {
|
||||||
|
fullTexts: {
|
||||||
|
[peerID: string]: string
|
||||||
|
}/* ,
|
||||||
|
shortIndexes: {
|
||||||
|
[shortStr: string]: number[]
|
||||||
|
} */
|
||||||
|
};
|
||||||
|
|
||||||
class SearchIndexManager {
|
class SearchIndexManager {
|
||||||
public static badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<]+/g;
|
public static badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<]+/g;
|
||||||
public static trimRe = /^\s+|\s$/g;
|
public static trimRe = /^\s+|\s$/g;
|
||||||
|
|
||||||
public createIndex() {
|
public createIndex(): SearchIndex {
|
||||||
return {
|
return {
|
||||||
shortIndexes: {},
|
fullTexts: {}/* ,
|
||||||
fullTexts: {}
|
shortIndexes: {} */
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,21 +42,19 @@ class SearchIndexManager {
|
|||||||
return username && username.toLowerCase() || '';
|
return username && username.toLowerCase() || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public indexObject(id: number, searchText: string, searchIndex: any) {
|
public indexObject(id: number, searchText: string, searchIndex: SearchIndex) {
|
||||||
if(searchIndex.fullTexts[id] !== undefined) {
|
if(searchIndex.fullTexts.hasOwnProperty(id)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchText = this.cleanSearchText(searchText);
|
searchText = this.cleanSearchText(searchText);
|
||||||
|
|
||||||
if(!searchText.length) {
|
if(!searchText.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shortIndexes = searchIndex.shortIndexes;
|
|
||||||
|
|
||||||
searchIndex.fullTexts[id] = searchText;
|
searchIndex.fullTexts[id] = searchText;
|
||||||
|
|
||||||
|
/* const shortIndexes = searchIndex.shortIndexes;
|
||||||
searchText.split(' ').forEach((searchWord) => {
|
searchText.split(' ').forEach((searchWord) => {
|
||||||
let len = Math.min(searchWord.length, 3),
|
let len = Math.min(searchWord.length, 3),
|
||||||
wordPart, i;
|
wordPart, i;
|
||||||
@ -59,39 +66,52 @@ class SearchIndexManager {
|
|||||||
shortIndexes[wordPart].push(id);
|
shortIndexes[wordPart].push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}); */
|
||||||
}
|
}
|
||||||
|
|
||||||
public search(query: string, searchIndex: any) {
|
public search(query: string, searchIndex: SearchIndex) {
|
||||||
const shortIndexes = searchIndex.shortIndexes;
|
|
||||||
const fullTexts = searchIndex.fullTexts;
|
const fullTexts = searchIndex.fullTexts;
|
||||||
|
//const shortIndexes = searchIndex.shortIndexes;
|
||||||
|
|
||||||
query = this.cleanSearchText(query);
|
query = this.cleanSearchText(query);
|
||||||
|
|
||||||
|
const newFoundObjs: {[peerID: string]: true} = {};
|
||||||
const queryWords = query.split(' ');
|
const queryWords = query.split(' ');
|
||||||
let foundObjs: any = false,
|
for(const peerID in fullTexts) {
|
||||||
newFoundObjs: any, i: number;
|
const fullText = fullTexts[peerID];
|
||||||
let j: number, searchText: string;
|
|
||||||
let found: boolean;
|
|
||||||
|
|
||||||
for(i = 0; i < queryWords.length; i++) {
|
let found = true;
|
||||||
newFoundObjs = shortIndexes[queryWords[i].substr(0, 3)];
|
for(const word of queryWords) {
|
||||||
if(!newFoundObjs) {
|
if(fullText.indexOf(word) === -1) {
|
||||||
foundObjs = [];
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(found) {
|
||||||
|
newFoundObjs[peerID] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* const queryWords = query.split(' ');
|
||||||
|
let foundArr: number[];
|
||||||
|
for(let i = 0; i < queryWords.length; i++) {
|
||||||
|
const newFound = shortIndexes[queryWords[i].substr(0, 3)];
|
||||||
|
if(!newFound) {
|
||||||
|
foundArr = [];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(foundObjs === false || foundObjs.length > newFoundObjs.length) {
|
if(foundArr === undefined || foundArr.length > newFound.length) {
|
||||||
foundObjs = newFoundObjs;
|
foundArr = newFound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newFoundObjs = {};
|
for(let j = 0; j < foundArr.length; j++) {
|
||||||
|
let found = true;
|
||||||
for(j = 0; j < foundObjs.length; j++) {
|
let searchText = fullTexts[foundArr[j]];
|
||||||
found = true;
|
for(let i = 0; i < queryWords.length; i++) {
|
||||||
searchText = fullTexts[foundObjs[j]];
|
|
||||||
for(i = 0; i < queryWords.length; i++) {
|
|
||||||
if(searchText.indexOf(queryWords[i]) == -1) {
|
if(searchText.indexOf(queryWords[i]) == -1) {
|
||||||
found = false;
|
found = false;
|
||||||
break;
|
break;
|
||||||
@ -99,9 +119,9 @@ class SearchIndexManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(found) {
|
if(found) {
|
||||||
newFoundObjs[foundObjs[j]] = true;
|
newFoundObjs[foundArr[j]] = true;
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
return newFoundObjs;
|
return newFoundObjs;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user