From 7e8ce5eb540c21a30a65d764f87c23d03bd6488e Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 18 Feb 2016 17:27:57 -0800 Subject: [PATCH] Omit left groups from search Unless they contain messages. // FREEBIE --- js/models/conversations.js | 4 ++++ js/models/messages.js | 7 +++++-- js/views/conversation_search_view.js | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 7644aed3ca0c..9d17d7f6a305 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -123,6 +123,10 @@ message.send(sendFunc(this.get('id'), body, attachments, now)); }, + isSearchable: function() { + return !this.get('left') || !!this.get('lastMessage'); + }, + endSession: function() { if (this.isPrivate()) { var now = Date.now(); diff --git a/js/models/messages.js b/js/models/messages.js index 1079d5fd9548..0b386f64dfde 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -394,7 +394,10 @@ }); }, - fetchConversation: function(conversationId) { + fetchConversation: function(conversationId, limit) { + if (typeof limit !== 'number') { + limit = 100; + } return new Promise(function(resolve) { var upper; if (this.length === 0) { @@ -404,7 +407,7 @@ // not our first rodeo, fetch older messages. upper = this.at(0).get('received_at'); } - var options = {remove: false, limit: 100}; + var options = {remove: false, limit: limit}; options.index = { // 'conversation' index on [conversationId, received_at] name : 'conversation', diff --git a/js/views/conversation_search_view.js b/js/views/conversation_search_view.js index 5226e831e3b7..4dc810ada078 100644 --- a/js/views/conversation_search_view.js +++ b/js/views/conversation_search_view.js @@ -67,7 +67,11 @@ } this.pending = this.pending.then(function() { return this.typeahead.search(query).then(function() { - this.typeahead_view.collection.reset(this.typeahead.models); + this.typeahead_view.collection.reset( + this.typeahead.filter(function(m) { + return m.isSearchable(); + }) + ); }.bind(this)); }.bind(this)); this.trigger('show');