Make nicer slugs for "sender" narrows.

Slugs are now like our "pm-with" slugs:

    narrow/sender/3-cordelia
This commit is contained in:
Steve Howell
2017-01-18 18:53:50 -08:00
committed by Tim Abbott
parent 1ae3feac3e
commit cd6115c24d
4 changed files with 43 additions and 3 deletions

View File

@@ -1,3 +1,9 @@
global.stub_out_jquery();
add_dependencies({
people: 'js/people.js',
});
var hashchange = require('js/hashchange.js');
(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');
}());

View File

@@ -128,6 +128,9 @@ function set_filter(operators) {
uri = narrow.huddle_with_uri("22,23");
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');
assert.equal(emails, 'alice@example.com,ray@example.com');
}());

View File

@@ -16,7 +16,7 @@ exports.encodeHashComponent = function (str) {
};
exports.encode_operand = function (operator, operand) {
if (operator === 'pm-with') {
if ((operator === 'pm-with') || (operator === 'sender')) {
var slug = people.emails_to_slug(operand);
if (slug) {
return slug;
@@ -31,7 +31,7 @@ function decodeHashComponent(str) {
}
exports.decode_operand = function (operator, operand) {
if (operator === 'pm-with') {
if ((operator === 'pm-with') || (operator === 'sender')) {
var emails = people.slug_to_emails(operand);
if (emails) {
return emails;

View File

@@ -598,7 +598,9 @@ exports.huddle_with_uri = function (user_ids_string) {
};
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) {