forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
narrow: Add new "with" narrow operator.
This commit adds a new narrow operator -- "with" which expects a string operand of message_id, and returns all the messages in the same channel and topic of the operand, with the first unread message of the topic as anchor. This is done as an effort to provide permalinks for topics in zulip#21505.
- Loading branch information
1 parent
44fa39c
commit 0f5a750
Showing
13 changed files
with
295 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,7 @@ test("basics", () => { | |
assert.ok(!filter.is_conversation_view()); | ||
|
||
terms = [ | ||
{operator: "with", operand: 17}, | ||
{operator: "channel", operand: "foo"}, | ||
{operator: "topic", operand: "bar"}, | ||
{operator: "search", operand: "pizza"}, | ||
|
@@ -167,6 +168,7 @@ test("basics", () => { | |
{operator: "channel", operand: "foo"}, | ||
{operator: "topic", operand: "bar"}, | ||
{operator: "near", operand: 17}, | ||
{operator: "with", operand: 17}, | ||
]; | ||
filter = new Filter(terms); | ||
|
||
|
@@ -179,8 +181,16 @@ test("basics", () => { | |
assert.ok(!filter.is_personal_filter()); | ||
assert.ok(filter.can_bucket_by("channel")); | ||
assert.ok(filter.can_bucket_by("channel", "topic")); | ||
assert.ok(filter.can_bucket_by("channel", "topic", "with")); | ||
assert.ok(!filter.is_conversation_view()); | ||
|
||
terms = [ | ||
{operator: "channel", operand: "foo"}, | ||
{operator: "with", operand: 17}, | ||
]; | ||
filter = new Filter(terms); | ||
assert.ok(filter.can_bucket_by("channel", "with")); | ||
|
||
// If our only channel operator is negated, then for all intents and purposes, | ||
// we don't consider ourselves to have a channel operator, because we don't | ||
// want to have the channel in the tab bar or unsubscribe messaging, etc. | ||
|
@@ -753,7 +763,7 @@ test("canonicalization", () => { | |
assert.equal(term.operand, "link"); | ||
}); | ||
|
||
test("predicate_basics", () => { | ||
test("predicate_basics", ({override}) => { | ||
// Predicates are functions that accept a message object with the message | ||
// attributes (not content), and return true if the message belongs in a | ||
// given narrow. If the narrow parameters include a search, the predicate | ||
|
@@ -769,6 +779,8 @@ test("predicate_basics", () => { | |
["topic", "Bar"], | ||
]); | ||
|
||
override(message_store, "get", () => ({type: stream_message, stream_id, topic: "bar"})); | ||
|
||
assert.ok(predicate({type: stream_message, stream_id, topic: "bar"})); | ||
assert.ok(!predicate({type: stream_message, stream_id, topic: "whatever"})); | ||
// 9999999 doesn't exist, testing no match | ||
|
@@ -844,6 +856,10 @@ test("predicate_basics", () => { | |
predicate = get_predicate([["near", 5]]); | ||
assert.ok(predicate({})); | ||
|
||
predicate = get_predicate([["with", 5]]); | ||
assert.ok(predicate({type: stream_message, stream_id, topic: "bar"})); | ||
assert.ok(!predicate({type: direct_message, stream_id, topic: "bar"})); | ||
|
||
predicate = get_predicate([["id", 5]]); | ||
assert.ok(predicate({id: 5})); | ||
assert.ok(!predicate({id: 6})); | ||
|
@@ -1251,6 +1267,10 @@ test("unparse", () => { | |
string = "near:150"; | ||
assert.deepEqual(Filter.unparse(terms), string); | ||
|
||
terms = [{operator: "with", operand: 150}]; | ||
string = "with:150"; | ||
assert.deepEqual(Filter.unparse(terms), string); | ||
|
||
terms = [{operator: "", operand: ""}]; | ||
string = ""; | ||
assert.deepEqual(Filter.unparse(terms), string); | ||
|
@@ -1335,6 +1355,10 @@ test("describe", ({mock_template}) => { | |
string = "unknown operator"; | ||
assert.equal(Filter.search_description_as_html(narrow), string); | ||
|
||
narrow = [{operator: "with", operand: "12"}]; | ||
string = "Thread with Message 12"; | ||
assert.equal(Filter.search_description_as_html(narrow), string); | ||
|
||
narrow = [ | ||
{operator: "channel", operand: "devel"}, | ||
{operator: "topic", operand: "JS", negated: true}, | ||
|
@@ -1501,6 +1525,8 @@ test("term_type", () => { | |
["dm", "near", "is-unread", "has-link"], | ||
); | ||
|
||
assert_term_sort(["topic", "channel", "with"], ["channel", "topic", "with"]); | ||
|
||
assert_term_sort(["bogus", "channel", "topic"], ["channel", "topic", "bogus"]); | ||
assert_term_sort(["channel", "topic", "channel"], ["channel", "channel", "topic"]); | ||
|
||
|
@@ -1592,6 +1618,12 @@ function make_web_public_sub(name, stream_id) { | |
} | ||
|
||
test("navbar_helpers", () => { | ||
const sub = { | ||
name: "Foo", | ||
stream_id: 12, | ||
}; | ||
stream_data.add_sub(sub); | ||
|
||
const stream_id = 43; | ||
make_sub("Foo", stream_id); | ||
|
||
|
@@ -1696,6 +1728,12 @@ test("navbar_helpers", () => { | |
{operator: "dm", operand: "[email protected]"}, | ||
{operator: "near", operand: "12"}, | ||
]; | ||
const channel_with = [ | ||
{operator: "channel", operand: "foo"}, | ||
{operator: "topic", operand: "bar"}, | ||
{operator: "with", operand: "12"}, | ||
]; | ||
const with_op = [{operator: "with", operand: "11"}]; | ||
|
||
const test_cases = [ | ||
{ | ||
|
@@ -1876,6 +1914,20 @@ test("navbar_helpers", () => { | |
title: properly_separated_names([joe.full_name]), | ||
redirect_url_with_search: "#", | ||
}, | ||
{ | ||
terms: with_op, | ||
is_common_narrow: true, | ||
icon: undefined, | ||
title: undefined, | ||
redirect_url_with_search: "#", | ||
}, | ||
{ | ||
terms: channel_with, | ||
is_common_narrow: true, | ||
zulip_icon: "hashtag", | ||
title: "Foo", | ||
redirect_url_with_search: "#", | ||
}, | ||
]; | ||
|
||
realm.realm_enable_guest_user_indicator = true; | ||
|
Oops, something went wrong.