Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

urls: Support simple user_id-based slugs.

Steve Howellad8e79a22e44
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js
index cd35de6659d..5456cd35afb 100644
--- a/frontend_tests/node_tests/hash_util.js
+++ b/frontend_tests/node_tests/hash_util.js
@@ -12,7 +12,7 @@ set_global('location', {
});
const hamlet = {
- user_id: 1,
+ user_id: 15,
full_name: 'Hamlet',
};
@@ -49,7 +49,7 @@ run_test('hash_util', () => {
let operator = 'sender';
let operand = hamlet.email;
- encode_decode_operand(operator, operand, '1-hamlet');
+ encode_decode_operand(operator, operand, '15-hamlet');
operator = 'stream';
operand = 'frontend';
@@ -161,7 +161,7 @@ run_test('test_by_conversation_and_time_uri', () => {
};
assert.equal(hash_util.by_conversation_and_time_uri(message),
- 'https://example.com/#narrow/pm-with/1-pm/near/43');
+ 'https://example.com/#narrow/pm-with/15-pm/near/43');
});
run_test('test_search_public_streams_notice_url', () => {
@@ -181,5 +181,5 @@ run_test('test_search_public_streams_notice_url', () => {
set_uri("#narrow/sender/15");
assert.equal(hash_util.search_public_streams_notice_url(),
- "#narrow/streams/public/sender/15");
+ "#narrow/streams/public/sender/15-hamlet");
});
diff --git a/frontend_tests/node_tests/people.js b/frontend_tests/node_tests/people.js
index 69e630b8e1a..e3e5a10c22c 100644
--- a/frontend_tests/node_tests/people.js
+++ b/frontend_tests/node_tests/people.js
@@ -560,6 +560,9 @@ run_test('multi_user_methods', () => {
let emails_string = people.user_ids_string_to_emails_string('402,401');
assert.equal(emails_string, '[email protected],[email protected]');
+ emails_string = people.slug_to_emails('402,401');
+ assert.equal(emails_string, '[email protected],[email protected]');
+
emails_string = people.slug_to_emails('402,401-group');
assert.equal(emails_string, '[email protected],[email protected]');
diff --git a/static/js/people.js b/static/js/people.js
index 8a8ab05997b..93791f6848a 100644
--- a/static/js/people.js
+++ b/static/js/people.js
@@ -547,7 +547,19 @@ exports.emails_to_slug = function (emails_string) {
};
exports.slug_to_emails = function (slug) {
- const m = /^([\d,]+)-/.exec(slug);
+ /*
+ It's not super important to be flexible about
+ PM-related slugs, since you would rarely post
+ them to the web, but we we do want to support
+ reasonable variations:
+
+ 99
+
+ Our canonical version is [email protected],
+ and we only care about the "99" prefix.
+ */
+ const m = /^([\d,]+)(-.*)?/.exec(slug);
if (m) {
let user_ids_string = m[1];
user_ids_string = exports.exclude_me_from_string(user_ids_string);