mirror of https://github.com/zulip/zulip.git
narrow_state: Use `message_lists.current` to return current filter.
It doesn't make sense for us to track a separate current filter when it should just the be filter of current message list if there is one. This will reduce possible confusion in the codebase where filter returned by narrow_state is different from message_lists.current.
This commit is contained in:
parent
f630272b4c
commit
c20340a5a6
|
@ -218,7 +218,7 @@ export function try_deliver_locally(message_request, insert_new_messages) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (narrow_state.active() && !narrow_state.filter().can_apply_locally(true)) {
|
if (narrow_state.filter() !== undefined && !narrow_state.filter().can_apply_locally(true)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ export type MessageList = {
|
||||||
export let home: MessageList | undefined;
|
export let home: MessageList | undefined;
|
||||||
export let current: MessageList | undefined;
|
export let current: MessageList | undefined;
|
||||||
|
|
||||||
function set_current(msg_list: MessageList | undefined): void {
|
export function set_current(msg_list: MessageList | undefined): void {
|
||||||
// NOTE: Use update_current_message_list instead of this function.
|
// NOTE: Use update_current_message_list instead of this function.
|
||||||
current = msg_list;
|
current = msg_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,8 @@ export function activate(raw_terms, opts) {
|
||||||
or rerendering due to server-side changes.
|
or rerendering due to server-side changes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const was_narrowed_already = narrow_state.active();
|
// Use to determine if user read any unread messages in non-All Messages narrow.
|
||||||
|
const was_narrowed_already = narrow_state.filter() !== undefined;
|
||||||
|
|
||||||
// Since narrow.activate is called directly from various
|
// Since narrow.activate is called directly from various
|
||||||
// places in our code without passing through hashchange,
|
// places in our code without passing through hashchange,
|
||||||
|
@ -409,12 +410,10 @@ export function activate(raw_terms, opts) {
|
||||||
// From here on down, any calls to the narrow_state API will
|
// From here on down, any calls to the narrow_state API will
|
||||||
// reflect the upcoming narrow.
|
// reflect the upcoming narrow.
|
||||||
narrow_state.set_has_shown_message_list_view();
|
narrow_state.set_has_shown_message_list_view();
|
||||||
narrow_state.set_current_filter(filter);
|
const excludes_muted_topics = narrow_state.excludes_muted_topics(filter);
|
||||||
|
|
||||||
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
|
||||||
|
|
||||||
let msg_data = new MessageListData({
|
let msg_data = new MessageListData({
|
||||||
filter: narrow_state.filter(),
|
filter,
|
||||||
excludes_muted_topics,
|
excludes_muted_topics,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -435,7 +434,7 @@ export function activate(raw_terms, opts) {
|
||||||
// maybe_add_local_messages is likely not be contiguous with
|
// maybe_add_local_messages is likely not be contiguous with
|
||||||
// the block we're about to request from the server instead.
|
// the block we're about to request from the server instead.
|
||||||
msg_data = new MessageListData({
|
msg_data = new MessageListData({
|
||||||
filter: narrow_state.filter(),
|
filter,
|
||||||
excludes_muted_topics,
|
excludes_muted_topics,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -591,7 +590,8 @@ export function maybe_add_local_messages(opts) {
|
||||||
// - add messages into our message list from our local cache
|
// - add messages into our message list from our local cache
|
||||||
const id_info = opts.id_info;
|
const id_info = opts.id_info;
|
||||||
const msg_data = opts.msg_data;
|
const msg_data = opts.msg_data;
|
||||||
const unread_info = narrow_state.get_first_unread_info();
|
const filter = msg_data.filter;
|
||||||
|
const unread_info = narrow_state.get_first_unread_info(filter);
|
||||||
|
|
||||||
// If we don't have a specific message we're hoping to select
|
// If we don't have a specific message we're hoping to select
|
||||||
// (i.e. no `target_id`) and the narrow's filter doesn't
|
// (i.e. no `target_id`) and the narrow's filter doesn't
|
||||||
|
@ -607,7 +607,7 @@ export function maybe_add_local_messages(opts) {
|
||||||
// If we're able to render the narrow locally, we'll end up
|
// If we're able to render the narrow locally, we'll end up
|
||||||
// overwriting this value with the ID of the latest message in the
|
// overwriting this value with the ID of the latest message in the
|
||||||
// narrow later in this function.
|
// narrow later in this function.
|
||||||
if (!id_info.target_id && !narrow_state.filter().allow_use_first_unread_when_narrowing()) {
|
if (!id_info.target_id && !filter.allow_use_first_unread_when_narrowing()) {
|
||||||
// Note that this may be overwritten; see above comment.
|
// Note that this may be overwritten; see above comment.
|
||||||
id_info.final_select_id = LARGER_THAN_MAX_MESSAGE_ID;
|
id_info.final_select_id = LARGER_THAN_MAX_MESSAGE_ID;
|
||||||
}
|
}
|
||||||
|
@ -628,13 +628,10 @@ export function maybe_add_local_messages(opts) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can now assume narrow_state.filter().can_apply_locally(),
|
// We can now assume filter.can_apply_locally(),
|
||||||
// because !can_apply_locally => cannot_compute
|
// because !can_apply_locally => cannot_compute
|
||||||
|
|
||||||
if (
|
if (unread_info.flavor === "found" && filter.allow_use_first_unread_when_narrowing()) {
|
||||||
unread_info.flavor === "found" &&
|
|
||||||
narrow_state.filter().allow_use_first_unread_when_narrowing()
|
|
||||||
) {
|
|
||||||
// We have at least one unread message in this narrow, and the
|
// We have at least one unread message in this narrow, and the
|
||||||
// narrow is one where we use the first unread message in
|
// narrow is one where we use the first unread message in
|
||||||
// narrowing positioning decisions. So either we aim for the
|
// narrowing positioning decisions. So either we aim for the
|
||||||
|
@ -1098,9 +1095,7 @@ export function deactivate() {
|
||||||
compose_actions.cancel();
|
compose_actions.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
|
||||||
narrow_state.set_has_shown_message_list_view();
|
narrow_state.set_has_shown_message_list_view();
|
||||||
|
|
||||||
message_lists.update_current_message_list(message_lists.home);
|
message_lists.update_current_message_list(message_lists.home);
|
||||||
assert(message_lists.current === message_lists.home);
|
assert(message_lists.current === message_lists.home);
|
||||||
message_lists.current.resume_reading();
|
message_lists.current.resume_reading();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
|
@ -8,13 +9,14 @@ import * as narrow_state from "./narrow_state";
|
||||||
// history, so that we are able to restore it if the user
|
// history, so that we are able to restore it if the user
|
||||||
// navigates back to this page.
|
// navigates back to this page.
|
||||||
function _save_narrow_state(): void {
|
function _save_narrow_state(): void {
|
||||||
if (!narrow_state.active() || message_lists.current === undefined) {
|
const current_filter = narrow_state.filter();
|
||||||
|
if (current_filter === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(message_lists.current !== undefined);
|
||||||
// We don't want to save state in the middle of a narrow change
|
// We don't want to save state in the middle of a narrow change
|
||||||
// to the wrong hash.
|
// to the wrong hash.
|
||||||
const current_filter = message_lists.current.data.filter;
|
|
||||||
if (hash_util.search_terms_to_hash(current_filter.terms()) !== window.location.hash) {
|
if (hash_util.search_terms_to_hash(current_filter.terms()) !== window.location.hash) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import {Filter} from "./filter";
|
import {Filter} from "./filter";
|
||||||
import * as inbox_util from "./inbox_util";
|
import * as inbox_util from "./inbox_util";
|
||||||
|
import * as message_lists from "./message_lists";
|
||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as recent_view_util from "./recent_view_util";
|
import * as recent_view_util from "./recent_view_util";
|
||||||
|
@ -9,29 +10,18 @@ import * as stream_data from "./stream_data";
|
||||||
import type {StreamSubscription} from "./sub_store";
|
import type {StreamSubscription} from "./sub_store";
|
||||||
import * as unread from "./unread";
|
import * as unread from "./unread";
|
||||||
|
|
||||||
let current_filter: Filter | undefined;
|
|
||||||
|
|
||||||
export let has_shown_message_list_view = false;
|
export let has_shown_message_list_view = false;
|
||||||
|
|
||||||
export function reset_current_filter(): void {
|
|
||||||
current_filter = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function set_current_filter(filter: Filter | undefined): void {
|
|
||||||
current_filter = filter;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function active(): boolean {
|
|
||||||
return current_filter !== undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function filter(): Filter | undefined {
|
export function filter(): Filter | undefined {
|
||||||
// Both, `All messages` and
|
// `All messages`, `Recent Conversations` and `Inbox` return undefined;
|
||||||
// `Recent Conversations` have `current_filter=undefined`
|
if (message_lists.current === undefined || message_lists.current.data.filter.is_in_home()) {
|
||||||
return current_filter;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search_terms(): NarrowTerm[] {
|
return message_lists.current.data.filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function search_terms(current_filter: Filter | undefined = filter()): NarrowTerm[] {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
if (page_params.narrow !== undefined) {
|
if (page_params.narrow !== undefined) {
|
||||||
return new Filter(page_params.narrow).terms();
|
return new Filter(page_params.narrow).terms();
|
||||||
|
@ -45,22 +35,28 @@ export function is_message_feed_visible(): boolean {
|
||||||
return !recent_view_util.is_visible() && !inbox_util.is_visible();
|
return !recent_view_util.is_visible() && !inbox_util.is_visible();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function update_email(user_id: number, new_email: string): void {
|
export function update_email(
|
||||||
|
user_id: number,
|
||||||
|
new_email: string,
|
||||||
|
current_filter: Filter | undefined = filter(),
|
||||||
|
): void {
|
||||||
if (current_filter !== undefined) {
|
if (current_filter !== undefined) {
|
||||||
current_filter.update_email(user_id, new_email);
|
current_filter.update_email(user_id, new_email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search terms we should send to the server. */
|
/* Search terms we should send to the server. */
|
||||||
export function public_search_terms(): NarrowTerm[] | undefined {
|
export function public_search_terms(
|
||||||
|
current_filter: Filter | undefined = filter(),
|
||||||
|
): NarrowTerm[] | undefined {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return current_filter.public_terms();
|
return current_filter.public_terms();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search_string(): string {
|
export function search_string(filter?: Filter): string {
|
||||||
return Filter.unparse(search_terms());
|
return Filter.unparse(search_terms(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect terms which appear only once into an object,
|
// Collect terms which appear only once into an object,
|
||||||
|
@ -123,7 +119,7 @@ export function set_compose_defaults(): {
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stream_name(): string | undefined {
|
export function stream_name(current_filter: Filter | undefined = filter()): string | undefined {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +134,9 @@ export function stream_name(): string | undefined {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stream_sub(): StreamSubscription | undefined {
|
export function stream_sub(
|
||||||
|
current_filter: Filter | undefined = filter(),
|
||||||
|
): StreamSubscription | undefined {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -153,15 +151,15 @@ export function stream_sub(): StreamSubscription | undefined {
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stream_id(): number | undefined {
|
export function stream_id(filter?: Filter): number | undefined {
|
||||||
const sub = stream_sub();
|
const sub = stream_sub(filter);
|
||||||
if (sub === undefined) {
|
if (sub === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return sub.stream_id;
|
return sub.stream_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function topic(): string | undefined {
|
export function topic(current_filter: Filter | undefined = filter()): string | undefined {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -172,10 +170,10 @@ export function topic(): string | undefined {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pm_ids_string(): string | undefined {
|
export function pm_ids_string(filter?: Filter): string | undefined {
|
||||||
// If you are narrowed to a group direct message with
|
// If you are narrowed to a group direct message with
|
||||||
// users 4, 5, and 99, this will return "4,5,99"
|
// users 4, 5, and 99, this will return "4,5,99"
|
||||||
const emails_string = pm_emails_string();
|
const emails_string = pm_emails_string(filter);
|
||||||
|
|
||||||
if (!emails_string) {
|
if (!emails_string) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -186,13 +184,15 @@ export function pm_ids_string(): string | undefined {
|
||||||
return user_ids_string;
|
return user_ids_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pm_ids_set(): Set<number> {
|
export function pm_ids_set(filter?: Filter): Set<number> {
|
||||||
const ids_string = pm_ids_string();
|
const ids_string = pm_ids_string(filter);
|
||||||
const pm_ids_list = ids_string ? people.user_ids_string_to_ids_array(ids_string) : [];
|
const pm_ids_list = ids_string ? people.user_ids_string_to_ids_array(ids_string) : [];
|
||||||
return new Set(pm_ids_list);
|
return new Set(pm_ids_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pm_emails_string(): string | undefined {
|
export function pm_emails_string(
|
||||||
|
current_filter: Filter | undefined = filter(),
|
||||||
|
): string | undefined {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -205,9 +205,9 @@ export function pm_emails_string(): string | undefined {
|
||||||
return operands[0];
|
return operands[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_first_unread_info():
|
export function get_first_unread_info(
|
||||||
| {flavor: "cannot_compute" | "not_found"}
|
current_filter: Filter | undefined = filter(),
|
||||||
| {flavor: "found"; msg_id: number} {
|
): {flavor: "cannot_compute" | "not_found"} | {flavor: "found"; msg_id: number} {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
// we don't yet support the all-messages view
|
// we don't yet support the all-messages view
|
||||||
blueslip.error("unexpected call to get_first_unread_info");
|
blueslip.error("unexpected call to get_first_unread_info");
|
||||||
|
@ -226,7 +226,7 @@ export function get_first_unread_info():
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const unread_ids = _possible_unread_message_ids();
|
const unread_ids = _possible_unread_message_ids(current_filter);
|
||||||
|
|
||||||
if (unread_ids === undefined) {
|
if (unread_ids === undefined) {
|
||||||
// _possible_unread_message_ids() only works for certain narrows
|
// _possible_unread_message_ids() only works for certain narrows
|
||||||
|
@ -249,7 +249,9 @@ export function get_first_unread_info():
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _possible_unread_message_ids(): number[] | undefined {
|
export function _possible_unread_message_ids(
|
||||||
|
current_filter: Filter | undefined = filter(),
|
||||||
|
): number[] | undefined {
|
||||||
// This function currently only returns valid results for
|
// This function currently only returns valid results for
|
||||||
// certain types of narrows, mostly left sidebar narrows.
|
// certain types of narrows, mostly left sidebar narrows.
|
||||||
// For more complicated narrows we may return undefined.
|
// For more complicated narrows we may return undefined.
|
||||||
|
@ -266,8 +268,8 @@ export function _possible_unread_message_ids(): number[] | undefined {
|
||||||
let current_filter_pm_string;
|
let current_filter_pm_string;
|
||||||
|
|
||||||
if (current_filter.can_bucket_by("stream", "topic")) {
|
if (current_filter.can_bucket_by("stream", "topic")) {
|
||||||
sub = stream_sub();
|
sub = stream_sub(current_filter);
|
||||||
topic_name = topic();
|
topic_name = topic(current_filter);
|
||||||
if (sub === undefined || topic_name === undefined) {
|
if (sub === undefined || topic_name === undefined) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -275,7 +277,7 @@ export function _possible_unread_message_ids(): number[] | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_filter.can_bucket_by("stream")) {
|
if (current_filter.can_bucket_by("stream")) {
|
||||||
sub = stream_sub();
|
sub = stream_sub(current_filter);
|
||||||
if (sub === undefined) {
|
if (sub === undefined) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -283,7 +285,7 @@ export function _possible_unread_message_ids(): number[] | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_filter.can_bucket_by("dm")) {
|
if (current_filter.can_bucket_by("dm")) {
|
||||||
current_filter_pm_string = pm_ids_string();
|
current_filter_pm_string = pm_ids_string(current_filter);
|
||||||
if (current_filter_pm_string === undefined) {
|
if (current_filter_pm_string === undefined) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -316,14 +318,14 @@ export function _possible_unread_message_ids(): number[] | undefined {
|
||||||
|
|
||||||
// Are we narrowed to direct messages: all direct messages
|
// Are we narrowed to direct messages: all direct messages
|
||||||
// or direct messages with particular people.
|
// or direct messages with particular people.
|
||||||
export function narrowed_to_pms(): boolean {
|
export function narrowed_to_pms(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return current_filter.has_operator("dm") || current_filter.has_operand("is", "dm");
|
return current_filter.has_operator("dm") || current_filter.has_operand("is", "dm");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_by_pm_reply(): boolean {
|
export function narrowed_by_pm_reply(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +333,7 @@ export function narrowed_by_pm_reply(): boolean {
|
||||||
return terms.length === 1 && current_filter.has_operator("dm");
|
return terms.length === 1 && current_filter.has_operator("dm");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_by_topic_reply(): boolean {
|
export function narrowed_by_topic_reply(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -346,11 +348,11 @@ export function narrowed_by_topic_reply(): boolean {
|
||||||
// We auto-reply under certain conditions, namely when you're narrowed
|
// We auto-reply under certain conditions, namely when you're narrowed
|
||||||
// to a 1:1 or group direct message conversation, and when you're
|
// to a 1:1 or group direct message conversation, and when you're
|
||||||
// narrowed to some stream/topic pair.
|
// narrowed to some stream/topic pair.
|
||||||
export function narrowed_by_reply(): boolean {
|
export function narrowed_by_reply(filter?: Filter): boolean {
|
||||||
return narrowed_by_pm_reply() || narrowed_by_topic_reply();
|
return narrowed_by_pm_reply(filter) || narrowed_by_topic_reply(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_by_stream_reply(): boolean {
|
export function narrowed_by_stream_reply(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -358,38 +360,38 @@ export function narrowed_by_stream_reply(): boolean {
|
||||||
return terms.length === 1 && current_filter.operands("stream").length === 1;
|
return terms.length === 1 && current_filter.operands("stream").length === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_to_topic(): boolean {
|
export function narrowed_to_topic(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return current_filter.has_operator("stream") && current_filter.has_operator("topic");
|
return current_filter.has_operator("stream") && current_filter.has_operator("topic");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_to_search(): boolean {
|
export function narrowed_to_search(current_filter: Filter | undefined = filter()): boolean {
|
||||||
return current_filter !== undefined && current_filter.is_keyword_search();
|
return current_filter !== undefined && current_filter.is_keyword_search();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function narrowed_to_starred(): boolean {
|
export function narrowed_to_starred(current_filter: Filter | undefined = filter()): boolean {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return current_filter.has_operand("is", "starred");
|
return current_filter.has_operand("is", "starred");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function excludes_muted_topics(): boolean {
|
export function excludes_muted_topics(filter: Filter): boolean {
|
||||||
return (
|
return (
|
||||||
!narrowed_to_topic() &&
|
!narrowed_to_topic(filter) &&
|
||||||
!narrowed_to_search() &&
|
!narrowed_to_search(filter) &&
|
||||||
!narrowed_to_pms() &&
|
!narrowed_to_pms(filter) &&
|
||||||
!narrowed_to_starred()
|
!narrowed_to_starred(filter)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_for_stream_id(stream_id: number): boolean {
|
export function is_for_stream_id(stream_id: number, filter?: Filter): boolean {
|
||||||
// This is not perfect, since we still track narrows by
|
// This is not perfect, since we still track narrows by
|
||||||
// name, not id, but at least the interface is good going
|
// name, not id, but at least the interface is good going
|
||||||
// forward.
|
// forward.
|
||||||
const narrow_sub = stream_sub();
|
const narrow_sub = stream_sub(filter);
|
||||||
|
|
||||||
if (narrow_sub === undefined) {
|
if (narrow_sub === undefined) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import assert from "minimalistic-assert";
|
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as compose_state from "./compose_state";
|
import * as compose_state from "./compose_state";
|
||||||
|
@ -8,7 +7,6 @@ import * as drafts from "./drafts";
|
||||||
import * as hash_util from "./hash_util";
|
import * as hash_util from "./hash_util";
|
||||||
import {localstorage} from "./localstorage";
|
import {localstorage} from "./localstorage";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as narrow_state from "./narrow_state";
|
|
||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
import * as reload_state from "./reload_state";
|
import * as reload_state from "./reload_state";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
|
@ -80,16 +78,15 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save_narrow) {
|
if (save_narrow) {
|
||||||
|
if (message_lists.current === message_lists.home) {
|
||||||
const $row = message_lists.home.selected_row();
|
const $row = message_lists.home.selected_row();
|
||||||
if (!narrow_state.active()) {
|
|
||||||
if ($row.length > 0) {
|
if ($row.length > 0) {
|
||||||
url += "+offset=" + $row.get_offset_to_window().top;
|
url += "+offset=" + $row.get_offset_to_window().top;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (message_lists.current !== undefined) {
|
||||||
assert(message_lists.current !== undefined);
|
|
||||||
url += "+offset=" + message_lists.home.pre_narrow_offset;
|
url += "+offset=" + message_lists.home.pre_narrow_offset;
|
||||||
|
|
||||||
// narrow_state.active() is true, so this is the current
|
// narrow_state.filter() is not undefined, so this is the current
|
||||||
// narrowed message list.
|
// narrowed message list.
|
||||||
const narrow_pointer = message_lists.current.selected_id();
|
const narrow_pointer = message_lists.current.selected_id();
|
||||||
if (narrow_pointer !== -1) {
|
if (narrow_pointer !== -1) {
|
||||||
|
@ -99,6 +96,8 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo
|
||||||
if ($narrow_row.length > 0) {
|
if ($narrow_row.length > 0) {
|
||||||
url += "+narrow_offset=" + $narrow_row.get_offset_to_window().top;
|
url += "+narrow_offset=" + $narrow_row.get_offset_to_window().top;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
url += "+offset=" + message_lists.home.pre_narrow_offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -580,12 +580,11 @@ export function update_streams_sidebar(force_rerender = false): void {
|
||||||
|
|
||||||
stream_cursor.redraw();
|
stream_cursor.redraw();
|
||||||
|
|
||||||
if (!narrow_state.active()) {
|
const filter = narrow_state.filter();
|
||||||
|
if (!filter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter = narrow_state.filter();
|
|
||||||
assert(filter !== undefined);
|
|
||||||
update_stream_sidebar_for_narrow(filter);
|
update_stream_sidebar_for_narrow(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ export function show(opts) {
|
||||||
|
|
||||||
unread_ui.hide_unread_banner();
|
unread_ui.hide_unread_banner();
|
||||||
opts.update_compose();
|
opts.update_compose();
|
||||||
narrow_state.reset_current_filter();
|
|
||||||
narrow_title.update_narrow_title(narrow_state.filter());
|
narrow_title.update_narrow_title(narrow_state.filter());
|
||||||
message_view_header.render_title_area();
|
message_view_header.render_title_area();
|
||||||
compose_recipient.handle_middle_pane_transition();
|
compose_recipient.handle_middle_pane_transition();
|
||||||
|
|
|
@ -2,7 +2,6 @@ import $ from "jquery";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as narrow_state from "./narrow_state";
|
|
||||||
|
|
||||||
export const widgets = new Map();
|
export const widgets = new Map();
|
||||||
export const widget_contents = new Map();
|
export const widget_contents = new Map();
|
||||||
|
@ -49,12 +48,8 @@ export function activate(in_opts) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (!$row.attr("id").startsWith(`message-row-${message_lists.current?.id}-`)) {
|
||||||
$row.attr("id").startsWith(`message-row-${message_lists.home.id}-`) &&
|
// Don't activate widgets for messages that are not in the current view.
|
||||||
narrow_state.active()
|
|
||||||
) {
|
|
||||||
// Don't place widget in a home message row if we are narrowed
|
|
||||||
// to active state
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,11 +70,12 @@ run_test("filter", () => {
|
||||||
// state with the narrow_state module.
|
// state with the narrow_state module.
|
||||||
|
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
|
|
||||||
run_test("narrow_state", () => {
|
run_test("narrow_state", () => {
|
||||||
stream_data.clear_subscriptions();
|
stream_data.clear_subscriptions();
|
||||||
stream_data.add_sub(denmark_stream);
|
stream_data.add_sub(denmark_stream);
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
|
|
||||||
// As we often do, first make assertions about the starting
|
// As we often do, first make assertions about the starting
|
||||||
// state:
|
// state:
|
||||||
|
@ -90,8 +91,11 @@ run_test("narrow_state", () => {
|
||||||
const filter = new Filter(filter_terms);
|
const filter = new Filter(filter_terms);
|
||||||
|
|
||||||
// And here is where we actually change state.
|
// And here is where we actually change state.
|
||||||
narrow_state.set_current_filter(filter);
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
});
|
||||||
assert.equal(narrow_state.stream_name(), "Denmark");
|
assert.equal(narrow_state.stream_name(), "Denmark");
|
||||||
assert.equal(narrow_state.topic(), "copenhagen");
|
assert.equal(narrow_state.topic(), "copenhagen");
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,7 +45,6 @@ message_lists.all_rendered_message_lists = () => [message_lists.home, message_li
|
||||||
// And we will also test some real code, of course.
|
// And we will also test some real code, of course.
|
||||||
const message_events = zrequire("message_events");
|
const message_events = zrequire("message_events");
|
||||||
const message_store = zrequire("message_store");
|
const message_store = zrequire("message_store");
|
||||||
const narrow_state = zrequire("narrow_state");
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
|
|
||||||
const isaac = {
|
const isaac = {
|
||||||
|
@ -107,8 +106,6 @@ run_test("insert_message", ({override}) => {
|
||||||
helper.redirect(unread_ops, "process_visible");
|
helper.redirect(unread_ops, "process_visible");
|
||||||
helper.redirect(unread_ui, "update_unread_counts");
|
helper.redirect(unread_ui, "update_unread_counts");
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
|
||||||
|
|
||||||
message_events.insert_new_messages([new_message]);
|
message_events.insert_new_messages([new_message]);
|
||||||
|
|
||||||
// Even though we have stubbed a *lot* of code, our
|
// Even though we have stubbed a *lot* of code, our
|
||||||
|
|
|
@ -27,7 +27,7 @@ mock_esm("../src/settings_data", {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {Filter} = zrequire("filter");
|
const {Filter} = zrequire("filter");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const message_lists = zrequire("message_lists");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const typing_data = zrequire("typing_data");
|
const typing_data = zrequire("typing_data");
|
||||||
const typing_events = zrequire("typing_events");
|
const typing_events = zrequire("typing_events");
|
||||||
|
@ -82,7 +82,11 @@ run_test("typing_events.render_notifications_for_narrow", ({override, mock_templ
|
||||||
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
||||||
const conversation_key = typing_data.get_direct_message_conversation_key(group);
|
const conversation_key = typing_data.get_direct_message_conversation_key(group);
|
||||||
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
|
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
|
||||||
narrow_state.set_current_filter(new Filter([{operator: "dm", operand: group_emails}]));
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: new Filter([{operator: "dm", operand: group_emails}]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Based on typing_events.MAX_USERS_TO_DISPLAY_NAME (which is currently 3),
|
// Based on typing_events.MAX_USERS_TO_DISPLAY_NAME (which is currently 3),
|
||||||
// we display either the list of all users typing (if they do not exceed
|
// we display either the list of all users typing (if they do not exceed
|
||||||
|
|
|
@ -11,7 +11,6 @@ const {page_params, realm} = require("./lib/zpage_params");
|
||||||
const hash_util = zrequire("hash_util");
|
const hash_util = zrequire("hash_util");
|
||||||
const compose_state = zrequire("compose_state");
|
const compose_state = zrequire("compose_state");
|
||||||
const narrow_banner = zrequire("narrow_banner");
|
const narrow_banner = zrequire("narrow_banner");
|
||||||
const narrow_state = zrequire("narrow_state");
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const {Filter} = zrequire("../src/filter");
|
const {Filter} = zrequire("../src/filter");
|
||||||
|
@ -20,6 +19,7 @@ const narrow_title = zrequire("narrow_title");
|
||||||
const settings_config = zrequire("settings_config");
|
const settings_config = zrequire("settings_config");
|
||||||
const recent_view_util = zrequire("recent_view_util");
|
const recent_view_util = zrequire("recent_view_util");
|
||||||
const inbox_util = zrequire("inbox_util");
|
const inbox_util = zrequire("inbox_util");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
|
|
||||||
mock_esm("../src/compose_banner", {
|
mock_esm("../src/compose_banner", {
|
||||||
clear_search_view_banner() {},
|
clear_search_view_banner() {},
|
||||||
|
@ -43,7 +43,11 @@ function set_filter(terms) {
|
||||||
operator: op[0],
|
operator: op[0],
|
||||||
operand: op[1],
|
operand: op[1],
|
||||||
}));
|
}));
|
||||||
narrow_state.set_current_filter(new Filter(terms));
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: new Filter(terms),
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const me = {
|
const me = {
|
||||||
|
@ -203,7 +207,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
|
|
||||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
narrow_banner.show_empty_narrow_message();
|
narrow_banner.show_empty_narrow_message();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$(".empty_feed_notice_main").html(),
|
$(".empty_feed_notice_main").html(),
|
||||||
|
@ -529,7 +533,7 @@ run_test("show_empty_narrow_message_with_search", ({mock_template}) => {
|
||||||
|
|
||||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
set_filter([["search", "grail"]]);
|
set_filter([["search", "grail"]]);
|
||||||
narrow_banner.show_empty_narrow_message();
|
narrow_banner.show_empty_narrow_message();
|
||||||
assert.match($(".empty_feed_notice_main").html(), /<span>grail<\/span>/);
|
assert.match($(".empty_feed_notice_main").html(), /<span>grail<\/span>/);
|
||||||
|
@ -553,7 +557,7 @@ run_test("show_search_stopwords", ({mock_template}) => {
|
||||||
{query_word: "grail", is_stop_word: false},
|
{query_word: "grail", is_stop_word: false},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
set_filter([["search", "what about grail"]]);
|
set_filter([["search", "what about grail"]]);
|
||||||
narrow_banner.show_empty_narrow_message();
|
narrow_banner.show_empty_narrow_message();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@ -607,7 +611,7 @@ run_test("show_search_stopwords", ({mock_template}) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("show_invalid_narrow_message", ({mock_template}) => {
|
run_test("show_invalid_narrow_message", ({mock_template}) => {
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
mock_template("empty_feed_notice.hbs", true, (_data, html) => html);
|
||||||
|
|
||||||
stream_data.add_sub({name: "streamA", stream_id: 88});
|
stream_data.add_sub({name: "streamA", stream_id: 88});
|
||||||
|
|
|
@ -9,7 +9,7 @@ const $ = require("./lib/zjquery");
|
||||||
mock_esm("../src/resize", {
|
mock_esm("../src/resize", {
|
||||||
resize_stream_filters_container() {},
|
resize_stream_filters_container() {},
|
||||||
});
|
});
|
||||||
|
const {Filter} = zrequire("../src/filter");
|
||||||
const all_messages_data = mock_esm("../src/all_messages_data");
|
const all_messages_data = mock_esm("../src/all_messages_data");
|
||||||
const browser_history = mock_esm("../src/browser_history", {
|
const browser_history = mock_esm("../src/browser_history", {
|
||||||
state: {changing_hash: false},
|
state: {changing_hash: false},
|
||||||
|
@ -37,6 +37,9 @@ const message_lists = mock_esm("../src/message_lists", {
|
||||||
addClass: noop,
|
addClass: noop,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
data: {
|
||||||
|
filter: new Filter([{operator: "in", operand: "all"}]),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
update_current_message_list(msg_list) {
|
update_current_message_list(msg_list) {
|
||||||
message_lists.current = msg_list;
|
message_lists.current = msg_list;
|
||||||
|
|
|
@ -11,11 +11,16 @@ const {Filter} = zrequire("../src/filter");
|
||||||
const {MessageListData} = zrequire("../src/message_list_data");
|
const {MessageListData} = zrequire("../src/message_list_data");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
const narrow = zrequire("narrow");
|
const narrow = zrequire("narrow");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
const resolved_topic = zrequire("../shared/src/resolved_topic");
|
const resolved_topic = zrequire("../shared/src/resolved_topic");
|
||||||
|
|
||||||
function test_with(fixture) {
|
function test_with(fixture) {
|
||||||
const filter = new Filter(fixture.filter_terms);
|
const filter = new Filter(fixture.filter_terms);
|
||||||
narrow_state.set_current_filter(filter);
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Make sure our simulated tests data satisfies the
|
// Make sure our simulated tests data satisfies the
|
||||||
// invariant that the first unread message we find
|
// invariant that the first unread message we find
|
||||||
|
|
|
@ -10,18 +10,23 @@ const people = zrequire("people");
|
||||||
const {Filter} = zrequire("../src/filter");
|
const {Filter} = zrequire("../src/filter");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
|
|
||||||
function set_filter(raw_terms) {
|
function set_filter(raw_terms) {
|
||||||
const terms = raw_terms.map((op) => ({
|
const terms = raw_terms.map((op) => ({
|
||||||
operator: op[0],
|
operator: op[0],
|
||||||
operand: op[1],
|
operand: op[1],
|
||||||
}));
|
}));
|
||||||
narrow_state.set_current_filter(new Filter(terms));
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: new Filter(terms),
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(label, f) {
|
function test(label, f) {
|
||||||
run_test(label, ({override}) => {
|
run_test(label, ({override}) => {
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
stream_data.clear_subscriptions();
|
stream_data.clear_subscriptions();
|
||||||
f({override});
|
f({override});
|
||||||
});
|
});
|
||||||
|
@ -29,7 +34,7 @@ function test(label, f) {
|
||||||
|
|
||||||
test("stream", () => {
|
test("stream", () => {
|
||||||
assert.equal(narrow_state.public_search_terms(), undefined);
|
assert.equal(narrow_state.public_search_terms(), undefined);
|
||||||
assert.ok(!narrow_state.active());
|
assert.ok(!narrow_state.filter());
|
||||||
assert.equal(narrow_state.stream_id(), undefined);
|
assert.equal(narrow_state.stream_id(), undefined);
|
||||||
|
|
||||||
const test_stream = {name: "Test", stream_id: 15};
|
const test_stream = {name: "Test", stream_id: 15};
|
||||||
|
@ -42,7 +47,7 @@ test("stream", () => {
|
||||||
["topic", "Bar"],
|
["topic", "Bar"],
|
||||||
["search", "yo"],
|
["search", "yo"],
|
||||||
]);
|
]);
|
||||||
assert.ok(narrow_state.active());
|
assert.ok(narrow_state.filter());
|
||||||
|
|
||||||
assert.equal(narrow_state.stream_name(), "Test");
|
assert.equal(narrow_state.stream_name(), "Test");
|
||||||
assert.equal(narrow_state.stream_id(), 15);
|
assert.equal(narrow_state.stream_id(), 15);
|
||||||
|
@ -143,7 +148,7 @@ test("terms", () => {
|
||||||
assert.equal(result[2].operator, "search");
|
assert.equal(result[2].operator, "search");
|
||||||
assert.equal(result[2].operand, "yo");
|
assert.equal(result[2].operand, "yo");
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
result = narrow_state.search_terms();
|
result = narrow_state.search_terms();
|
||||||
assert.equal(result.length, 0);
|
assert.equal(result.length, 0);
|
||||||
|
|
||||||
|
@ -158,7 +163,7 @@ test("excludes_muted_topics", () => {
|
||||||
set_filter([["stream", "devel"]]);
|
set_filter([["stream", "devel"]]);
|
||||||
assert.ok(narrow_state.excludes_muted_topics());
|
assert.ok(narrow_state.excludes_muted_topics());
|
||||||
|
|
||||||
narrow_state.reset_current_filter(); // not narrowed, basically
|
message_lists.current = undefined; // not narrowed, basically
|
||||||
assert.ok(narrow_state.excludes_muted_topics());
|
assert.ok(narrow_state.excludes_muted_topics());
|
||||||
|
|
||||||
set_filter([
|
set_filter([
|
||||||
|
@ -271,7 +276,7 @@ test("topic", () => {
|
||||||
]);
|
]);
|
||||||
assert.equal(narrow_state.topic(), undefined);
|
assert.equal(narrow_state.topic(), undefined);
|
||||||
|
|
||||||
narrow_state.set_current_filter(undefined);
|
message_lists.set_current(undefined);
|
||||||
assert.equal(narrow_state.topic(), undefined);
|
assert.equal(narrow_state.topic(), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -302,7 +307,7 @@ test("pm_ids_string", () => {
|
||||||
// This function will return undefined unless we're clearly
|
// This function will return undefined unless we're clearly
|
||||||
// narrowed to a specific direct message (including group
|
// narrowed to a specific direct message (including group
|
||||||
// direct messages) with real users.
|
// direct messages) with real users.
|
||||||
narrow_state.set_current_filter(undefined);
|
message_lists.set_current(undefined);
|
||||||
assert.equal(narrow_state.pm_ids_string(), undefined);
|
assert.equal(narrow_state.pm_ids_string(), undefined);
|
||||||
assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set());
|
assert.deepStrictEqual(narrow_state.pm_ids_set(), new Set());
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ const stream_data = zrequire("stream_data");
|
||||||
const unread = zrequire("unread");
|
const unread = zrequire("unread");
|
||||||
// The main code we are testing lives here.
|
// The main code we are testing lives here.
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
|
|
||||||
const alice = {
|
const alice = {
|
||||||
email: "alice@example.com",
|
email: "alice@example.com",
|
||||||
|
@ -29,11 +30,18 @@ people.add_active_user(alice);
|
||||||
|
|
||||||
function set_filter(terms) {
|
function set_filter(terms) {
|
||||||
const filter = new Filter(terms);
|
const filter = new Filter(terms);
|
||||||
narrow_state.set_current_filter(filter);
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_unread_info(expected) {
|
function assert_unread_info(expected) {
|
||||||
assert.deepEqual(narrow_state.get_first_unread_info(), expected);
|
assert.deepEqual(
|
||||||
|
narrow_state.get_first_unread_info(message_lists.current?.data.filter),
|
||||||
|
expected,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function candidate_ids() {
|
function candidate_ids() {
|
||||||
|
@ -42,7 +50,7 @@ function candidate_ids() {
|
||||||
|
|
||||||
run_test("get_unread_ids", () => {
|
run_test("get_unread_ids", () => {
|
||||||
unread.declare_bankruptcy();
|
unread.declare_bankruptcy();
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
|
|
||||||
let unread_ids;
|
let unread_ids;
|
||||||
let terms;
|
let terms;
|
||||||
|
@ -194,7 +202,7 @@ run_test("get_unread_ids", () => {
|
||||||
flavor: "cannot_compute",
|
flavor: "cannot_compute",
|
||||||
});
|
});
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
blueslip.expect("error", "unexpected call to get_first_unread_info");
|
blueslip.expect("error", "unexpected call to get_first_unread_info");
|
||||||
assert_unread_info({
|
assert_unread_info({
|
||||||
flavor: "cannot_compute",
|
flavor: "cannot_compute",
|
||||||
|
|
|
@ -18,6 +18,7 @@ const narrow_state = zrequire("narrow_state");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const pm_conversations = zrequire("pm_conversations");
|
const pm_conversations = zrequire("pm_conversations");
|
||||||
const pm_list_data = zrequire("pm_list_data");
|
const pm_list_data = zrequire("pm_list_data");
|
||||||
|
const message_lists = zrequire("message_lists");
|
||||||
|
|
||||||
const alice = {
|
const alice = {
|
||||||
email: "alice@zulip.com",
|
email: "alice@zulip.com",
|
||||||
|
@ -67,7 +68,7 @@ people.initialize_current_user(me.user_id);
|
||||||
|
|
||||||
function test(label, f) {
|
function test(label, f) {
|
||||||
run_test(label, (helpers) => {
|
run_test(label, (helpers) => {
|
||||||
narrow_state.reset_current_filter();
|
message_lists.set_current(undefined);
|
||||||
pm_conversations.clear_for_testing();
|
pm_conversations.clear_for_testing();
|
||||||
f(helpers);
|
f(helpers);
|
||||||
});
|
});
|
||||||
|
@ -75,7 +76,11 @@ function test(label, f) {
|
||||||
|
|
||||||
function set_pm_with_filter(emails) {
|
function set_pm_with_filter(emails) {
|
||||||
const active_filter = new Filter([{operator: "dm", operand: emails}]);
|
const active_filter = new Filter([{operator: "dm", operand: emails}]);
|
||||||
narrow_state.set_current_filter(active_filter);
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: active_filter,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_list_info(list, length, more_unread, recipients_array) {
|
function check_list_info(list, length, more_unread, recipients_array) {
|
||||||
|
@ -183,7 +188,11 @@ test("get_active_user_ids_string", () => {
|
||||||
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
||||||
|
|
||||||
const stream_filter = new Filter([{operator: "stream", operand: "test"}]);
|
const stream_filter = new Filter([{operator: "stream", operand: "test"}]);
|
||||||
narrow_state.set_current_filter(stream_filter);
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: stream_filter,
|
||||||
|
},
|
||||||
|
});
|
||||||
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
assert.equal(pm_list_data.get_active_user_ids_string(), undefined);
|
||||||
|
|
||||||
set_pm_with_filter("bob@zulip.com,alice@zulip.com");
|
set_pm_with_filter("bob@zulip.com,alice@zulip.com");
|
||||||
|
|
|
@ -9,9 +9,6 @@ const {page_params, realm} = require("./lib/zpage_params");
|
||||||
const {Filter} = zrequire("filter");
|
const {Filter} = zrequire("filter");
|
||||||
const {MessageList} = zrequire("message_list");
|
const {MessageList} = zrequire("message_list");
|
||||||
const message_lists = zrequire("message_lists");
|
const message_lists = zrequire("message_lists");
|
||||||
message_lists.update_current_message_list = (list) => {
|
|
||||||
message_lists.current = list;
|
|
||||||
};
|
|
||||||
|
|
||||||
const popover_menus_data = zrequire("popover_menus_data");
|
const popover_menus_data = zrequire("popover_menus_data");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
|
@ -139,7 +136,7 @@ test("my_message_all_actions", () => {
|
||||||
// Get message with maximum permissions available
|
// Get message with maximum permissions available
|
||||||
// Initialize message list
|
// Initialize message list
|
||||||
const list = init_message_list();
|
const list = init_message_list();
|
||||||
message_lists.update_current_message_list(list);
|
message_lists.set_current(list);
|
||||||
|
|
||||||
// Assume message has been previously edited.
|
// Assume message has been previously edited.
|
||||||
// Message is sent by me, and is a stream. I should have all permissions to this message.
|
// Message is sent by me, and is a stream. I should have all permissions to this message.
|
||||||
|
@ -189,7 +186,7 @@ test("not_my_message_view_actions", () => {
|
||||||
// Get message that is only viewable
|
// Get message that is only viewable
|
||||||
|
|
||||||
const list = init_message_list();
|
const list = init_message_list();
|
||||||
message_lists.update_current_message_list(list);
|
message_lists.set_current(list);
|
||||||
|
|
||||||
// Message is sent by somebody else and is a stream with previous history.
|
// Message is sent by somebody else and is a stream with previous history.
|
||||||
// I should only be able to view this message with no edit/move permissions.
|
// I should only be able to view this message with no edit/move permissions.
|
||||||
|
@ -229,7 +226,7 @@ test("not_my_message_view_source_and_move", () => {
|
||||||
// Get message that is movable with viewable source
|
// Get message that is movable with viewable source
|
||||||
|
|
||||||
const list = init_message_list();
|
const list = init_message_list();
|
||||||
message_lists.update_current_message_list(list);
|
message_lists.set_current(list);
|
||||||
|
|
||||||
// Message tests edge case where message it sent by someone else.
|
// Message tests edge case where message it sent by someone else.
|
||||||
// Message is movable, however--I should have only view permissions with the exception of moving the message.
|
// Message is movable, however--I should have only view permissions with the exception of moving the message.
|
||||||
|
|
|
@ -80,7 +80,11 @@ const frontend = {
|
||||||
|
|
||||||
function narrow_to_frontend() {
|
function narrow_to_frontend() {
|
||||||
const filter = new Filter([{operator: "stream", operand: "frontend"}]);
|
const filter = new Filter([{operator: "stream", operand: "frontend"}]);
|
||||||
narrow_state.set_current_filter(filter);
|
message_lists.current = {
|
||||||
|
data: {
|
||||||
|
filter,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(label, f) {
|
function test(label, f) {
|
||||||
|
@ -321,7 +325,7 @@ test("marked_subscribed (normal)", ({override}) => {
|
||||||
assert.equal(list_updated, true);
|
assert.equal(list_updated, true);
|
||||||
|
|
||||||
assert.equal(sub.color, "blue");
|
assert.equal(sub.color, "blue");
|
||||||
narrow_state.reset_current_filter();
|
message_lists.current = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
test("marked_subscribed (color)", ({override}) => {
|
test("marked_subscribed (color)", ({override}) => {
|
||||||
|
@ -433,7 +437,7 @@ test("mark_unsubscribed (render_title_area)", ({override}) => {
|
||||||
|
|
||||||
assert.equal(message_view_header_stub.num_calls, 1);
|
assert.equal(message_view_header_stub.num_calls, 1);
|
||||||
|
|
||||||
narrow_state.reset_current_filter();
|
message_lists.current = undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
test("remove_deactivated_user_from_all_streams", () => {
|
test("remove_deactivated_user_from_all_streams", () => {
|
||||||
|
|
|
@ -16,9 +16,6 @@ page_params.realm_users = [];
|
||||||
let unread_unmuted_count;
|
let unread_unmuted_count;
|
||||||
let stream_has_any_unread_mentions;
|
let stream_has_any_unread_mentions;
|
||||||
|
|
||||||
mock_esm("../src/narrow_state", {
|
|
||||||
active: () => false,
|
|
||||||
});
|
|
||||||
const topic_list = mock_esm("../src/topic_list");
|
const topic_list = mock_esm("../src/topic_list");
|
||||||
const scroll_util = mock_esm("../src/scroll_util", {
|
const scroll_util = mock_esm("../src/scroll_util", {
|
||||||
scroll_element_into_container() {},
|
scroll_element_into_container() {},
|
||||||
|
|
|
@ -10,7 +10,7 @@ const {current_user} = require("./lib/zpage_params");
|
||||||
const settings_data = mock_esm("../src/settings_data");
|
const settings_data = mock_esm("../src/settings_data");
|
||||||
|
|
||||||
const {Filter} = zrequire("filter");
|
const {Filter} = zrequire("filter");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const message_lists = zrequire("message_lists");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const typing_data = zrequire("typing_data");
|
const typing_data = zrequire("typing_data");
|
||||||
const typing_events = zrequire("typing_events");
|
const typing_events = zrequire("typing_events");
|
||||||
|
@ -50,7 +50,11 @@ run_test("render_notifications_for_narrow", ({override, mock_template}) => {
|
||||||
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
const group = [anna.user_id, vronsky.user_id, levin.user_id, kitty.user_id];
|
||||||
const conversation_key = typing_data.get_direct_message_conversation_key(group);
|
const conversation_key = typing_data.get_direct_message_conversation_key(group);
|
||||||
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
|
const group_emails = `${anna.email},${vronsky.email},${levin.email},${kitty.email}`;
|
||||||
narrow_state.set_current_filter(new Filter([{operator: "dm", operand: group_emails}]));
|
message_lists.set_current({
|
||||||
|
data: {
|
||||||
|
filter: new Filter([{operator: "dm", operand: group_emails}]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const $typing_notifications = $("#typing_notifications");
|
const $typing_notifications = $("#typing_notifications");
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,7 @@ const fake_poll_widget = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const message_lists = mock_esm("../src/message_lists", {current: {}, home: {id: 1}});
|
const message_lists = mock_esm("../src/message_lists", {current: {id: 2}, home: {id: 1}});
|
||||||
const narrow_state = mock_esm("../src/narrow_state");
|
|
||||||
mock_esm("../src/poll_widget", fake_poll_widget);
|
mock_esm("../src/poll_widget", fake_poll_widget);
|
||||||
|
|
||||||
set_global("document", "document-stub");
|
set_global("document", "document-stub");
|
||||||
|
@ -80,13 +79,10 @@ test("activate", ({override}) => {
|
||||||
// Both widgetize.activate and widgetize.handle_event are tested
|
// Both widgetize.activate and widgetize.handle_event are tested
|
||||||
// here to use the "caching" of widgets
|
// here to use the "caching" of widgets
|
||||||
const $row = $.create("<stub message row>");
|
const $row = $.create("<stub message row>");
|
||||||
$row.attr("id", "message-row-1-2909");
|
$row.attr("id", `message-row-${message_lists.current.id}-2909`);
|
||||||
const $message_content = $.create("#message-row-1-2909");
|
const $message_content = $.create(`#message-row-${message_lists.current.id}-2909`);
|
||||||
$row.set_find_results(".message_content", $message_content);
|
$row.set_find_results(".message_content", $message_content);
|
||||||
|
|
||||||
let narrow_active;
|
|
||||||
override(narrow_state, "active", () => narrow_active);
|
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
events: [...events],
|
events: [...events],
|
||||||
extra_data: "",
|
extra_data: "",
|
||||||
|
@ -133,7 +129,7 @@ test("activate", ({override}) => {
|
||||||
assert.ok(!is_widget_activated);
|
assert.ok(!is_widget_activated);
|
||||||
assert.ok(!is_event_handled);
|
assert.ok(!is_event_handled);
|
||||||
|
|
||||||
narrow_active = true;
|
message_lists.current = undefined;
|
||||||
is_widget_elem_inserted = false;
|
is_widget_elem_inserted = false;
|
||||||
is_widget_activated = false;
|
is_widget_activated = false;
|
||||||
is_event_handled = false;
|
is_event_handled = false;
|
||||||
|
@ -146,7 +142,6 @@ test("activate", ({override}) => {
|
||||||
assert.ok(!is_event_handled);
|
assert.ok(!is_event_handled);
|
||||||
|
|
||||||
blueslip.expect("warn", "unknown widget_type");
|
blueslip.expect("warn", "unknown widget_type");
|
||||||
narrow_active = false;
|
|
||||||
is_widget_elem_inserted = false;
|
is_widget_elem_inserted = false;
|
||||||
is_widget_activated = false;
|
is_widget_activated = false;
|
||||||
is_event_handled = false;
|
is_event_handled = false;
|
||||||
|
@ -187,6 +182,7 @@ test("activate", ({override}) => {
|
||||||
widgetize.handle_event(post_activate_event);
|
widgetize.handle_event(post_activate_event);
|
||||||
assert.ok(!is_event_handled);
|
assert.ok(!is_event_handled);
|
||||||
|
|
||||||
|
message_lists.current = {id: 2};
|
||||||
/* Test narrow change message update */
|
/* Test narrow change message update */
|
||||||
override(message_lists.current, "get", (idx) => {
|
override(message_lists.current, "get", (idx) => {
|
||||||
assert.equal(idx, 2001);
|
assert.equal(idx, 2001);
|
||||||
|
|
Loading…
Reference in New Issue