Multi search + latinizer
Added latinizer for search indexer. Closes #678 Added multisearch for conversations / messages. Closes #676
This commit is contained in:
parent
50d2c079e2
commit
b49f9d0efd
@ -2473,7 +2473,8 @@ a.peer_photo_init:focus {
|
||||
|
||||
|
||||
|
||||
.im_dialogs_contacts_wrap h5 {
|
||||
.im_dialogs_contacts_wrap h5,
|
||||
.im_dialogs_messages_wrap h5 {
|
||||
color: #999;
|
||||
font-size: 13px;
|
||||
margin-left: 20px;
|
||||
|
@ -409,7 +409,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
|
||||
$scope.searchClear = function () {
|
||||
$scope.search.query = '';
|
||||
$scope.search.messages = false;
|
||||
$scope.$broadcast('search_clear');
|
||||
}
|
||||
|
||||
@ -468,7 +467,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
if ($routeParams.q) {
|
||||
if ($routeParams.q !== lastSearch) {
|
||||
$scope.search.query = lastSearch = $routeParams.q;
|
||||
$scope.search.messages = true;
|
||||
if ($scope.curDialog !== undefined) {
|
||||
return false;
|
||||
}
|
||||
@ -505,7 +503,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
$scope.dialogs = [];
|
||||
$scope.contacts = [];
|
||||
$scope.foundUsers = [];
|
||||
$scope.contactsLoaded = false;
|
||||
$scope.foundMessages = [];
|
||||
|
||||
if ($scope.search === undefined) {
|
||||
$scope.search = {};
|
||||
}
|
||||
@ -514,12 +513,13 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
}
|
||||
$scope.phonebookAvailable = PhonebookContactsService.isAvailable();
|
||||
|
||||
var offset = 0,
|
||||
maxID = 0,
|
||||
hasMore = false,
|
||||
jump = 0,
|
||||
peersInDialogs = {},
|
||||
contactsShown;
|
||||
var searchMessages = false;
|
||||
var maxID = 0;
|
||||
var hasMore = false;
|
||||
var jump = 0;
|
||||
var contactsJump = 0;
|
||||
var peersInDialogs = {};
|
||||
var contactsShown;
|
||||
|
||||
$scope.$on('dialogs_need_more', function () {
|
||||
// console.log('on need more');
|
||||
@ -550,7 +550,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
if (pos !== false) {
|
||||
var prev = $scope.dialogs.splice(pos, 1);
|
||||
safeReplaceObject(prev, wrappedDialog);
|
||||
offset++;
|
||||
}
|
||||
$scope.dialogs.unshift(wrappedDialog);
|
||||
delete $scope.isEmpty.dialogs;
|
||||
@ -558,7 +557,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
if (!peersInDialogs[dialog.peerID]) {
|
||||
peersInDialogs[dialog.peerID] = true;
|
||||
if (contactsShown) {
|
||||
showMoreContacts();
|
||||
showMoreConversations();
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,17 +583,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
}
|
||||
});
|
||||
|
||||
var prevMessages = false;
|
||||
$scope.$watchCollection('search', function () {
|
||||
if ($scope.search.messages != prevMessages) {
|
||||
prevMessages = $scope.search.messages;
|
||||
$scope.dialogs = [];
|
||||
loadDialogs(true);
|
||||
} else {
|
||||
loadDialogs();
|
||||
}
|
||||
$scope.dialogs = [];
|
||||
$scope.foundMessages = [];
|
||||
searchMessages = false;
|
||||
contactsJump++;
|
||||
loadDialogs();
|
||||
|
||||
if ($routeParams.q && (!$scope.search.messages || $scope.search.query != $routeParams.q)) {
|
||||
if ($routeParams.q && $scope.search.query != $routeParams.q) {
|
||||
$timeout(function () {
|
||||
$location.url(
|
||||
'/im' +
|
||||
@ -620,7 +616,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
|
||||
$scope.$on('contacts_update', function () {
|
||||
if (contactsShown) {
|
||||
showMoreContacts();
|
||||
showMoreConversations();
|
||||
}
|
||||
});
|
||||
|
||||
@ -628,13 +624,12 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
|
||||
var searchTimeoutPromise;
|
||||
function getDialogs(force) {
|
||||
var searchMessages = $scope.search.messages && $scope.search.query.length > 0,
|
||||
curJump = ++jump,
|
||||
var curJump = ++jump,
|
||||
promise;
|
||||
|
||||
$timeout.cancel(searchTimeoutPromise);
|
||||
if (searchMessages) {
|
||||
searchTimeoutPromise = force ? $q.when() : $timeout(angular.noop, 500);
|
||||
searchTimeoutPromise = (force || maxID) ? $q.when() : $timeout(angular.noop, 500);
|
||||
promise = searchTimeoutPromise.then(function () {
|
||||
return AppMessagesManager.getSearch({_: 'inputPeerEmpty'}, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID);
|
||||
});
|
||||
@ -686,29 +681,38 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
};
|
||||
|
||||
function loadDialogs (force) {
|
||||
offset = 0;
|
||||
maxID = 0;
|
||||
hasMore = false;
|
||||
peersInDialogs = {};
|
||||
contactsShown = false;
|
||||
if (!searchMessages) {
|
||||
peersInDialogs = {};
|
||||
contactsShown = false;
|
||||
}
|
||||
|
||||
getDialogs(force).then(function (dialogsResult) {
|
||||
$scope.dialogs = [];
|
||||
$scope.contacts = [];
|
||||
$scope.foundUsers = [];
|
||||
if (!searchMessages) {
|
||||
$scope.dialogs = [];
|
||||
$scope.contacts = [];
|
||||
$scope.foundUsers = [];
|
||||
}
|
||||
$scope.foundMessages = [];
|
||||
|
||||
var dialogsList = searchMessages ? $scope.foundMessages : $scope.dialogs;
|
||||
|
||||
if (dialogsResult.dialogs.length) {
|
||||
offset += dialogsResult.dialogs.length;
|
||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count);
|
||||
if (!searchMessages) {
|
||||
peersInDialogs[dialog.peerID] = true;
|
||||
}
|
||||
dialogsList.push(wrappedDialog);
|
||||
});
|
||||
|
||||
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
|
||||
hasMore = dialogsResult.count === null || offset < dialogsResult.count;
|
||||
hasMore = dialogsResult.count === null || dialogsList.length < dialogsResult.count;
|
||||
|
||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||
peersInDialogs[dialog.peerID] = true;
|
||||
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count);
|
||||
$scope.dialogs.push(wrappedDialog);
|
||||
});
|
||||
delete $scope.isEmpty.dialogs;
|
||||
if (!searchMessages) {
|
||||
delete $scope.isEmpty.dialogs;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$broadcast('ui_dialogs_change');
|
||||
@ -726,12 +730,42 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
});
|
||||
}
|
||||
|
||||
function showMoreContacts () {
|
||||
function showMoreDialogs () {
|
||||
if (contactsShown && (!hasMore || !maxID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMore && !searchMessages && ($scope.search.query || !$scope.dialogs.length)) {
|
||||
showMoreConversations();
|
||||
return;
|
||||
}
|
||||
|
||||
getDialogs().then(function (dialogsResult) {
|
||||
if (dialogsResult.dialogs.length) {
|
||||
var dialogsList = searchMessages ? $scope.foundMessages : $scope.dialogs;
|
||||
|
||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count);
|
||||
if (!searchMessages) {
|
||||
peersInDialogs[dialog.peerID] = true;
|
||||
}
|
||||
dialogsList.push(wrappedDialog);
|
||||
});
|
||||
|
||||
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
|
||||
hasMore = dialogsResult.count === null || dialogsList.length < dialogsResult.count;
|
||||
|
||||
$scope.$broadcast('ui_dialogs_append');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function showMoreConversations () {
|
||||
contactsShown = true;
|
||||
|
||||
var curJump = ++jump;
|
||||
var curJump = ++contactsJump;
|
||||
AppUsersManager.getContacts($scope.search.query).then(function (contactsList) {
|
||||
if (curJump != jump) return;
|
||||
if (curJump != contactsJump) return;
|
||||
$scope.contacts = [];
|
||||
angular.forEach(contactsList, function(userID) {
|
||||
if (peersInDialogs[userID] === undefined) {
|
||||
@ -753,10 +787,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
|
||||
if ($scope.search.query && $scope.search.query.length >= 5) {
|
||||
$timeout(function() {
|
||||
if (curJump != jump) return;
|
||||
if (curJump != contactsJump) return;
|
||||
MtpApiManager.invokeApi('contacts.search', {q: $scope.search.query, limit: 10}).then(function (result) {
|
||||
AppUsersManager.saveApiUsers(result.users);
|
||||
if (curJump != jump) return;
|
||||
if (curJump != contactsJump) return;
|
||||
$scope.foundUsers = [];
|
||||
angular.forEach(result.results, function(contactFound) {
|
||||
var userID = contactFound.user_id;
|
||||
@ -775,34 +809,13 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
|
||||
if ($scope.search.query) {
|
||||
searchMessages = true;
|
||||
loadDialogs();
|
||||
}
|
||||
}
|
||||
|
||||
function showMoreDialogs () {
|
||||
if (contactsShown && (!hasMore || !offset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasMore && !$scope.search.messages && ($scope.search.query || !$scope.dialogs.length)) {
|
||||
showMoreContacts();
|
||||
return;
|
||||
}
|
||||
|
||||
getDialogs().then(function (dialogsResult) {
|
||||
if (dialogsResult.dialogs.length) {
|
||||
offset += dialogsResult.dialogs.length;
|
||||
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
|
||||
hasMore = dialogsResult.count === null || offset < dialogsResult.count;
|
||||
|
||||
angular.forEach(dialogsResult.dialogs, function (dialog) {
|
||||
peersInDialogs[dialog.peerID] = true;
|
||||
$scope.dialogs.push(AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count));
|
||||
});
|
||||
|
||||
$scope.$broadcast('ui_dialogs_append');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})
|
||||
|
||||
.controller('AppImHistoryController', function ($scope, $location, $timeout, $rootScope, MtpApiManager, AppUsersManager, AppChatsManager, AppMessagesManager, AppPeersManager, ApiUpdatesManager, PeersSelectService, IdleManager, StatusManager, ErrorService) {
|
||||
|
File diff suppressed because one or more lines are too long
@ -736,16 +736,7 @@ angular.module('izhukov.utils', [])
|
||||
|
||||
.service('SearchIndexManager', function () {
|
||||
var badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<\s]+/g,
|
||||
trimRe = /^\s+|\s$/g,
|
||||
accentsReplace = {
|
||||
a: /[åáâäà]/g,
|
||||
e: /[éêëè]/g,
|
||||
i: /[íîïì]/g,
|
||||
o: /[óôöò]/g,
|
||||
u: /[úûüù]/g,
|
||||
c: /ç/g,
|
||||
ss: /ß/g
|
||||
}
|
||||
trimRe = /^\s+|\s$/g;
|
||||
|
||||
return {
|
||||
createIndex: createIndex,
|
||||
@ -762,13 +753,11 @@ angular.module('izhukov.utils', [])
|
||||
}
|
||||
|
||||
function cleanSearchText (text) {
|
||||
text = text.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase();
|
||||
|
||||
for (var key in accentsReplace) {
|
||||
if (accentsReplace.hasOwnProperty(key)) {
|
||||
text = text.replace(accentsReplace[key], key);
|
||||
}
|
||||
}
|
||||
text = text.replace(badCharsRe, ' ').replace(trimRe, '');
|
||||
text = text.replace(/[^A-Za-z0-9]/g, function (ch) {
|
||||
return Config.LatinizeMap[ch] || ch;
|
||||
});
|
||||
text = text.toLowerCase();
|
||||
|
||||
return text;
|
||||
}
|
||||
|
@ -12,13 +12,6 @@
|
||||
<i class="icon icon-search-clear"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_tabs_wrap">
|
||||
<div class="im_dialogs_tabs clearfix">
|
||||
<a href="" class="im_dialogs_tab" ng-class="{active: !search.messages}" ng-click="search.messages = false" my-i18n="im_conversations"></a>
|
||||
<a href="" class="im_dialogs_tab" ng-class="{active: search.messages}" ng-click="search.messages = true" my-i18n="im_messages"></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div my-dialogs-list class="im_dialogs_col">
|
||||
@ -32,22 +25,16 @@
|
||||
<button ng-if="phonebookAvailable" type="button" class="btn btn-primary btn-sm im_dialogs_import_phonebook" ng-click="importPhonebook()" my-i18n="im_import_phonebook"></button>
|
||||
</div>
|
||||
|
||||
<div ng-switch="search.messages">
|
||||
<ul ng-switch-when="true" class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.id" ng-class="{active: curDialog.peerID == dialogMessage.peerID && curDialog.messageID == dialogMessage.id}"></li>
|
||||
</ul>
|
||||
<ul ng-switch-default class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.peerID" ng-class="{active: curDialog.peerID == dialogMessage.peerID}"></li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.peerID" ng-class="{active: curDialog.peerID == dialogMessage.peerID}"></li>
|
||||
</ul>
|
||||
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages && contacts.length > 0">
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="contacts.length > 0">
|
||||
<h5 my-i18n="im_contacts_title"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" ng-repeat="contact in contacts | orderBy:'user.sortName' track by contact.userID" ng-class="{active: curDialog.peerID == contact.userID}">
|
||||
<a class="im_dialog" ng-mousedown="dialogSelect(contact.peerString)">
|
||||
<div class="im_dialog_photo pull-left" my-peer-photolink="contact.userID" img-class="im_dialog_photo" watch="true"></div>
|
||||
|
||||
<div class="im_dialog_message_wrap">
|
||||
<div class="im_dialog_peer">
|
||||
<span class="im_dialog_user" my-user-link="contact.userID"></span>
|
||||
@ -61,7 +48,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages && foundUsers.length > 0">
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="foundUsers.length > 0">
|
||||
<h5 my-i18n="im_found_title"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" ng-repeat="foundUser in foundUsers track by foundUser.userID" ng-class="{active: curDialog.peerID == foundUser.userID}">
|
||||
@ -81,6 +68,13 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_messages_wrap" ng-show="foundMessages.length > 0">
|
||||
<h5 my-i18n="im_messages"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in foundMessages track by dialogMessage.id" ng-class="{active: curDialog.peerID == dialogMessage.peerID && curDialog.messageID == dialogMessage.id}"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -12,13 +12,6 @@
|
||||
<i class="icon icon-search-clear"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_tabs_wrap">
|
||||
<div class="im_dialogs_tabs clearfix">
|
||||
<a href="" class="im_dialogs_tab" ng-class="{active: !search.messages}" ng-click="search.messages = false" my-i18n="im_conversations"></a>
|
||||
<a href="" class="im_dialogs_tab" ng-class="{active: search.messages}" ng-click="search.messages = true" my-i18n="im_messages"></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div my-dialogs-list-mobile class="im_dialogs_col im_dialogs_scrollable_wrap mobile_scrollable_wrap">
|
||||
@ -30,21 +23,16 @@
|
||||
<button ng-if="phonebookAvailable" type="button" class="btn btn-primary btn-block im_dialogs_import_phonebook" ng-click="importPhonebook()" my-i18n="im_import_phonebook"></button>
|
||||
</div>
|
||||
|
||||
<div ng-switch="search.messages">
|
||||
<ul ng-switch-when="true" class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.id" ng-class="{active: curDialog.peerID == dialogMessage.peerID && curDialog.messageID == dialogMessage.id}"></li>
|
||||
</ul>
|
||||
<ul ng-switch-default class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.peerID" ng-class="{active: curDialog.peerID == dialogMessage.peerID}"></li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in dialogs track by dialogMessage.peerID" ng-class="{active: curDialog.peerID == dialogMessage.peerID}"></li>
|
||||
</ul>
|
||||
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages && contacts.length > 0">
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="contacts.length > 0">
|
||||
<h5 my-i18n="im_contacts_title"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" ng-repeat="contact in contacts | orderBy:'user.sortName' track by contact.userID" ng-class="{active: curDialog.peerID == contact.userID}">
|
||||
<a class="im_dialog" ng-mousedown="dialogSelect(contact.peerString)">
|
||||
<div class="im_dialog_photo pull-left" my-user-photolink="contact.userID" img-class="im_dialog_photo"></div>
|
||||
<div class="im_dialog_photo pull-left" my-user-photolink="contact.userID" img-class="im_dialog_photo" watch="true"></div>
|
||||
<div class="im_dialog_message_wrap">
|
||||
<div class="im_dialog_peer">
|
||||
<span class="im_dialog_user" my-user-link="contact.userID"></span>
|
||||
@ -58,12 +46,12 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages && foundUsers.length > 0">
|
||||
<div class="im_dialogs_contacts_wrap" ng-show="foundUsers.length > 0">
|
||||
<h5 my-i18n="im_found_title"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" ng-repeat="foundUser in foundUsers track by foundUser.userID" ng-class="{active: curDialog.peerID == foundUser.userID}">
|
||||
<a class="im_dialog" ng-mousedown="dialogSelect(foundUser.peerString)">
|
||||
<div class="im_dialog_photo pull-left" my-user-photolink="foundUser.userID" img-class="im_dialog_photo"></div>
|
||||
<div class="im_dialog_photo pull-left" my-user-photolink="foundUser.userID" img-class="im_dialog_photo" watch="true"></div>
|
||||
<div class="im_dialog_message_wrap">
|
||||
<div class="im_dialog_peer">
|
||||
<span class="im_dialog_user" my-user-link="foundUser.userID"></span>
|
||||
@ -78,6 +66,13 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="im_dialogs_messages_wrap" ng-show="foundMessages.length > 0">
|
||||
<h5 my-i18n="im_messages"></h5>
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="im_dialog_wrap" my-dialog dialog-message="dialogMessage" ng-repeat="dialogMessage in foundMessages track by dialogMessage.id" ng-class="{active: curDialog.peerID == dialogMessage.peerID && curDialog.messageID == dialogMessage.id}"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user