Browse Source

Multi search + latinizer

Added latinizer for search indexer. Closes #678
Added multisearch for conversations / messages. Closes #676
master
Igor Zhukov 10 years ago
parent
commit
b49f9d0efd
  1. 3
      app/css/app.css
  2. 131
      app/js/controllers.js
  3. 5
      app/js/lib/config.js
  4. 23
      app/js/lib/ng_utils.js
  5. 26
      app/partials/desktop/im.html
  6. 29
      app/partials/mobile/im.html

3
app/css/app.css

@ -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; color: #999;
font-size: 13px; font-size: 13px;
margin-left: 20px; margin-left: 20px;

131
app/js/controllers.js

@ -409,7 +409,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.searchClear = function () { $scope.searchClear = function () {
$scope.search.query = ''; $scope.search.query = '';
$scope.search.messages = false;
$scope.$broadcast('search_clear'); $scope.$broadcast('search_clear');
} }
@ -468,7 +467,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if ($routeParams.q) { if ($routeParams.q) {
if ($routeParams.q !== lastSearch) { if ($routeParams.q !== lastSearch) {
$scope.search.query = lastSearch = $routeParams.q; $scope.search.query = lastSearch = $routeParams.q;
$scope.search.messages = true;
if ($scope.curDialog !== undefined) { if ($scope.curDialog !== undefined) {
return false; return false;
} }
@ -505,7 +503,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.dialogs = []; $scope.dialogs = [];
$scope.contacts = []; $scope.contacts = [];
$scope.foundUsers = []; $scope.foundUsers = [];
$scope.contactsLoaded = false; $scope.foundMessages = [];
if ($scope.search === undefined) { if ($scope.search === undefined) {
$scope.search = {}; $scope.search = {};
} }
@ -514,12 +513,13 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
$scope.phonebookAvailable = PhonebookContactsService.isAvailable(); $scope.phonebookAvailable = PhonebookContactsService.isAvailable();
var offset = 0, var searchMessages = false;
maxID = 0, var maxID = 0;
hasMore = false, var hasMore = false;
jump = 0, var jump = 0;
peersInDialogs = {}, var contactsJump = 0;
contactsShown; var peersInDialogs = {};
var contactsShown;
$scope.$on('dialogs_need_more', function () { $scope.$on('dialogs_need_more', function () {
// console.log('on need more'); // console.log('on need more');
@ -550,7 +550,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (pos !== false) { if (pos !== false) {
var prev = $scope.dialogs.splice(pos, 1); var prev = $scope.dialogs.splice(pos, 1);
safeReplaceObject(prev, wrappedDialog); safeReplaceObject(prev, wrappedDialog);
offset++;
} }
$scope.dialogs.unshift(wrappedDialog); $scope.dialogs.unshift(wrappedDialog);
delete $scope.isEmpty.dialogs; delete $scope.isEmpty.dialogs;
@ -558,7 +557,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if (!peersInDialogs[dialog.peerID]) { if (!peersInDialogs[dialog.peerID]) {
peersInDialogs[dialog.peerID] = true; peersInDialogs[dialog.peerID] = true;
if (contactsShown) { if (contactsShown) {
showMoreContacts(); showMoreConversations();
} }
} }
@ -584,17 +583,14 @@ angular.module('myApp.controllers', ['myApp.i18n'])
} }
}); });
var prevMessages = false;
$scope.$watchCollection('search', function () { $scope.$watchCollection('search', function () {
if ($scope.search.messages != prevMessages) {
prevMessages = $scope.search.messages;
$scope.dialogs = []; $scope.dialogs = [];
loadDialogs(true); $scope.foundMessages = [];
} else { searchMessages = false;
contactsJump++;
loadDialogs(); loadDialogs();
}
if ($routeParams.q && (!$scope.search.messages || $scope.search.query != $routeParams.q)) { if ($routeParams.q && $scope.search.query != $routeParams.q) {
$timeout(function () { $timeout(function () {
$location.url( $location.url(
'/im' + '/im' +
@ -620,7 +616,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.$on('contacts_update', function () { $scope.$on('contacts_update', function () {
if (contactsShown) { if (contactsShown) {
showMoreContacts(); showMoreConversations();
} }
}); });
@ -628,13 +624,12 @@ angular.module('myApp.controllers', ['myApp.i18n'])
var searchTimeoutPromise; var searchTimeoutPromise;
function getDialogs(force) { function getDialogs(force) {
var searchMessages = $scope.search.messages && $scope.search.query.length > 0, var curJump = ++jump,
curJump = ++jump,
promise; promise;
$timeout.cancel(searchTimeoutPromise); $timeout.cancel(searchTimeoutPromise);
if (searchMessages) { if (searchMessages) {
searchTimeoutPromise = force ? $q.when() : $timeout(angular.noop, 500); searchTimeoutPromise = (force || maxID) ? $q.when() : $timeout(angular.noop, 500);
promise = searchTimeoutPromise.then(function () { promise = searchTimeoutPromise.then(function () {
return AppMessagesManager.getSearch({_: 'inputPeerEmpty'}, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID); return AppMessagesManager.getSearch({_: 'inputPeerEmpty'}, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID);
}); });
@ -686,30 +681,39 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}; };
function loadDialogs (force) { function loadDialogs (force) {
offset = 0;
maxID = 0; maxID = 0;
hasMore = false; hasMore = false;
if (!searchMessages) {
peersInDialogs = {}; peersInDialogs = {};
contactsShown = false; contactsShown = false;
}
getDialogs(force).then(function (dialogsResult) { getDialogs(force).then(function (dialogsResult) {
if (!searchMessages) {
$scope.dialogs = []; $scope.dialogs = [];
$scope.contacts = []; $scope.contacts = [];
$scope.foundUsers = []; $scope.foundUsers = [];
}
$scope.foundMessages = [];
if (dialogsResult.dialogs.length) { var dialogsList = searchMessages ? $scope.foundMessages : $scope.dialogs;
offset += dialogsResult.dialogs.length;
maxID = dialogsResult.dialogs[dialogsResult.dialogs.length - 1].top_message;
hasMore = dialogsResult.count === null || offset < dialogsResult.count;
if (dialogsResult.dialogs.length) {
angular.forEach(dialogsResult.dialogs, function (dialog) { angular.forEach(dialogsResult.dialogs, function (dialog) {
peersInDialogs[dialog.peerID] = true;
var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count); var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, dialog.unread_count);
$scope.dialogs.push(wrappedDialog); 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;
if (!searchMessages) {
delete $scope.isEmpty.dialogs; delete $scope.isEmpty.dialogs;
} }
}
$scope.$broadcast('ui_dialogs_change'); $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; contactsShown = true;
var curJump = ++jump; var curJump = ++contactsJump;
AppUsersManager.getContacts($scope.search.query).then(function (contactsList) { AppUsersManager.getContacts($scope.search.query).then(function (contactsList) {
if (curJump != jump) return; if (curJump != contactsJump) return;
$scope.contacts = []; $scope.contacts = [];
angular.forEach(contactsList, function(userID) { angular.forEach(contactsList, function(userID) {
if (peersInDialogs[userID] === undefined) { if (peersInDialogs[userID] === undefined) {
@ -753,10 +787,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
if ($scope.search.query && $scope.search.query.length >= 5) { if ($scope.search.query && $scope.search.query.length >= 5) {
$timeout(function() { $timeout(function() {
if (curJump != jump) return; if (curJump != contactsJump) return;
MtpApiManager.invokeApi('contacts.search', {q: $scope.search.query, limit: 10}).then(function (result) { MtpApiManager.invokeApi('contacts.search', {q: $scope.search.query, limit: 10}).then(function (result) {
AppUsersManager.saveApiUsers(result.users); AppUsersManager.saveApiUsers(result.users);
if (curJump != jump) return; if (curJump != contactsJump) return;
$scope.foundUsers = []; $scope.foundUsers = [];
angular.forEach(result.results, function(contactFound) { angular.forEach(result.results, function(contactFound) {
var userID = contactFound.user_id; var userID = contactFound.user_id;
@ -775,33 +809,12 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}); });
}, 500); }, 500);
} }
}
function showMoreDialogs () { if ($scope.search.query) {
if (contactsShown && (!hasMore || !offset)) { searchMessages = true;
return; loadDialogs();
}
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');
} }
});
};
}) })

5
app/js/lib/config.js

File diff suppressed because one or more lines are too long

23
app/js/lib/ng_utils.js

@ -736,16 +736,7 @@ angular.module('izhukov.utils', [])
.service('SearchIndexManager', function () { .service('SearchIndexManager', function () {
var badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<\s]+/g, var badCharsRe = /[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<\s]+/g,
trimRe = /^\s+|\s$/g, trimRe = /^\s+|\s$/g;
accentsReplace = {
a: /[åáâäà]/g,
e: /[éêëè]/g,
i: /[íîïì]/g,
o: /[óôöò]/g,
u: /[úûüù]/g,
c: /ç/g,
ss: /ß/g
}
return { return {
createIndex: createIndex, createIndex: createIndex,
@ -762,13 +753,11 @@ angular.module('izhukov.utils', [])
} }
function cleanSearchText (text) { function cleanSearchText (text) {
text = text.replace(badCharsRe, ' ').replace(trimRe, '').toLowerCase(); text = text.replace(badCharsRe, ' ').replace(trimRe, '');
text = text.replace(/[^A-Za-z0-9]/g, function (ch) {
for (var key in accentsReplace) { return Config.LatinizeMap[ch] || ch;
if (accentsReplace.hasOwnProperty(key)) { });
text = text.replace(accentsReplace[key], key); text = text.toLowerCase();
}
}
return text; return text;
} }

26
app/partials/desktop/im.html

@ -12,13 +12,6 @@
<i class="icon icon-search-clear"></i> <i class="icon icon-search-clear"></i>
</a> </a>
</div> </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>
<div my-dialogs-list class="im_dialogs_col"> <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> <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>
<div ng-switch="search.messages"> <ul class="nav nav-pills nav-stacked">
<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 &amp;&amp; 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> <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> </ul>
</div>
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages &amp;&amp; contacts.length > 0"> <div class="im_dialogs_contacts_wrap" ng-show="contacts.length > 0">
<h5 my-i18n="im_contacts_title"></h5> <h5 my-i18n="im_contacts_title"></h5>
<ul class="nav nav-pills nav-stacked"> <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}"> <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)"> <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_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_message_wrap">
<div class="im_dialog_peer"> <div class="im_dialog_peer">
<span class="im_dialog_user" my-user-link="contact.userID"></span> <span class="im_dialog_user" my-user-link="contact.userID"></span>
@ -61,7 +48,7 @@
</ul> </ul>
</div> </div>
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages &amp;&amp; foundUsers.length > 0"> <div class="im_dialogs_contacts_wrap" ng-show="foundUsers.length > 0">
<h5 my-i18n="im_found_title"></h5> <h5 my-i18n="im_found_title"></h5>
<ul class="nav nav-pills nav-stacked"> <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}"> <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> </ul>
</div> </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 &amp;&amp; curDialog.messageID == dialogMessage.id}"></li>
</ul>
</div>
</div> </div>
</div> </div>
</div> </div>

29
app/partials/mobile/im.html

@ -12,13 +12,6 @@
<i class="icon icon-search-clear"></i> <i class="icon icon-search-clear"></i>
</a> </a>
</div> </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>
<div my-dialogs-list-mobile class="im_dialogs_col im_dialogs_scrollable_wrap mobile_scrollable_wrap"> <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> <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>
<div ng-switch="search.messages"> <ul class="nav nav-pills nav-stacked">
<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 &amp;&amp; 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> <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> </ul>
</div>
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages &amp;&amp; contacts.length > 0"> <div class="im_dialogs_contacts_wrap" ng-show="contacts.length > 0">
<h5 my-i18n="im_contacts_title"></h5> <h5 my-i18n="im_contacts_title"></h5>
<ul class="nav nav-pills nav-stacked"> <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}"> <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)"> <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_message_wrap">
<div class="im_dialog_peer"> <div class="im_dialog_peer">
<span class="im_dialog_user" my-user-link="contact.userID"></span> <span class="im_dialog_user" my-user-link="contact.userID"></span>
@ -58,12 +46,12 @@
</ul> </ul>
</div> </div>
<div class="im_dialogs_contacts_wrap" ng-show="!search.messages &amp;&amp; foundUsers.length > 0"> <div class="im_dialogs_contacts_wrap" ng-show="foundUsers.length > 0">
<h5 my-i18n="im_found_title"></h5> <h5 my-i18n="im_found_title"></h5>
<ul class="nav nav-pills nav-stacked"> <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}"> <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)"> <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_message_wrap">
<div class="im_dialog_peer"> <div class="im_dialog_peer">
<span class="im_dialog_user" my-user-link="foundUser.userID"></span> <span class="im_dialog_user" my-user-link="foundUser.userID"></span>
@ -78,6 +66,13 @@
</ul> </ul>
</div> </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 &amp;&amp; curDialog.messageID == dialogMessage.id}"></li>
</ul>
</div>
</div> </div>
</div> </div>

Loading…
Cancel
Save