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