From 01b19291e73f5bfddd48999623d581d40fe12caf Mon Sep 17 00:00:00 2001
From: Vinit Singh
Date: Wed, 14 Aug 2019 00:33:48 +0530
Subject: [PATCH] search: Advertise the ability to search shared history.
When a user performs a search that might contain historical public
streams messages that the user has access to (but doesn't because
we're searching the user's own personal history), we add a notice
above the first search result to let the user know that not all
messages may have been searched.
Fixes #12036.
---
frontend_tests/node_tests/filter.js | 3 +++
static/js/filter.js | 4 ++++
static/js/narrow.js | 9 +++++++++
static/styles/night_mode.scss | 3 ++-
static/styles/zulip.scss | 11 ++++++++++-
templates/zerver/app/home.html | 10 ++++++++++
templates/zerver/help/search-for-messages.md | 17 +++++++++++------
7 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js
index d88a1a290a..bb379c88db 100644
--- a/frontend_tests/node_tests/filter.js
+++ b/frontend_tests/node_tests/filter.js
@@ -71,6 +71,7 @@ run_test('basics', () => {
assert(filter.can_mark_messages_read());
assert(!filter.contains_only_private_messages());
assert(filter.allow_use_first_unread_when_narrowing());
+ assert(filter.includes_full_stream_history());
assert(filter.can_apply_locally());
operators = [
@@ -115,6 +116,7 @@ run_test('basics', () => {
filter = new Filter(operators);
assert(filter.has_operator('has'));
assert(!filter.can_apply_locally());
+ assert(!filter.includes_full_stream_history());
operators = [
{operator: 'streams', operand: 'public', negated: true},
@@ -133,6 +135,7 @@ run_test('basics', () => {
assert(filter.has_operator('streams'));
assert(!filter.has_negated_operand('streams', 'public'));
assert(!filter.can_apply_locally());
+ assert(filter.includes_full_stream_history());
operators = [
{operator: 'is', operand: 'private'},
diff --git a/static/js/filter.js b/static/js/filter.js
index 3215372dbd..fc9fced423 100644
--- a/static/js/filter.js
+++ b/static/js/filter.js
@@ -394,6 +394,10 @@ Filter.prototype = {
this.has_operator("pm-with") || this.has_operator("group-pm-with");
},
+ includes_full_stream_history: function () {
+ return this.has_operator("stream") || this.has_operator("streams");
+ },
+
can_apply_locally: function () {
if (this.is_search()) {
// The semantics for matching keywords are implemented
diff --git a/static/js/narrow.js b/static/js/narrow.js
index c7b828db04..c4fcb907ba 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -281,6 +281,14 @@ exports.activate = function (raw_operators, opts) {
compose.update_closed_compose_buttons_for_stream();
}
+ // Toggle the notice that lets users know that not all messages were searched.
+ if (!filter.contains_only_private_messages() &&
+ !filter.includes_full_stream_history()) {
+ $(".all-messages-search-caution").show();
+ } else {
+ $(".all-messages-search-caution").hide();
+ }
+
// Put the narrow operators in the search bar.
$('#search_query').val(Filter.unparse(operators));
search.update_button_visibility();
@@ -690,6 +698,7 @@ function handle_post_narrow_deactivate_processes() {
exports.narrow_title = "home";
notifications.redraw_title();
notifications.hide_or_show_history_limit_message(home_msg_list);
+ $(".all-messages-search-caution").hide();
}
exports.deactivate = function () {
diff --git a/static/styles/night_mode.scss b/static/styles/night_mode.scss
index d8f5362e0b..ad4aafabad 100644
--- a/static/styles/night_mode.scss
+++ b/static/styles/night_mode.scss
@@ -531,7 +531,8 @@ on a dark background, and don't change the dark labels dark either. */
stroke: hsl(0, 0%, 100%);
}
- .history-limited-box {
+ .history-limited-box,
+ .all-messages-search-caution {
background-color: hsla(0, 0%, 0%, 0.2);
}
diff --git a/static/styles/zulip.scss b/static/styles/zulip.scss
index 7d83b6fb72..b0055c145a 100644
--- a/static/styles/zulip.scss
+++ b/static/styles/zulip.scss
@@ -86,8 +86,17 @@ p.n-margin {
.history-limited-box {
color: hsl(16, 60%, 45%);
border: 1px solid hsl(16, 60%, 45%);
- border-radius: 4px;
box-shadow: 0 0 2px hsl(16, 60%, 45%);
+}
+
+.all-messages-search-caution {
+ border: 1px solid hsla(192, 19%, 75%, 0.2);
+ box-shadow: 0 0 2px hsla(192, 19%, 75%, 0.2);
+}
+
+.history-limited-box,
+.all-messages-search-caution {
+ border-radius: 4px;
display: none;
height: 28x;
font-size: 16px;
diff --git a/templates/zerver/app/home.html b/templates/zerver/app/home.html
index 4043b9986f..28125605d1 100644
--- a/templates/zerver/app/home.html
+++ b/templates/zerver/app/home.html
@@ -18,6 +18,16 @@
{% endtrans %}
+
+
+
+ {% trans %}
+ Additional results may be available if you add a stream:
+ or streams operator to your search.
+ Learn more.
+ {% endtrans %}
+
+
diff --git a/templates/zerver/help/search-for-messages.md b/templates/zerver/help/search-for-messages.md
index 7ffed051f9..a42023a3e6 100644
--- a/templates/zerver/help/search-for-messages.md
+++ b/templates/zerver/help/search-for-messages.md
@@ -68,10 +68,15 @@ keywords are ignored, we'll return 0 search results.
## Messages sent before you joined
-In most cases, Zulip only searches messages that you received. In particular,
-this means Zulip will not search messages sent before you joined.
+Zulip's [stream permissions](/help/stream-permissions) model allows
+full access to the full history of public streams and [private streams
+with shared history](/help/stream-permissions), including messages
+sent before you joined the stream (or organization) or those sent to
+public streams you are not subscribed to.
-However, if a) the search includes a `stream:` operator and b) that stream
-is either public or [private with shared history](/help/stream-permissions),
-Zulip will search the entire history of the stream, including messages
-that were sent before you joined.
+By default, Zulip searches messages in your personal history,
+i.e. the messages you actually received.
+
+If you'd like to search the organization's shared history, any query
+using the `stream:` or `streams:` operators will search all messages
+that you have access to in the selected stream(s).