filter: Use stream id instead of stream name.

This commit is contained in:
evykassirer
2024-08-02 18:05:34 -07:00
committed by Tim Abbott
parent 2be181c367
commit dba1af84e0
38 changed files with 760 additions and 592 deletions

View File

@@ -38,48 +38,60 @@ const message_view = zrequire("../src/message_view");
const stream_data = zrequire("stream_data");
const {Filter} = zrequire("../src/filter");
const devel_id = 100;
const devel = {
name: "devel",
stream_id: devel_id,
color: "blue",
subscribed: true,
};
stream_data.add_sub(devel);
run_test("terms_round_trip", () => {
let terms;
let hash;
let narrow;
terms = [
{operator: "stream", operand: "devel"},
{operator: "stream", operand: devel_id.toString()},
{operator: "topic", operand: "algol"},
];
hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel/topic/algol");
assert.equal(hash, "#narrow/stream/100-devel/topic/algol");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [
{operator: "stream", operand: "devel", negated: false},
{operator: "stream", operand: devel_id.toString(), negated: false},
{operator: "topic", operand: "algol", negated: false},
]);
terms = [
{operator: "stream", operand: "devel"},
{operator: "stream", operand: devel_id.toString()},
{operator: "topic", operand: "visual c++", negated: true},
];
hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel/-topic/visual.20c.2B.2B");
assert.equal(hash, "#narrow/stream/100-devel/-topic/visual.20c.2B.2B");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [
{operator: "stream", operand: "devel", negated: false},
{operator: "stream", operand: devel_id.toString(), negated: false},
{operator: "topic", operand: "visual c++", negated: true},
]);
// test new encodings, where we have a stream id
const florida_id = 987;
const florida_stream = {
name: "Florida, USA",
stream_id: 987,
stream_id: florida_id,
};
stream_data.add_sub(florida_stream);
terms = [{operator: "stream", operand: "Florida, USA"}];
terms = [{operator: "stream", operand: florida_id.toString()}];
hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/987-Florida.2C-USA");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "stream", operand: "Florida, USA", negated: false}]);
assert.deepEqual(narrow, [
{operator: "stream", operand: florida_id.toString(), negated: false},
]);
});
run_test("stream_to_channel_rename", () => {
@@ -90,13 +102,15 @@ run_test("stream_to_channel_rename", () => {
// Confirm the URLs generated from search terms use "stream" and "streams"
// and that the new Filter has the new "channel" and "channels" operators.
terms = [{operator: "channel", operand: "devel"}];
terms = [{operator: "channel", operand: devel_id.toString()}];
hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel");
assert.equal(hash, "#narrow/stream/100-devel");
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "stream", operand: "devel", negated: false}]);
assert.deepEqual(narrow, [{operator: "stream", operand: devel_id.toString(), negated: false}]);
filter = new Filter(narrow);
assert.deepEqual(filter.terms(), [{operator: "channel", operand: "devel", negated: false}]);
assert.deepEqual(filter.terms(), [
{operator: "channel", operand: devel_id.toString(), negated: false},
]);
terms = [{operator: "channels", operand: "public"}];
hash = hash_util.search_terms_to_hash(terms);
@@ -108,23 +122,28 @@ run_test("stream_to_channel_rename", () => {
// Confirm that a narrow URL with "channel" and an enocoded stream/channel ID,
// will be decoded correctly.
const test_stream_id = 34;
const test_channel = {
name: "decode",
stream_id: 34,
stream_id: test_stream_id,
};
stream_data.add_sub(test_channel);
hash = "#narrow/channel/34-decode";
narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [{operator: "channel", operand: "decode", negated: false}]);
assert.deepEqual(narrow, [
{operator: "channel", operand: test_stream_id.toString(), negated: false},
]);
filter = new Filter(narrow);
assert.deepEqual(filter.terms(), [{operator: "channel", operand: "decode", negated: false}]);
assert.deepEqual(filter.terms(), [
{operator: "channel", operand: test_stream_id.toString(), negated: false},
]);
});
run_test("terms_trailing_slash", () => {
const hash = "#narrow/stream/devel/topic/algol/";
const hash = "#narrow/stream/100-devel/topic/algol/";
const narrow = hash_util.parse_narrow(hash.split("/"));
assert.deepEqual(narrow, [
{operator: "stream", operand: "devel", negated: false},
{operator: "stream", operand: devel_id.toString(), negated: false},
{operator: "topic", operand: "algol", negated: false},
]);
});
@@ -270,6 +289,12 @@ run_test("hash_interactions", ({override, override_rewire}) => {
]);
assert.equal(window.location.hash, "#recent");
const denmark_id = 1;
stream_data.add_sub({
subscribed: true,
name: "Denmark",
stream_id: denmark_id,
});
window.location.hash = "#narrow/stream/Denmark";
helper.clear_events();
@@ -280,7 +305,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {
"message_view.show",
]);
let terms = helper.get_narrow_terms();
assert.equal(terms[0].operand, "Denmark");
assert.equal(terms[0].operand, denmark_id.toString());
window.location.hash = "#narrow";