@@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
2
2
import { Match , check } from 'meteor/check' ;
3
3
import s from 'underscore.string' ;
4
4
5
- import { Subscriptions , Messages } from '../../app/models' ;
5
+ import { Subscriptions , Messages , Tags } from '../../app/models' ;
6
6
import { settings } from '../../app/settings' ;
7
7
8
8
Meteor . methods ( {
@@ -38,7 +38,7 @@ Meteor.methods({
38
38
const currentUserName = user . username ;
39
39
const currentUserTimezoneOffset = user . utcOffset ;
40
40
41
- const query = { } ;
41
+ let query = { } ;
42
42
const options = {
43
43
sort : {
44
44
ts : - 1 ,
@@ -198,17 +198,26 @@ Meteor.methods({
198
198
// Query in message text
199
199
text = text . trim ( ) . replace ( / \s \s / g, ' ' ) ;
200
200
if ( text !== '' ) {
201
+ const queryTags = { } ;
201
202
if ( / ^ \/ .+ \/ [ i m x s ] * $ / . test ( text ) ) {
202
203
const r = text . split ( '/' ) ;
203
204
query . msg = {
204
205
$regex : r [ 1 ] ,
205
206
$options : r [ 2 ] ,
206
207
} ;
208
+ queryTags . name = {
209
+ $regex : r [ 1 ] ,
210
+ $options : r [ 2 ] ,
211
+ } ;
207
212
} else if ( settings . get ( 'Message_AlwaysSearchRegExp' ) ) {
208
213
query . msg = {
209
214
$regex : text ,
210
215
$options : 'i' ,
211
216
} ;
217
+ queryTags . name = {
218
+ $regex : text ,
219
+ $options : 'i' ,
220
+ } ;
212
221
} else {
213
222
query . $text = {
214
223
$search : text ,
@@ -219,6 +228,24 @@ Meteor.methods({
219
228
} ,
220
229
} ;
221
230
}
231
+
232
+ if ( Object . keys ( queryTags ) . length > 0 ) {
233
+ const tags = Tags . find ( queryTags ) . fetch ( ) ;
234
+ if ( tags . length > 0 ) {
235
+ const expressions = [ ] ;
236
+ expressions . push ( query ) ;
237
+
238
+ tags . forEach ( tag => {
239
+ const exp = { } ;
240
+ exp [ 'tags.' + tag . _id ] = { $exists : true } ;
241
+ expressions . push ( exp ) ;
242
+ } ) ;
243
+
244
+ query = {
245
+ $or : expressions ,
246
+ } ;
247
+ }
248
+ }
222
249
}
223
250
224
251
if ( Object . keys ( query ) . length > 0 ) {
0 commit comments