Browse Source

Select peers:

Fix infinity load bug
Fix search peer by text
Fix search Saved Messages
master
morethanwords 4 years ago
parent
commit
8a0f1ac794
  1. 34
      src/components/appSelectPeers.ts
  2. 6
      src/components/sidebarRight/tabs/forward.ts
  3. 24
      src/lib/appManagers/appMessagesManager.ts
  4. 78
      src/lib/searchIndexManager.ts

34
src/components/appSelectPeers.ts

@ -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]);
} }
@ -235,18 +237,30 @@ export class AppSelectPeers {
} }
} }
checkForTriggers = () => {
this.scrollable.checkForTriggers();
};
private getMoreResults() { private getMoreResults() {
const get = () => {
const promises: Promise<any>[] = []; const promises: Promise<any>[] = [];
if(!loadedAllDialogs) { if(!loadedAllDialogs && !loadAllDialogsPromise) {
promises.push(appMessagesManager.getConversationsAll()); loadAllDialogsPromise = appMessagesManager.getConversationsAll()
.then(() => {
loadedAllDialogs = true;
}, () => {
loadAllDialogsPromise = null;
});
promises.push(loadAllDialogsPromise);
} }
if((this.peerType.includes('dialogs') || this.loadedWhat.contacts) && !this.loadedWhat.archived) { // to load non-contacts if((this.peerType.includes('dialogs') || this.loadedWhat.contacts) && !this.loadedWhat.archived) { // to load non-contacts
promises.push(this.getMoreDialogs()); promises.push(this.getMoreDialogs());
if(!this.loadedWhat.archived) { if(!this.loadedWhat.archived) {
return Promise.all(promises); return promises;
} }
} }
@ -254,7 +268,15 @@ export class AppSelectPeers {
promises.push(this.getMoreContacts()); promises.push(this.getMoreContacts());
} }
return Promise.all(promises); return promises;
};
const promises = get();
const promise = Promise.all(promises);
if(promises.length) {
promise.then(this.checkForTriggers);
}
return promise
} }
private renderResults(peerIDs: number[]) { private renderResults(peerIDs: number[]) {

6
src/components/sidebarRight/tabs/forward.ts

@ -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');
} }

24
src/lib/appManagers/appMessagesManager.ts

@ -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;
} }

78
src/lib/searchIndexManager.ts

@ -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; let found = true;
for(const word of queryWords) {
for(i = 0; i < queryWords.length; i++) { if(fullText.indexOf(word) === -1) {
newFoundObjs = shortIndexes[queryWords[i].substr(0, 3)]; found = false;
if(!newFoundObjs) {
foundObjs = [];
break; break;
} }
}
if(foundObjs === false || foundObjs.length > newFoundObjs.length) { if(found) {
foundObjs = newFoundObjs; 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;
} }
newFoundObjs = {}; if(foundArr === undefined || foundArr.length > newFound.length) {
foundArr = newFound;
}
}
for(j = 0; j < foundObjs.length; j++) { for(let j = 0; j < foundArr.length; j++) {
found = true; let found = true;
searchText = fullTexts[foundObjs[j]]; let searchText = fullTexts[foundArr[j]];
for(i = 0; i < queryWords.length; i++) { for(let 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…
Cancel
Save