Skip to content

Commit

Permalink
msglist: Handle topic permalinks (/with/<id>) just as we do /near/ links
Browse files Browse the repository at this point in the history
Explanation in a comment, which quotes Greg in zulip#5866.

Fixes: zulip#5866
  • Loading branch information
chrisbobbe committed Jun 3, 2024
1 parent 6d5d56d commit 9faa84b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/message/messagesActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
18 changes: 16 additions & 2 deletions src/utils/internalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 9faa84b

Please sign in to comment.