From 9faa84b0e8040bbeda6eaced501498a481f5c7d3 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Mon, 3 Jun 2024 10:42:30 -0700 Subject: [PATCH] msglist: Handle topic permalinks (/with/) just as we do /near/ links Explanation in a comment, which quotes Greg in #5866. Fixes: #5866 --- src/message/messagesActions.js | 4 +++- src/utils/internalLinks.js | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/message/messagesActions.js b/src/message/messagesActions.js index c5ea73b65ce..ea8773abe87 100644 --- a/src/message/messagesActions.js +++ b/src/message/messagesActions.js @@ -257,7 +257,9 @@ export const messageLinkPress = return; } - const nearOperand = getNearOperandFromLink(parsedUrl, auth.realm); + const nearOperand = + getNearOperandFromLink(parsedUrl, auth.realm) + ?? getNearOperandFromLink(parsedUrl, auth.realm, { actuallyWith: true }); if (!isNarrowValid(state, narrow)) { // E.g., a stream that's hidden from our user (perhaps doesn't exist). diff --git a/src/utils/internalLinks.js b/src/utils/internalLinks.js index 4b7bf55bbc2..4d6c3c35606 100644 --- a/src/utils/internalLinks.js +++ b/src/utils/internalLinks.js @@ -203,8 +203,22 @@ export const getNarrowFromNarrowLink = ( /** * From a URL and realm with `isNarrowLink(url, realm) === true`, give * message_id if the URL has /near/{message_id}, otherwise give null. + * + * HACK: to check for the new 'with' operator instead of 'near' (#5866), + * pass `actuallyWith: true`. Quoting Greg from #5866: + * > Currently the app doesn't interpret the "anchor" meaning of `/near/` + * > links at all (that's #3604) — we already effectively give `/near/` + * > links exactly the meaning that the upcoming `/with/` links will have. + * > So to handle the new links, we just need to parse them and then + * > handle them the way we already handle `/near/` links. */ -export const getNearOperandFromLink = (url: URL, realm: URL): number | null => { +export const getNearOperandFromLink = ( + url: URL, + realm: URL, + options: {| actuallyWith?: boolean |} = Object.freeze({}), +): number | null => { + const { actuallyWith = false } = options; + // isNarrowLink(…) is true, by jsdoc, so this call is OK. const hashSegments = getHashSegmentsFromNarrowLink(url, realm); @@ -217,7 +231,7 @@ export const getNearOperandFromLink = (url: URL, realm: URL): number | null => { i % 2 === 0 // The operator is 'near' and its meaning is not negated (`str` does // not start with "-"). - && str === 'near', + && str === (actuallyWith ? 'with' : 'near'), ); if (nearOperatorIndex < 0) { return null;