@@ -36,7 +36,7 @@ export opaque type Narrow =
36
36
| { | type : 'stream' , streamId : number | }
37
37
| { | type : 'topic' , streamId : number , topic : string | }
38
38
| { | type : 'pm' , userIds : PmKeyRecipients | }
39
- | { | type : 'search' , query : string | }
39
+ | { | type : 'search' , query : string , streamId ?: number | }
40
40
| { | type : 'all' | 'starred' | 'mentioned' | 'all-pm' | } ;
41
41
42
42
export const HOME_NARROW : Narrow = Object . freeze ( { type : 'all' } ) ;
@@ -153,7 +153,8 @@ export const streamNarrow = (streamId: number): Narrow =>
153
153
export const topicNarrow = ( streamId : number , topic : string ) : Narrow =>
154
154
Object . freeze ( { type : 'topic' , streamId, topic } ) ;
155
155
156
- export const SEARCH_NARROW = ( query : string ) : Narrow => Object . freeze ( { type : 'search' , query } ) ;
156
+ export const SEARCH_NARROW = ( query : string , streamId ? : number ) : Narrow =>
157
+ Object . freeze ( { type : 'search' , query, streamId } ) ;
157
158
158
159
type NarrowCases < T > = { |
159
160
home : ( ) => T ,
@@ -163,7 +164,7 @@ type NarrowCases<T> = {|
163
164
allPrivate : ( ) => T ,
164
165
stream : ( streamId : number ) => T ,
165
166
topic : ( streamId : number , topic : string ) => T ,
166
- search : ( query : string ) => T ,
167
+ search : ( query : string , streamId ? : number ) => T ,
167
168
| } ;
168
169
169
170
/* prettier-ignore */
@@ -176,7 +177,7 @@ export function caseNarrow<T>(narrow: Narrow, cases: NarrowCases<T>): T {
176
177
case 'stream ': return cases . stream ( narrow . streamId ) ;
177
178
case 'topic' : return cases . topic ( narrow . streamId , narrow . topic ) ;
178
179
case 'pm' : return cases . pm ( narrow . userIds ) ;
179
- case 'search' : return cases . search ( narrow . query ) ;
180
+ case 'search' : return cases . search ( narrow . query , narrow . streamId ) ;
180
181
case 'all' : return cases . home ( ) ;
181
182
case 'starred' : return cases . starred ( ) ;
182
183
case 'mentioned' : return cases . mentioned ( ) ;
@@ -437,7 +438,18 @@ export const apiNarrowOfNarrow = (
437
438
// TODO(server-2.1): just send IDs instead
438
439
return [ { operator : 'pm-with' , operand : emails . join ( ',' ) } ] ;
439
440
} ,
440
- search : query => [ { operator : 'search' , operand : query } ] ,
441
+ // The search narrow can behave in two ways,
442
+ // one where there is no filters, so the user can search a message in all the streams
443
+ // the second where the user wants to search in a particular stream
444
+ // Below we are checking if the streamId is mentioned or not
445
+ // If it is mentioned, it will construct a narrow based on that.
446
+ search : ( query , streamId ) =>
447
+ streamId !== undefined
448
+ ? [
449
+ { operator : 'search' , operand : query } ,
450
+ { operator : 'stream' , operand : streamId } ,
451
+ ]
452
+ : [ { operator : 'search' , operand : query } ] ,
441
453
home : ( ) => [ ] ,
442
454
starred : ( ) => [ { operator : 'is' , operand : 'starred' } ] ,
443
455
mentioned : ( ) => [ { operator : 'is' , operand : 'mentioned' } ] ,
0 commit comments