Search only by words beginning
This commit is contained in:
parent
e0b2b1ed39
commit
45acc17f6f
@ -189,11 +189,7 @@ export default class AppSelectPeers {
|
||||
}
|
||||
|
||||
private renderSaved() {
|
||||
if(!this.offsetIndex && this.folderId == 0 &&
|
||||
(!this.query
|
||||
|| 'saved messages'.includes(this.query.toLowerCase())
|
||||
|| appUsersManager.getUser(rootScope.myId).sortName.includes(this.query.toLowerCase())) &&
|
||||
this.peerType.includes('dialogs')) {
|
||||
if(!this.offsetIndex && this.folderId == 0 && this.peerType.includes('dialogs') && (!this.query || appUsersManager.testSelfSearch(this.query))) {
|
||||
this.renderResultsFunc([rootScope.myId]);
|
||||
}
|
||||
}
|
||||
|
@ -232,19 +232,19 @@ export class AppMessagesManager {
|
||||
const processDialog = (dialog: MTDialog.dialog) => {
|
||||
const historyStorage = this.getHistoryStorage(dialog.peerId);
|
||||
const history = [].concat(historyStorage.history);
|
||||
dialog = copy(dialog);
|
||||
//dialog = copy(dialog);
|
||||
let removeUnread = 0;
|
||||
for(const mid of history) {
|
||||
const message = this.getMessageByPeer(dialog.peerId, mid);
|
||||
if(/* message._ != 'messageEmpty' && */!message.pFlags.is_outgoing) {
|
||||
messages.push(message);
|
||||
|
||||
if(message.fromId != dialog.peerId) {
|
||||
if(message.fromId !== dialog.peerId) {
|
||||
appStateManager.setPeer(message.fromId, appPeersManager.getPeer(message.fromId));
|
||||
}
|
||||
|
||||
dialog.top_message = message.mid;
|
||||
this.dialogsStorage.generateIndexForDialog(dialog, false, message);
|
||||
/* dialog.top_message = message.mid;
|
||||
this.dialogsStorage.generateIndexForDialog(dialog, false, message); */
|
||||
|
||||
break;
|
||||
} else if(message.pFlags && message.pFlags.unread) {
|
||||
@ -320,6 +320,8 @@ export class AppMessagesManager {
|
||||
|
||||
if(state.dialogs) {
|
||||
state.dialogs.forEachReverse(dialog => {
|
||||
dialog.top_message = this.getServerMessageId(dialog.top_message); // * fix outgoing message to avoid copying dialog
|
||||
|
||||
this.saveConversation(dialog);
|
||||
|
||||
// ! WARNING, убрать это когда нужно будет делать чтобы pending сообщения сохранялись
|
||||
@ -4416,8 +4418,6 @@ export class AppMessagesManager {
|
||||
|
||||
this.maxSeenId = maxId;
|
||||
|
||||
sessionStorage.set({max_seen_msg: maxId});
|
||||
|
||||
apiManager.invokeApi('messages.receivedMessages', {
|
||||
max_id: this.getServerMessageId(maxId)
|
||||
});
|
||||
|
@ -176,7 +176,7 @@ export class AppUsersManager {
|
||||
return '';
|
||||
}
|
||||
|
||||
const serviceText = user.pFlags.self ? 'user_name_saved_msgs_raw' : '';
|
||||
const serviceText = user.pFlags.self ? 'Saved Messages' : '';
|
||||
return (user.first_name || '') +
|
||||
' ' + (user.last_name || '') +
|
||||
' ' + (user.phone || '') +
|
||||
@ -202,10 +202,7 @@ export class AppUsersManager {
|
||||
});
|
||||
|
||||
if(includeSaved) {
|
||||
const isSearchingSaved = 'saved messages'.includes(query.toLowerCase())
|
||||
|| appUsersManager.getUser(rootScope.myId).sortName.includes(query.toLowerCase());
|
||||
|
||||
if(isSearchingSaved) {
|
||||
if(this.testSelfSearch(query)) {
|
||||
contactsList.findAndSplice(p => p == rootScope.myId);
|
||||
contactsList.unshift(rootScope.myId);
|
||||
}
|
||||
@ -225,12 +222,19 @@ export class AppUsersManager {
|
||||
});
|
||||
}
|
||||
|
||||
public testSelfSearch(query: string) {
|
||||
const user = this.getSelf();
|
||||
const index = searchIndexManager.createIndex();
|
||||
searchIndexManager.indexObject(user.id, this.getUserSearchText(user.id), index);
|
||||
return !!searchIndexManager.search(query, index)[user.id];
|
||||
}
|
||||
|
||||
public saveApiUsers(apiUsers: any[]) {
|
||||
apiUsers.forEach((user) => this.saveApiUser(user));
|
||||
}
|
||||
|
||||
public saveApiUser(_user: MTUser, noReplace?: boolean) {
|
||||
if(_user._ == 'userEmpty') return;
|
||||
if(_user._ === 'userEmpty') return;
|
||||
|
||||
const user = _user;
|
||||
if(noReplace && isObject(this.users[user.id]) && this.users[user.id].first_name) {
|
||||
@ -311,7 +315,7 @@ export class AppUsersManager {
|
||||
|
||||
public getUserStatusForSort(status: User['status']) {
|
||||
if(status) {
|
||||
const expires = status._ == 'userStatusOnline' ? status.expires : (status._ == 'userStatusOffline' ? status.was_online : 0);
|
||||
const expires = status._ === 'userStatusOnline' ? status.expires : (status._ === 'userStatusOffline' ? status.was_online : 0);
|
||||
if(expires) {
|
||||
return expires;
|
||||
}
|
||||
@ -478,7 +482,7 @@ export class AppUsersManager {
|
||||
const user = this.users[i];
|
||||
|
||||
if(user.status &&
|
||||
user.status._ == 'userStatusOnline' &&
|
||||
user.status._ === 'userStatusOnline' &&
|
||||
user.status.expires < timestampNow) {
|
||||
|
||||
user.status = {_: 'userStatusOffline', was_online: user.status.expires};
|
||||
@ -505,8 +509,8 @@ export class AppUsersManager {
|
||||
const user = this.getUser(id);
|
||||
if(user &&
|
||||
user.status &&
|
||||
user.status._ != 'userStatusOnline' &&
|
||||
user.status._ != 'userStatusEmpty' &&
|
||||
user.status._ !== 'userStatusOnline' &&
|
||||
user.status._ !== 'userStatusEmpty' &&
|
||||
!user.pFlags.support &&
|
||||
!user.pFlags.deleted) {
|
||||
|
||||
@ -605,7 +609,7 @@ export class AppUsersManager {
|
||||
hash: 0,
|
||||
}).then((result) => {
|
||||
let peerIds: number[];
|
||||
if(result._ == 'contacts.topPeers') {
|
||||
if(result._ === 'contacts.topPeers') {
|
||||
//console.log(result);
|
||||
this.saveApiUsers(result.users);
|
||||
appChatsManager.saveApiChats(result.chats);
|
||||
|
@ -21,7 +21,7 @@ class SearchIndexManager {
|
||||
}
|
||||
|
||||
public cleanSearchText(text: string, latinize = true) {
|
||||
const hasTag = text.charAt(0) == '%';
|
||||
const hasTag = text.charAt(0) === '%';
|
||||
text = text.replace(SearchIndexManager['badCharsRe'], '').replace(SearchIndexManager['trimRe'], '');
|
||||
if(latinize) {
|
||||
text = text.replace(/[^A-Za-z0-9]/g, (ch) => {
|
||||
@ -81,8 +81,9 @@ class SearchIndexManager {
|
||||
const fullText = fullTexts[peerId];
|
||||
|
||||
let found = true;
|
||||
for(const word of queryWords) {
|
||||
if(fullText.indexOf(word) === -1) {
|
||||
for(const word of queryWords) { // * verify that all words are found
|
||||
const idx = fullText.indexOf(word);
|
||||
if(idx === -1 || (idx !== 0 && fullText[idx - 1] !== ' ')) { // * search only from word beginning
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user