Browse Source

Simple search in chat history

master
Igor Zhukov 8 years ago
parent
commit
75df136a7f
  1. 50
      app/js/controllers.js
  2. 4
      app/js/directives.js
  3. 3
      app/js/locales/en-us.json
  4. 6
      app/js/messages_manager.js
  5. 18
      app/less/app.less
  6. 1
      app/partials/desktop/head.html
  7. 27
      app/partials/desktop/im.html

50
app/js/controllers.js

@ -716,6 +716,14 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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 = []

4
app/js/directives.js

@ -681,7 +681,6 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -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']) @@ -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']) @@ -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()
setTimeout(function () {
searchField.focus()
}, 0)
}, 100)
}
return cancelEvent(e)

3
app/js/locales/en-us.json

@ -311,6 +311,8 @@ @@ -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 @@ @@ -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",

6
app/js/messages_manager.js

@ -754,6 +754,12 @@ angular.module('myApp.services') @@ -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]]

18
app/less/app.less

@ -1340,6 +1340,24 @@ a.im_dialog_selected { @@ -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;

1
app/partials/desktop/head.html

@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
<li><a ng-click="toggleMedia('video')" my-i18n="head_media_video"></a></li>
<li><a ng-click="toggleMedia('documents')" my-i18n="head_media_documents"></a></li>
<li><a ng-click="toggleMedia('audio')" my-i18n="head_media_audio"></a></li>
<li><a ng-click="toggleMedia('search')" my-i18n="head_media_search"></a></li>
</ul>
</div>

27
app/partials/desktop/im.html

@ -26,6 +26,33 @@ @@ -26,6 +26,33 @@
</div>
<ul class="nav nav-pills nav-stacked">
<li class="im_dialog_wrap" ng-if="searchPeer">
<a class="im_dialog im_dialog_searchpeer disabled" ng-mousedown="setSearchPeer()">
<div class="im_dialog_meta pull-right">
<div class="im_dialog_clear_searchpeer">
<!-- <i class="icon icon-clear-searchpeer"></i> -->
<i class="icon icon-search-clear"></i>
</div>
</div>
<div class="im_dialog_photo pull-left" my-peer-photolink="searchPeer" img-class="im_dialog_photo" watch="true"></div>
<div class="im_dialog_message_wrap">
<div class="im_dialog_peer">
<span my-peer-link="searchPeer"></span>
</div>
<div class="im_dialog_message">
<span class="" my-i18n="conversation_search_peer"></span>
</div>
</div>
</a>
</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>

Loading…
Cancel
Save