Skip to content

Commit 9e8a0d0

Browse files
chrisbobbegnprice
authored andcommitted
messagesActions [nfc]: Handle unexpected narrow links more explicitly
This should give the same behavior, just without an odd run-around in the case where isNarrowLink gives true but getNarrowFromNarrowLink gives false. Before, in that case, we'd call api.tryGetFileTemporaryUrl, which would give null because of the unexpected pathname ("/" instead of something that starts with "/user_uploads/"). We'd recognize that `null` and take the intended action, calling openLinkWithUserPreference. Refactor and add some comments; and for that case, just call openLinkWithUserPreference without going through an API method.
1 parent 761c24b commit 9e8a0d0

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/message/messagesActions.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,26 @@ export const messageLinkPress =
236236
return;
237237
}
238238

239-
const narrow = isNarrowLink(parsedUrl, auth.realm)
240-
? getNarrowFromNarrowLink(parsedUrl, auth.realm, streamsById, streamsByName, ownUserId)
241-
: null;
239+
if (isNarrowLink(parsedUrl, auth.realm)) {
240+
const narrow = getNarrowFromNarrowLink(
241+
parsedUrl,
242+
auth.realm,
243+
streamsById,
244+
streamsByName,
245+
ownUserId,
246+
);
247+
248+
if (!narrow) {
249+
// Open mobile web, because it could be a valid narrow link that web
250+
// can handle but mobile can't; our Narrow type can't represent it.
251+
//
252+
// …Could also be an invalid narrow link, or one that we *could*
253+
// parse but just haven't (e.g., operands in an unexpected order).
254+
// Opening the browser won't be ideal in those cases.
255+
openLinkWithUserPreference(parsedUrl, getGlobalSettings());
256+
return;
257+
}
242258

243-
if (narrow) {
244-
// This call is OK: `narrow` is truthy, so isNarrowLink(…) was true.
245259
const nearOperand = getNearOperandFromLink(parsedUrl, auth.realm);
246260

247261
if (!isNarrowValid(state, narrow)) {

0 commit comments

Comments
 (0)