mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
compose: Fix opening compose box when viewing invalid stream.
This likely needs further refactoring to switch to using stream IDs rather than names in this code path, but this change fixes an exception that would be throw when opening the compose box while viewing a narrow to an invalid stream name/ID.
This commit is contained in:
@@ -88,7 +88,13 @@ export function set_compose_defaults() {
|
||||
// if they are uniquely specified in the narrow view.
|
||||
|
||||
if (single.has("stream")) {
|
||||
opts.stream = stream_data.get_name(single.get("stream"));
|
||||
// The raw stream name from collect_single may be an arbitrary
|
||||
// unvalidated string from the URL fragment and thus not be valid.
|
||||
// So we look up the resolved stream and return that if appropriate.
|
||||
const sub = stream_sub();
|
||||
if (sub !== undefined) {
|
||||
opts.stream = sub.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (single.has("topic")) {
|
||||
|
@@ -174,7 +174,14 @@ test("set_compose_defaults", () => {
|
||||
["topic", "Bar"],
|
||||
]);
|
||||
|
||||
const stream_and_topic = narrow_state.set_compose_defaults();
|
||||
// First try with a stream that doesn't exist.
|
||||
let stream_and_topic = narrow_state.set_compose_defaults();
|
||||
assert.equal(stream_and_topic.stream, undefined);
|
||||
assert.equal(stream_and_topic.topic, "Bar");
|
||||
|
||||
const test_stream = {name: "Foo", stream_id: 72};
|
||||
stream_data.add_sub(test_stream);
|
||||
stream_and_topic = narrow_state.set_compose_defaults();
|
||||
assert.equal(stream_and_topic.stream, "Foo");
|
||||
assert.equal(stream_and_topic.topic, "Bar");
|
||||
|
||||
|
Reference in New Issue
Block a user