Skip to content

Commit 8e19bdb

Browse files
chrisbobbegnprice
authored andcommitted
compose: Use new /dm/… link format in quote-and-reply, for recent servers
Fixes: zulip#5710
1 parent 205f882 commit 8e19bdb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/compose/ComposeBox.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function getQuoteAndReplyText(args: {|
138138
user: UserOrBot,
139139
realm: URL,
140140
streamsById: Map<number, Stream>,
141+
zulipFeatureLevel: number,
141142
_: GetText,
142143
|}): string {
143144
// Modeled on replace_content in static/js/compose_actions.js in the
@@ -150,13 +151,13 @@ function getQuoteAndReplyText(args: {|
150151
// message content
151152
// ```
152153

153-
const { message, rawContent, user, realm, streamsById, _ } = args;
154+
const { message, rawContent, user, realm, streamsById, zulipFeatureLevel, _ } = args;
154155
const authorLine = _({
155156
// Matches the web-app string
156157
text: '{username} [said]({link_to_message}):',
157158
values: {
158159
username: `@_**${user.full_name}|${user.user_id}**`,
159-
link_to_message: getMessageUrl(realm, message, streamsById).toString(),
160+
link_to_message: getMessageUrl(realm, message, streamsById, zulipFeatureLevel).toString(),
160161
},
161162
});
162163
const fence = fenced_code.get_unused_fence(rawContent);
@@ -439,6 +440,7 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
439440
user,
440441
realm: auth.realm,
441442
streamsById,
443+
zulipFeatureLevel,
442444
_,
443445
});
444446
setMessageInputValue(state => state.value.replace(quotingPlaceholder, quoteAndReplyText));

src/utils/internalLinks.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,19 @@ export const getStreamUrl = (
256256
*/
257257
// Based on pm_perma_link in static/js/people.js in the zulip/zulip repo.
258258
// TODO(shared): Share that code.
259-
export const getPmConversationLinkForMessage = (realm: URL, message: PmMessage | PmOutbox): URL => {
259+
export const getPmConversationLinkForMessage = (
260+
realm: URL,
261+
message: PmMessage | PmOutbox,
262+
zulipFeatureLevel: number,
263+
): URL => {
260264
const recipientIds = recipientsOfPrivateMessage(message)
261265
.map(r => r.id)
262266
.sort((a, b) => a - b);
263-
const suffix = recipientIds.length >= 3 ? 'group' : 'pm';
267+
const suffix = recipientIds.length >= 3 ? 'group' : zulipFeatureLevel >= 177 ? 'dm' : 'pm';
264268
const slug = `${recipientIds.join(',')}-${suffix}`;
265-
return new URL(`#narrow/pm-with/${slug}`, realm);
269+
// TODO(server-7.0): Remove FL 177 condition (here and on `suffix`)
270+
const operator = zulipFeatureLevel >= 177 ? 'dm' : 'pm-with';
271+
return new URL(`#narrow/${operator}/${slug}`, realm);
266272
};
267273

268274
/**
@@ -272,14 +278,15 @@ export const getMessageUrl = (
272278
realm: URL,
273279
message: Message | Outbox,
274280
streamsById: Map<number, Stream>,
281+
zulipFeatureLevel: number,
275282
): URL => {
276283
let result = undefined;
277284

278285
// Build the part that points to the message's conversation…
279286
if (message.type === 'stream') {
280287
result = getStreamTopicUrl(realm, message.stream_id, message.subject, streamsById);
281288
} else {
282-
result = getPmConversationLinkForMessage(realm, message);
289+
result = getPmConversationLinkForMessage(realm, message, zulipFeatureLevel);
283290
}
284291

285292
// …then add the part that points to the message.

0 commit comments

Comments
 (0)