mirror of https://github.com/zulip/zulip.git
Add pm_perma_link helper.
This commit is contained in:
parent
8c49985058
commit
adf616d3f1
|
@ -403,6 +403,7 @@ run_test('message_methods', () => {
|
|||
sender_id: charles.user_id,
|
||||
};
|
||||
assert.equal(people.pm_with_url(message), '#narrow/pm-with/451,452-group');
|
||||
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30,451,452-group');
|
||||
assert.equal(people.pm_reply_to(message),
|
||||
'Athens@example.com,charles@example.com');
|
||||
assert.equal(people.small_avatar_url(message),
|
||||
|
@ -417,6 +418,7 @@ run_test('message_methods', () => {
|
|||
avatar_url: 'legacy.png',
|
||||
};
|
||||
assert.equal(people.pm_with_url(message), '#narrow/pm-with/452-athens');
|
||||
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30,452-pm');
|
||||
assert.equal(people.pm_reply_to(message),
|
||||
'Athens@example.com');
|
||||
assert.equal(people.small_avatar_url(message),
|
||||
|
@ -446,9 +448,11 @@ run_test('message_methods', () => {
|
|||
],
|
||||
};
|
||||
assert.equal(people.pm_with_url(message), '#narrow/pm-with/30-me');
|
||||
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30-pm');
|
||||
|
||||
message = { type: 'stream' };
|
||||
assert.equal(people.pm_with_user_ids(message), undefined);
|
||||
assert.equal(people.all_user_ids_in_pm(message), undefined);
|
||||
|
||||
// Test undefined user_ids
|
||||
assert.equal(people.pm_reply_to(message), undefined);
|
||||
|
|
|
@ -82,7 +82,9 @@ run_test('blueslip', () => {
|
|||
blueslip.set_test_data('error', 'Empty recipient list in message');
|
||||
people.pm_with_user_ids(message);
|
||||
people.group_pm_with_user_ids(message);
|
||||
assert.equal(blueslip.get_test_logs('error').length, 2);
|
||||
people.all_user_ids_in_pm(message);
|
||||
assert.equal(people.pm_perma_link(message), undefined);
|
||||
assert.equal(blueslip.get_test_logs('error').length, 4);
|
||||
blueslip.clear_test_data();
|
||||
|
||||
var charles = {
|
||||
|
|
|
@ -341,6 +341,24 @@ exports.pm_lookup_key = function (user_ids_string) {
|
|||
return user_ids.join(',');
|
||||
};
|
||||
|
||||
exports.all_user_ids_in_pm = function (message) {
|
||||
if (message.type !== 'private') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.display_recipient.length === 0) {
|
||||
blueslip.error('Empty recipient list in message');
|
||||
return;
|
||||
}
|
||||
|
||||
var user_ids = _.map(message.display_recipient, function (elem) {
|
||||
return elem.user_id || elem.id;
|
||||
});
|
||||
|
||||
user_ids = sort_numerically(user_ids);
|
||||
return user_ids;
|
||||
};
|
||||
|
||||
exports.pm_with_user_ids = function (message) {
|
||||
if (message.type !== 'private') {
|
||||
return;
|
||||
|
@ -382,6 +400,26 @@ exports.group_pm_with_user_ids = function (message) {
|
|||
return false;
|
||||
};
|
||||
|
||||
exports.pm_perma_link = function (message) {
|
||||
var user_ids = exports.all_user_ids_in_pm(message);
|
||||
|
||||
if (!user_ids) {
|
||||
return;
|
||||
}
|
||||
|
||||
var suffix;
|
||||
|
||||
if (user_ids.length >= 3) {
|
||||
suffix = 'group';
|
||||
} else {
|
||||
suffix = 'pm';
|
||||
}
|
||||
|
||||
var slug = user_ids.join(',') + '-' + suffix;
|
||||
var uri = "#narrow/pm-with/" + slug;
|
||||
return uri;
|
||||
};
|
||||
|
||||
exports.pm_with_url = function (message) {
|
||||
var user_ids = exports.pm_with_user_ids(message);
|
||||
|
||||
|
|
Loading…
Reference in New Issue