`,
);
});
run_test("urls", () => {
people.add_active_user(ray, "server_events");
people.add_active_user(alice, "server_events");
people.add_active_user(me, "server_events");
people.initialize_current_user(me.user_id);
let url = hash_util.pm_with_url(ray.user_id.toString());
assert.equal(url, "#narrow/dm/22-Raymond");
url = hash_util.direct_message_group_with_url("22,23");
assert.equal(url, "#narrow/dm/22,23-group");
url = hash_util.by_sender_url(ray.user_id);
assert.equal(url, "#narrow/sender/22-Raymond");
let user_ids = hash_util.decode_operand("dm", "22,23-group");
assert.deepEqual(user_ids, [22, 23]);
user_ids = hash_util.decode_operand("dm", "5,22,23-group");
assert.deepEqual(user_ids, [22, 23]);
user_ids = hash_util.decode_operand("dm", "5-group");
assert.deepEqual(user_ids, [5]);
});
run_test("show_empty_narrow_message", ({mock_template, override, override_rewire}) => {
settings_data.user_can_access_all_other_users = () => true;
settings_data.user_has_permission_for_group_setting = () => true;
override(realm, "stop_words", []);
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
// for empty combined feed
let current_filter = new Filter([{operator: "in", operand: "home"}]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages in your combined feed.",
undefined,
'translated: Would you like to view messages in all public channels?',
),
);
// for non-existent or private stream
current_filter = set_filter([["stream", "999"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: This channel doesn't exist, or you are not allowed to view it.",
),
);
current_filter = set_filter([
["stream", "999"],
["topic", "foo"],
["near", "99"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: This channel doesn't exist, or you are not allowed to view it.",
),
);
// for non-subbed public stream
const rome_id = 99;
stream_data.add_sub_for_tests(
make_stream({name: "ROME", subscribed: false, stream_id: rome_id}),
);
current_filter = set_filter([["stream", rome_id.toString()]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
undefined,
'translated: Why not start the conversation?',
),
);
// for non-web-public stream for spectator
page_params.is_spectator = true;
current_filter = set_filter([["stream", rome_id.toString()]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"",
undefined,
'translated: This is not a publicly accessible conversation.',
),
);
current_filter = set_filter([
["stream", rome_id.toString()],
["topic", "foo"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"",
undefined,
'translated: This is not a publicly accessible conversation.',
),
);
// for web-public stream for spectator
const web_public_id = 1231;
stream_data.add_sub_for_tests(
make_stream({
name: "web-public-stream",
stream_id: web_public_id,
is_web_public: true,
}),
);
current_filter = set_filter([
["stream", web_public_id.toString()],
["topic", "foo"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: There are no messages here."),
);
page_params.is_spectator = false;
current_filter = set_filter([["is", "starred"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no starred messages.",
undefined,
'translated: Starring messages is a good way to keep track of important messages, such as tasks you need to go back to, or useful references. To star a message, hover over a message and click the . Learn more',
),
);
current_filter = set_filter([["is", "mentioned"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: This view will show messages where you are mentioned.",
undefined,
'translated: To call attention to a message, you can mention a user, a group, topic participants, or all subscribers to a channel. Type @ in the compose box, and choose who you\'d like to mention from the list of suggestions. Learn more',
),
);
override(realm, "realm_direct_message_permission_group", everyone.id);
override(realm, "realm_direct_message_initiator_group", everyone.id);
current_filter = set_filter([["is", "dm"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages yet!",
undefined,
'translated: Why not start the conversation?',
),
);
current_filter = set_filter([["is", "unread"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no unread messages!"),
);
current_filter = set_filter([["is", "resolved"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
undefined,
`translated: No topics in your history are marked as resolved.`,
undefined,
undefined,
true,
),
);
current_filter = set_filter([["is", "followed"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You aren't following any topics."),
);
current_filter = set_filter([["is", "muted"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no messages in muted topics and channels."),
);
current_filter = set_filter([["is", "alerted"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
undefined,
`translated: No search results from your message history.`,
),
);
// organization has disabled sending direct messages
override(realm, "realm_direct_message_permission_group", nobody.id);
// prioritize information about invalid user(s) in narrow/search
current_filter = set_filter([["dm", [-1]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
current_filter = set_filter([["dm", [9999, alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: One or more of these users do not exist!"),
);
current_filter = set_filter([["dm", [alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: Direct messages are disabled in this organization.",
undefined,
'translated: Learn more.',
),
);
// direct messages with a bot are possible even though
// the organization has disabled sending direct messages
people.add_active_user(bot, "server_events");
current_filter = set_filter([["dm", [bot.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with Example Bot yet.",
undefined,
'translated: Why not start the conversation?',
),
);
// group direct messages with bots are not possible when
// sending direct messages is disabled
current_filter = set_filter([["dm", [bot.user_id, alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: Direct messages are disabled in this organization.",
undefined,
'translated: Learn more.',
),
);
// sending direct messages enabled
override(realm, "realm_direct_message_permission_group", everyone.id);
current_filter = set_filter([["dm", [alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with Alice Smith yet.",
undefined,
'translated: Why not start the conversation?',
),
);
// sending direct messages to deactivated user
override(realm, "realm_direct_message_permission_group", everyone.id);
people.deactivate(alice);
current_filter = set_filter([["dm", [alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages with Alice Smith."),
);
people.add_active_user(alice);
people.add_active_user(me);
people.initialize_current_user(me.user_id);
current_filter = set_filter([["dm", [me.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You haven't sent yourself any notes yet!",
undefined,
"translated: Use this space for personal notes, or to test out Zulip features.",
),
);
current_filter = set_filter([["dm", [me.user_id, alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have no direct messages with these users yet.",
undefined,
'translated: Why not start the conversation?',
),
);
// group dm with a deactivated user
people.deactivate(alice);
current_filter = set_filter([["dm", [ray.user_id, alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages with these users."),
);
people.add_active_user(alice);
// organization has disabled sending direct messages
override(realm, "realm_direct_message_permission_group", nobody.id);
// prioritize information about invalid user in narrow/search
current_filter = set_filter([["dm-including", [-1]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
current_filter = set_filter([["dm-including", [9999, 88888]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: One or more of these users do not exist!"),
);
current_filter = set_filter([["dm-including", [alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: Direct messages are disabled in this organization.",
undefined,
'translated: Learn more.',
),
);
// direct messages with a bot are possible even though
// the organization has disabled sending direct messages
current_filter = set_filter([["dm-including", [bot.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages including Example Bot yet."),
);
// sending direct messages enabled
override(realm, "realm_direct_message_permission_group", everyone.id);
override(realm, "realm_direct_message_permission_group", everyone.id);
current_filter = set_filter([["dm-including", [alice.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You have no direct messages including Alice Smith yet."),
);
current_filter = set_filter([["dm-including", [me.user_id]]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: You don't have any direct message conversations yet."),
);
current_filter = set_filter([["sender", ray.user_id]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You haven't received any messages sent by Raymond yet.",
undefined,
undefined,
undefined,
true,
),
);
current_filter = set_filter([["sender", 9999]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: This user doesn't exist, or you are not allowed to view any of their messages.",
),
);
current_filter = set_filter([
["sender", alice.user_id],
["stream", rome_id.toString()],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: No search results."),
);
current_filter = set_filter([["mentions", alice.user_id]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No messages in your message history mention Alice Smith yet.",
'translated: No messages in your message history mention Alice Smith yet.',
undefined,
undefined,
true,
),
);
current_filter = set_filter([["mentions", -1]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: This user does not exist!"),
);
current_filter = set_filter([["is", "invalid"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
undefined,
'translated: Why not start the conversation?',
),
);
const my_stream_id = 103;
const my_stream = make_stream({
name: "my stream",
stream_id: my_stream_id,
});
stream_data.add_sub_for_tests(my_stream);
override_rewire(stream_data, "set_max_channel_width_css_variable", noop);
stream_data.subscribe_myself(my_stream);
current_filter = set_filter([["stream", my_stream_id.toString()]]);
const list = new MessageList({
data: new MessageListData({
excludes_muted_topics: false,
filter: current_filter,
}),
});
message_lists.current = list;
message_lists.current.visibly_empty = () => true;
// There are muted topics in the channel.
message_lists.current.empty = () => false;
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You have muted all the topics in this channel.",
undefined,
'translated: To view a muted topic, click show all topics in the left sidebar, and select one from the list. Learn more',
),
);
// There are no muted topics in the channel.
message_lists.current.empty = () => true;
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: There are no messages here.",
undefined,
'translated: Why not start the conversation?',
),
);
// The channel does not exist.
current_filter = set_filter([["stream", ""]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: This channel doesn't exist, or you are not allowed to view it.",
),
);
current_filter = set_filter([["has", "images"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
undefined,
`translated: No search results from your message history.`,
undefined,
undefined,
true,
),
);
current_filter = set_filter([
["has", "reaction"],
["sender", me.user_id],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: None of your messages have emoji reactions yet.",
undefined,
'translated: Learn more about emoji reactions here.',
),
);
// The channel is private, and the user cannot subscribe (e.g., they
// have access to channel metadata, but don't have content access).
const private_sub = make_stream({
stream_id: 101,
name: "private",
subscribed: false,
invite_only: true,
});
stream_data.add_sub_for_tests(private_sub);
settings_data.user_has_permission_for_group_setting = () => false;
current_filter = set_filter([["stream", private_sub.stream_id.toString()]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: You are not allowed to view messages in this private channel.",
),
);
const channels_operands = ["archived", "public", "web-public"];
for (const operand of channels_operands) {
current_filter = set_filter([["channels", operand]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html("translated: There are no messages here."),
);
}
});
run_test("show_empty_narrow_message_with_search", ({mock_template, override}) => {
override(realm, "stop_words", []);
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
const current_filter = set_filter([["search", "grail"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
undefined,
`translated: No search results from your message history.`,
undefined,
undefined,
true,
),
);
});
run_test("hide_empty_narrow_message", () => {
narrow_banner.hide_empty_narrow_message();
assert.equal($(".empty_feed_notice").text(), "never-been-set");
});
run_test("show_search_stopwords", ({mock_template, override}) => {
override(realm, "stop_words", ["what", "about"]);
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
const expected_search_data = {
has_stop_word: true,
query_words: [
{query_word: "what", is_stop_word: true},
{query_word: "about", is_stop_word: true},
{query_word: "grail", is_stop_word: false},
],
};
let current_filter = set_filter([["search", "what about grail"]]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
undefined,
`translated: No search results from your message history.`,
undefined,
expected_search_data,
true,
),
);
const streamA_id = 88;
stream_data.add_sub_for_tests(make_stream({name: "streamA", stream_id: streamA_id}));
current_filter = set_filter([
["stream", streamA_id.toString()],
["search", "what about grail"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
undefined,
undefined,
expected_search_data,
),
);
current_filter = set_filter([
["stream", streamA_id.toString()],
["topic", "topicA"],
["search", "what about grail"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
undefined,
undefined,
expected_search_data,
),
);
// Stop word exclusion is case insensitive.
const expected_search_data_capitalization_case = {
has_stop_word: true,
query_words: [
{query_word: "What", is_stop_word: true},
{query_word: "ABOUT", is_stop_word: true},
{query_word: "Grail", is_stop_word: false},
],
};
current_filter = set_filter([
["stream", streamA_id.toString()],
["search", "What ABOUT Grail"],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
undefined,
undefined,
expected_search_data_capitalization_case,
),
);
});
run_test("show_invalid_narrow_message", ({mock_template}) => {
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
const streamA_id = 88;
const streamB_id = 77;
stream_data.add_sub_for_tests(make_stream({name: "streamA", stream_id: streamA_id}));
stream_data.add_sub_for_tests(make_stream({name: "streamB", stream_id: streamB_id}));
let current_filter = set_filter([
["stream", streamA_id.toString()],
["stream", streamB_id.toString()],
]);
narrow_banner.show_empty_narrow_message(current_filter);
assert.equal(
$(".empty_feed_notice_main").html(),
empty_narrow_html(
"translated: No search results.",
undefined,
"translated:
You are searching for messages that belong to more than one channel, which is not possible.