diff --git a/app/js/controllers.js b/app/js/controllers.js index 4b0b9c8e..105f4f60 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -716,6 +716,14 @@ angular.module('myApp.controllers', ['myApp.i18n']) }) }) + $scope.$on('history_search', function (e, peerID) { + $scope.setSearchPeer(peerID) + }) + + $scope.$on('esc_no_more', function () { + $scope.setSearchPeer(false) + }) + $scope.$on('dialogs_multiupdate', function (e, dialogsUpdated) { if ($scope.search.query !== undefined && $scope.search.query.length) { return false @@ -862,7 +870,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) $scope.$watchCollection('search', function () { $scope.dialogs = [] $scope.foundMessages = [] - searchMessages = false + searchMessages = $scope.searchPeer ? true : false contactsJump++ loadDialogs() }) @@ -877,6 +885,20 @@ angular.module('myApp.controllers', ['myApp.i18n']) PhonebookContactsService.openPhonebookImport() } + $scope.setSearchPeer = function (peerID) { + $scope.searchPeer = peerID || false + $scope.searchClear() + if (peerID) { + $scope.dialogs = [] + $scope.foundPeers = [] + searchMessages = true + $scope.toggleSearch() + } else { + searchMessages = false + } + loadDialogs(true) + } + $scope.$on('contacts_update', function () { if (contactsShown) { showMoreConversations() @@ -901,7 +923,8 @@ angular.module('myApp.controllers', ['myApp.i18n']) if (searchMessages) { searchTimeoutPromise = (force || maxID) ? $q.when() : $timeout(angular.noop, 500) return searchTimeoutPromise.then(function () { - return AppMessagesManager.getSearch(false, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID).then(function (result) { + var searchPeerID = $scope.searchPeer || false + return AppMessagesManager.getSearch(searchPeerID, $scope.search.query, {_: 'inputMessagesFilterEmpty'}, maxID).then(function (result) { if (curJump != jump) { return $q.reject() } @@ -964,6 +987,15 @@ angular.module('myApp.controllers', ['myApp.i18n']) } var wrapDialog = searchMessages ? undefined : dialog var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, wrapDialog) + + if (searchMessages && + $scope.searchPeer) { + var message = AppMessagesManager.getMessage(dialog.top_message) + if (message.fromID > 0) { + wrappedDialog.peerID = message.fromID + } + } + if (searchMessages) { wrappedDialog.unreadCount = -1 } else { @@ -1022,11 +1054,21 @@ angular.module('myApp.controllers', ['myApp.i18n']) } var wrapDialog = searchMessages ? undefined : dialog var wrappedDialog = AppMessagesManager.wrapForDialog(dialog.top_message, wrapDialog) + if (searchMessages) { wrappedDialog.unreadCount = -1 } else { peersInDialogs[dialog.peerID] = true } + + if (searchMessages && + $scope.searchPeer) { + var message = AppMessagesManager.getMessage(dialog.top_message) + if (message.fromID > 0) { + wrappedDialog.peerID = message.fromID + } + } + dialogsList.push(wrappedDialog) }) @@ -1847,6 +1889,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) } function toggleMedia (mediaType) { + if (mediaType == 'search') { + $rootScope.$broadcast('history_search', $scope.curDialog.peerID) + return + } $scope.historyFilter.mediaType = mediaType || false $scope.curDialog.messageID = false peerHistory.messages = [] diff --git a/app/js/directives.js b/app/js/directives.js index fc8e9805..8928d2ec 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -681,7 +681,6 @@ angular.module('myApp.directives', ['myApp.filters']) function link($scope, element, attrs) { var messageID = $scope.$parent.$eval(attrs.myMessageEdited) - console.log(attrs.myMessageEdited, messageID) if (checkEdited($scope, element, messageID)) { $scope.$on('message_edit', function (e, data) { var messageID = $scope.$parent.$eval(attrs.myMessageEdited) @@ -694,7 +693,6 @@ angular.module('myApp.directives', ['myApp.filters']) function checkEdited($scope, element, messageID) { var message = AppMessagesManager.getMessage(messageID) - console.warn('check edited', messageID, message.canBeEdited, message.edit_date) if (!message.canBeEdited) { $timeout(function () { $scope.$destroy() @@ -795,7 +793,9 @@ angular.module('myApp.directives', ['myApp.filters']) // Strange Chrome bug, when field doesn't get blur, but becomes inactive after location change setTimeout(function () { searchField.blur() - searchField.focus() + setTimeout(function () { + searchField.focus() + }, 0) }, 100) } return cancelEvent(e) diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index 320c5c69..594057fb 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -311,6 +311,8 @@ "conversation_media_contact": "Contact", "conversation_media_attachment": "Attachment", + "conversation_search_peer": "Search in this chat", + "conversation_group_created": "created the group", "conversation_group_renamed": "changed group name", "conversation_group_photo_updated": "changed group photo", @@ -433,6 +435,7 @@ "head_media_video": "Videos", "head_media_documents": "Files", "head_media_audio": "Voice messages", + "head_media_search": "Search", "head_about": "About", "head_clear_all": "Clear history", "head_edit": "Edit", diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index ddd4a510..b3794cda 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -754,6 +754,12 @@ angular.module('myApp.services') neededContents['messageMediaDocument'] = true neededDocType = 'voice' break + + default: + return $q.when({ + count: 0, + history: [] + }) } for (i = 0; i < historyStorage.history.length; i++) { message = messagesStorage[historyStorage.history[i]] diff --git a/app/less/app.less b/app/less/app.less index 5fb2d2a6..8496f5f6 100644 --- a/app/less/app.less +++ b/app/less/app.less @@ -1340,6 +1340,24 @@ a.im_dialog_selected { } } +.im_dialogs_scrollable_wrap a.im_dialog_searchpeer .icon-search-clear { + display: inline-block; + cursor: pointer; + pointer-events: all; +} + +.im_dialogs_scrollable_wrap { + a.im_dialog_searchpeer { + &, + &:hover, + &_selected { + background: #f3f3f3; + } + } +} + + + .im_dialog_peer { color: #222; font-weight: bold; diff --git a/app/partials/desktop/head.html b/app/partials/desktop/head.html index 3d3b8c66..ab4c5f91 100644 --- a/app/partials/desktop/head.html +++ b/app/partials/desktop/head.html @@ -49,6 +49,7 @@
  • +
  • diff --git a/app/partials/desktop/im.html b/app/partials/desktop/im.html index 4e2dbaae..6293e6a9 100644 --- a/app/partials/desktop/im.html +++ b/app/partials/desktop/im.html @@ -26,6 +26,33 @@