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 10, 2024
1 parent 12950d5 commit c752b48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/message/__tests__/messageActions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ describe('messageActions', () => {
pmNarrowFromUsersUnsafe([user1, user2]),
);
});

test('handles /with/ links', async () => {
const stream = eg.makeStream({ stream_id: 1, name: 'test' });
const user1 = eg.makeUser({ user_id: 1, full_name: 'user 1' });
const user2 = eg.makeUser({ user_id: 2, full_name: 'user 2' });
const { store } = prepare({ streams: [stream], users: [user1, user2] });

await checkLink(store, '#narrow/stream/1-test/topic/hello/with/1', topicNarrow(1, 'hello'));
await checkLink(store, '#narrow/dm/1-user-1/with/1', pmNarrowFromUsersUnsafe([user1]));
await checkLink(
store,
'#narrow/dm/1,2-group/with/1',
pmNarrowFromUsersUnsafe([user1, user2]),
);
});
});

describe('doNarrow', () => {
Expand Down
19 changes: 14 additions & 5 deletions src/utils/internalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getNarrowFromNarrowLink = (
if (
// 'dm' is new in server-7.0; means the same as 'pm-with'
(hashSegments.length === 2
// probably a /near/ link
// probably a /near/ or /with/ link
|| hashSegments.length === 4)
&& (hashSegments[0] === 'pm-with' || hashSegments[0] === 'dm')
) {
Expand All @@ -161,7 +161,7 @@ export const getNarrowFromNarrowLink = (

if (
(hashSegments.length === 4
// probably a /near/ link
// probably a /near/ or /with/ link
|| hashSegments.length === 6)
// 'channel' is new in server-9.0; means the same as 'stream'
&& (hashSegments[0] === 'stream' || hashSegments[0] === 'channel')
Expand Down Expand Up @@ -217,9 +217,18 @@ export const getNearOperandFromLink = (url: URL, realm: URL): number | null => {
(str, i) =>
// This is a segment where we expect an operator to be specified.
i % 2 === 0
// The operator is 'near' and its meaning is not negated (`str` does
// not start with "-").
&& str === 'near',
// The operator is 'near' or 'with' and its meaning is not negated
// (`str` does not start with "-").
//
// 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.
// Which makes sense for this legacy codebase.
&& (str === 'near' || str === 'with'),
);
if (nearOperatorIndex < 0) {
return null;
Expand Down

0 comments on commit c752b48

Please sign in to comment.