mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	subs: Move active_stream function to hash_util.
This function better belongs in hash_util since it relies on the current window hash.
This commit is contained in:
		@@ -119,6 +119,15 @@ run_test("build_reload_url", () => {
 | 
			
		||||
    assert.equal(hash_util.build_reload_url(), "+oldhash=");
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test("test_active_stream", () => {
 | 
			
		||||
    location.hash = "#streams/1/announce";
 | 
			
		||||
    assert.equal(hash_util.active_stream().id, 1);
 | 
			
		||||
    assert.equal(hash_util.active_stream().name, "announce");
 | 
			
		||||
 | 
			
		||||
    location.hash = "#test/narrow";
 | 
			
		||||
    assert.equal(hash_util.active_stream(), undefined);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test("test_parse_narrow", () => {
 | 
			
		||||
    assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [
 | 
			
		||||
        {negated: false, operator: "stream", operand: "frontend"},
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ mock_esm("../../static/js/browser_history", {update: noop});
 | 
			
		||||
mock_esm("../../static/js/hash_util", {
 | 
			
		||||
    stream_edit_uri: noop,
 | 
			
		||||
    by_stream_uri: noop,
 | 
			
		||||
    active_stream: noop,
 | 
			
		||||
});
 | 
			
		||||
mock_esm("../../static/js/list_widget", {
 | 
			
		||||
    create: () => ({init: noop}),
 | 
			
		||||
 
 | 
			
		||||
@@ -249,3 +249,20 @@ export function is_overlay_hash(hash) {
 | 
			
		||||
 | 
			
		||||
    return overlay_list.includes(main_hash);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// this finds the stream that is actively open in the settings and focused in
 | 
			
		||||
// the left side.
 | 
			
		||||
export function active_stream() {
 | 
			
		||||
    const hash_components = window.location.hash.slice(1).split(/\//);
 | 
			
		||||
 | 
			
		||||
    // if the string casted to a number is valid, and another component
 | 
			
		||||
    // after exists then it's a stream name/id pair.
 | 
			
		||||
    if (typeof Number.parseFloat(hash_components[1]) === "number" && hash_components[2]) {
 | 
			
		||||
        return {
 | 
			
		||||
            id: Number.parseFloat(hash_components[1]),
 | 
			
		||||
            name: hash_components[2],
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return undefined;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -78,7 +78,7 @@ export function is_sub_settings_active(sub) {
 | 
			
		||||
    // currently being viewed/edited in the stream edit UI.  This is
 | 
			
		||||
    // used to determine whether we need to rerender the stream edit
 | 
			
		||||
    // UI when a sub object is modified by an event.
 | 
			
		||||
    const active_stream = subs.active_stream();
 | 
			
		||||
    const active_stream = hash_util.active_stream();
 | 
			
		||||
    if (active_stream !== undefined && active_stream.id === sub.stream_id) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -145,23 +145,6 @@ function should_list_all_streams() {
 | 
			
		||||
    return !page_params.realm_is_zephyr_mirror_realm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// this finds the stream that is actively open in the settings and focused in
 | 
			
		||||
// the left side.
 | 
			
		||||
export function active_stream() {
 | 
			
		||||
    const hash_components = window.location.hash.slice(1).split(/\//);
 | 
			
		||||
 | 
			
		||||
    // if the string casted to a number is valid, and another component
 | 
			
		||||
    // after exists then it's a stream name/id pair.
 | 
			
		||||
    if (typeof Number.parseFloat(hash_components[1]) === "number" && hash_components[2]) {
 | 
			
		||||
        return {
 | 
			
		||||
            id: Number.parseFloat(hash_components[1]),
 | 
			
		||||
            name: hash_components[2],
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return undefined;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function set_muted(sub, is_muted, status_element) {
 | 
			
		||||
    stream_muting.update_is_muted(sub, is_muted);
 | 
			
		||||
    stream_edit.set_stream_property(sub, "is_muted", sub.is_muted, status_element);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user