Skip to content

Commit 810823a

Browse files
committed
internal links [nfc]: Parse the stream ID, too
This will help us when the Narrow constructors start requiring this.
1 parent e3860ae commit 810823a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/utils/internalLinks.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ export const decodeHashComponent = (string: string): string => {
119119
};
120120

121121
/**
122-
* Parse the operand of a `stream` operator, returning a stream name.
122+
* Parse the operand of a `stream` operator, returning a stream ID and name.
123123
*
124124
* Return null if the operand doesn't match any known stream.
125125
*/
126-
const parseStreamOperand = (operand, streamsById, streamsByName): null | string => {
126+
const parseStreamOperand = (operand, streamsById, streamsByName): null | [string, number] => {
127127
// "New" (2018) format: ${stream_id}-${stream_name} .
128128
const match = /^([\d]+)(?:-.*)?$/.exec(operand);
129129
if (match) {
130-
const stream = streamsById.get(parseInt(match[1], 10));
130+
const streamId = parseInt(match[1], 10);
131+
const stream = streamsById.get(streamId);
131132
if (stream) {
132-
return stream.name;
133+
return [stream.name, streamId];
133134
}
134135
}
135136

@@ -138,7 +139,7 @@ const parseStreamOperand = (operand, streamsById, streamsByName): null | string
138139
const streamName = decodeHashComponent(operand);
139140
const stream = streamsByName.get(streamName);
140141
if (stream) {
141-
return streamName;
142+
return [streamName, stream.stream_id];
142143
}
143144

144145
return null;
@@ -181,12 +182,12 @@ export const getNarrowFromLink = (
181182
return pmNarrowFromRecipients(pmKeyRecipientsFromIds(ids, ownUserId));
182183
}
183184
case 'topic': {
184-
const streamName = parseStreamOperand(paths[1], streamsById, streamsByName);
185-
return streamName == null ? null : topicNarrow(streamName, parseTopicOperand(paths[3]));
185+
const streamNameAndId = parseStreamOperand(paths[1], streamsById, streamsByName);
186+
return streamNameAndId && topicNarrow(streamNameAndId[0], parseTopicOperand(paths[3]));
186187
}
187188
case 'stream': {
188-
const streamName = parseStreamOperand(paths[1], streamsById, streamsByName);
189-
return streamName == null ? null : streamNarrow(streamName);
189+
const streamNameAndId = parseStreamOperand(paths[1], streamsById, streamsByName);
190+
return streamNameAndId && streamNarrow(streamNameAndId[0]);
190191
}
191192
case 'special':
192193
try {

0 commit comments

Comments
 (0)