Skip to content

Commit

Permalink
compose: Use new /dm/… link format in quote-and-reply, for recent ser…
Browse files Browse the repository at this point in the history
…vers

Fixes: zulip#5710
  • Loading branch information
chrisbobbe committed Apr 25, 2023
1 parent 2c1ca7f commit 7cbbcb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/compose/ComposeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function getQuoteAndReplyText(args: {|
user: UserOrBot,
realm: URL,
streamsById: Map<number, Stream>,
zulipFeatureLevel: number,
_: GetText,
|}): string {
// Modeled on replace_content in static/js/compose_actions.js in the
Expand All @@ -150,13 +151,13 @@ function getQuoteAndReplyText(args: {|
// message content
// ```

const { message, rawContent, user, realm, streamsById, _ } = args;
const { message, rawContent, user, realm, streamsById, zulipFeatureLevel, _ } = args;
const authorLine = _({
// Matches the web-app string
text: '{username} [said]({link_to_message}):',
values: {
username: `@_**${user.full_name}|${user.user_id}**`,
link_to_message: getMessageUrl(realm, message, streamsById).toString(),
link_to_message: getMessageUrl(realm, message, streamsById, zulipFeatureLevel).toString(),
},
});
const fence = fenced_code.get_unused_fence(rawContent);
Expand Down Expand Up @@ -439,6 +440,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
user,
realm: auth.realm,
streamsById,
zulipFeatureLevel,
_,
});
setMessageInputValue(state => state.value.replace(quotingPlaceholder, quoteAndReplyText));
Expand Down
15 changes: 11 additions & 4 deletions src/utils/internalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,19 @@ export const getStreamUrl = (
*/
// Based on pm_perma_link in static/js/people.js in the zulip/zulip repo.
// TODO(shared): Share that code.
export const getPmConversationLinkForMessage = (realm: URL, message: PmMessage | PmOutbox): URL => {
export const getPmConversationLinkForMessage = (
realm: URL,
message: PmMessage | PmOutbox,
zulipFeatureLevel: number,
): URL => {
const recipientIds = recipientsOfPrivateMessage(message)
.map(r => r.id)
.sort((a, b) => a - b);
const suffix = recipientIds.length >= 3 ? 'group' : 'pm';
const suffix = recipientIds.length >= 3 ? 'group' : zulipFeatureLevel >= 177 ? 'dm' : 'pm';
const slug = `${recipientIds.join(',')}-${suffix}`;
return new URL(`#narrow/pm-with/${slug}`, realm);
// TODO(server-7.0): Remove FL 177 condition (here and on `suffix`)
const operator = zulipFeatureLevel >= 177 ? 'dm' : 'pm-with';
return new URL(`#narrow/${operator}/${slug}`, realm);
};

/**
Expand All @@ -272,14 +278,15 @@ export const getMessageUrl = (
realm: URL,
message: Message | Outbox,
streamsById: Map<number, Stream>,
zulipFeatureLevel: number,
): URL => {
let result = undefined;

// Build the part that points to the message's conversation…
if (message.type === 'stream') {
result = getStreamTopicUrl(realm, message.stream_id, message.subject, streamsById);
} else {
result = getPmConversationLinkForMessage(realm, message);
result = getPmConversationLinkForMessage(realm, message, zulipFeatureLevel);
}

// …then add the part that points to the message.
Expand Down

0 comments on commit 7cbbcb7

Please sign in to comment.