mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
Make nicer slugs for "sender" narrows.
Slugs are now like our "pm-with" slugs:
narrow/sender/3-cordelia
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
global.stub_out_jquery();
|
||||||
|
|
||||||
|
add_dependencies({
|
||||||
|
people: 'js/people.js',
|
||||||
|
});
|
||||||
|
|
||||||
var hashchange = require('js/hashchange.js');
|
var hashchange = require('js/hashchange.js');
|
||||||
|
|
||||||
(function test_operators_round_trip() {
|
(function test_operators_round_trip() {
|
||||||
@@ -32,3 +38,32 @@ var hashchange = require('js/hashchange.js');
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
(function test_people_slugs() {
|
||||||
|
var operators;
|
||||||
|
var hash;
|
||||||
|
var narrow;
|
||||||
|
|
||||||
|
var alice = {
|
||||||
|
email: 'alice@example.com',
|
||||||
|
user_id: 42,
|
||||||
|
full_name: 'Alice Smith',
|
||||||
|
};
|
||||||
|
|
||||||
|
people.add(alice);
|
||||||
|
operators = [
|
||||||
|
{operator: 'sender', operand: 'alice@example.com'},
|
||||||
|
];
|
||||||
|
hash = hashchange.operators_to_hash(operators);
|
||||||
|
assert.equal(hash, '#narrow/sender/42-alice');
|
||||||
|
narrow = hashchange.parse_narrow(hash.split('/'));
|
||||||
|
assert.deepEqual(narrow, [
|
||||||
|
{operator: 'sender', operand: 'alice@example.com', negated: false},
|
||||||
|
]);
|
||||||
|
|
||||||
|
operators = [
|
||||||
|
{operator: 'pm-with', operand: 'alice@example.com'},
|
||||||
|
];
|
||||||
|
hash = hashchange.operators_to_hash(operators);
|
||||||
|
assert.equal(hash, '#narrow/pm-with/42-alice');
|
||||||
|
}());
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ function set_filter(operators) {
|
|||||||
uri = narrow.huddle_with_uri("22,23");
|
uri = narrow.huddle_with_uri("22,23");
|
||||||
assert.equal(uri, '#narrow/pm-with/22,23-group');
|
assert.equal(uri, '#narrow/pm-with/22,23-group');
|
||||||
|
|
||||||
|
uri = narrow.by_sender_uri(ray.email);
|
||||||
|
assert.equal(uri, '#narrow/sender/22-ray');
|
||||||
|
|
||||||
var emails = global.hashchange.decode_operand('pm-with', '22,23-group');
|
var emails = global.hashchange.decode_operand('pm-with', '22,23-group');
|
||||||
assert.equal(emails, 'alice@example.com,ray@example.com');
|
assert.equal(emails, 'alice@example.com,ray@example.com');
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ exports.encodeHashComponent = function (str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.encode_operand = function (operator, operand) {
|
exports.encode_operand = function (operator, operand) {
|
||||||
if (operator === 'pm-with') {
|
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||||
var slug = people.emails_to_slug(operand);
|
var slug = people.emails_to_slug(operand);
|
||||||
if (slug) {
|
if (slug) {
|
||||||
return slug;
|
return slug;
|
||||||
@@ -31,7 +31,7 @@ function decodeHashComponent(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.decode_operand = function (operator, operand) {
|
exports.decode_operand = function (operator, operand) {
|
||||||
if (operator === 'pm-with') {
|
if ((operator === 'pm-with') || (operator === 'sender')) {
|
||||||
var emails = people.slug_to_emails(operand);
|
var emails = people.slug_to_emails(operand);
|
||||||
if (emails) {
|
if (emails) {
|
||||||
return emails;
|
return emails;
|
||||||
|
|||||||
@@ -598,7 +598,9 @@ exports.huddle_with_uri = function (user_ids_string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.by_sender_uri = function (reply_to) {
|
exports.by_sender_uri = function (reply_to) {
|
||||||
return "#narrow/sender/" + hashchange.encodeHashComponent(reply_to);
|
return hashchange.operators_to_hash([
|
||||||
|
{operator: 'sender', operand: reply_to},
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.by_stream_uri = function (stream) {
|
exports.by_stream_uri = function (stream) {
|
||||||
|
|||||||
Reference in New Issue
Block a user