@@ -66,27 +66,24 @@ export const decodeHashComponent = (string: string): string => {
66
66
} ;
67
67
68
68
/**
69
- * Parse the operand of a `stream` operator.
69
+ * Parse the operand of a `stream` operator, returning a stream ID .
70
70
*
71
71
* Return null if the operand doesn't match any known stream.
72
72
*/
73
- const parseStreamOperand = ( operand , streamsById , streamsByName ) : null | Stream => {
73
+ const parseStreamOperand = ( operand , streamsById , streamsByName ) : null | number => {
74
74
// "New" (2018) format: ${stream_id}-${stream_name} .
75
75
const match = / ^ ( [ \d ] + ) (?: - .* ) ? $ / . exec ( operand ) ;
76
76
const newFormatStreamId = match ? parseInt ( match [ 1 ] , 10 ) : null ;
77
- if ( newFormatStreamId != null ) {
78
- const stream = streamsById . get ( newFormatStreamId ) ;
79
- if ( stream ) {
80
- return stream ;
81
- }
77
+ if ( newFormatStreamId != null && streamsById . has ( newFormatStreamId ) ) {
78
+ return newFormatStreamId ;
82
79
}
83
80
84
81
// Old format: just stream name. This case is relevant indefinitely,
85
82
// so that links in old conversations continue to work.
86
83
const streamName = decodeHashComponent ( operand ) ;
87
84
const stream = streamsByName . get ( streamName ) ;
88
85
if ( stream ) {
89
- return stream ;
86
+ return stream . stream_id ;
90
87
}
91
88
92
89
// Not any stream we know. (Most likely this means a stream the user
@@ -142,13 +139,13 @@ export const getNarrowFromLink = (
142
139
&& hashSegments [ 0 ] === 'stream'
143
140
&& ( hashSegments [ 2 ] === 'subject' || hashSegments [ 2 ] === 'topic' )
144
141
) {
145
- const stream = parseStreamOperand ( hashSegments [ 1 ] , streamsById , streamsByName ) ;
146
- return stream && topicNarrow ( stream . stream_id , parseTopicOperand ( hashSegments [ 3 ] ) ) ;
142
+ const streamId = parseStreamOperand ( hashSegments [ 1 ] , streamsById , streamsByName ) ;
143
+ return streamId != null ? topicNarrow ( streamId , parseTopicOperand ( hashSegments [ 3 ] ) ) : null ;
147
144
}
148
145
149
146
if ( hashSegments . length === 2 && hashSegments [ 0 ] === 'stream' ) {
150
- const stream = parseStreamOperand ( hashSegments [ 1 ] , streamsById , streamsByName ) ;
151
- return stream && streamNarrow ( stream . stream_id ) ;
147
+ const streamId = parseStreamOperand ( hashSegments [ 1 ] , streamsById , streamsByName ) ;
148
+ return streamId != null ? streamNarrow ( streamId ) : null ;
152
149
}
153
150
154
151
if (
0 commit comments