@@ -118,8 +118,12 @@ export const decodeHashComponent = (string: string): string => {
118
118
}
119
119
} ;
120
120
121
- /** Parse the operand of a `stream` operator, returning a stream name. */
122
- const parseStreamOperand = ( operand , streamsById ) : string => {
121
+ /**
122
+ * Parse the operand of a `stream` operator, returning a stream name.
123
+ *
124
+ * Return null if the operand doesn't match any known stream.
125
+ */
126
+ const parseStreamOperand = ( operand , streamsById , streamsByName ) : null | string => {
123
127
// "New" (2018) format: ${stream_id}-${stream_name} .
124
128
const match = / ^ ( [ \d ] + ) (?: - .* ) ? $ / . exec ( operand ) ;
125
129
if ( match ) {
@@ -131,7 +135,13 @@ const parseStreamOperand = (operand, streamsById): string => {
131
135
132
136
// Old format: just stream name. This case is relevant indefinitely,
133
137
// so that links in old conversations continue to work.
134
- return decodeHashComponent ( operand ) ;
138
+ const streamName = decodeHashComponent ( operand ) ;
139
+ const stream = streamsByName . get ( streamName ) ;
140
+ if ( stream ) {
141
+ return streamName ;
142
+ }
143
+
144
+ return null ;
135
145
} ;
136
146
137
147
/** Parse the operand of a `topic` or `subject` operator. */
@@ -154,6 +164,7 @@ export const getNarrowFromLink = (
154
164
url : string ,
155
165
realm : URL ,
156
166
streamsById : Map < number , Stream > ,
167
+ streamsByName : Map < string , Stream > ,
157
168
ownUserId : UserId ,
158
169
) : Narrow | null => {
159
170
const type = getLinkType ( url , realm ) ;
@@ -169,10 +180,14 @@ export const getNarrowFromLink = (
169
180
const ids = parsePmOperand ( paths [ 1 ] ) ;
170
181
return pmNarrowFromRecipients ( pmKeyRecipientsFromIds ( ids , ownUserId ) ) ;
171
182
}
172
- case 'topic' :
173
- return topicNarrow ( parseStreamOperand ( paths [ 1 ] , streamsById ) , parseTopicOperand ( paths [ 3 ] ) ) ;
174
- case 'stream' :
175
- return streamNarrow ( parseStreamOperand ( paths [ 1 ] , streamsById ) ) ;
183
+ case 'topic' : {
184
+ const streamName = parseStreamOperand ( paths [ 1 ] , streamsById , streamsByName ) ;
185
+ return streamName == null ? null : topicNarrow ( streamName , parseTopicOperand ( paths [ 3 ] ) ) ;
186
+ }
187
+ case 'stream' : {
188
+ const streamName = parseStreamOperand ( paths [ 1 ] , streamsById , streamsByName ) ;
189
+ return streamName == null ? null : streamNarrow ( streamName ) ;
190
+ }
176
191
case 'special' :
177
192
try {
178
193
return specialNarrow ( paths [ 1 ] ) ;
0 commit comments