mirror of https://github.com/zulip/zulip.git
refactor: Extract get_sub_for_target().
This commit is contained in:
parent
a4376efd0f
commit
df6d644788
|
@ -85,12 +85,27 @@ function get_stream_id(target) {
|
||||||
return target.closest(".stream-row, .subscription_settings").attr("data-stream-id");
|
return target.closest(".stream-row, .subscription_settings").attr("data-stream-id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_sub_for_target(target) {
|
||||||
|
var stream_id = get_stream_id(target);
|
||||||
|
if (!stream_id) {
|
||||||
|
blueslip.error('Cannot find stream id for target');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sub = stream_data.get_sub_by_id(stream_id);
|
||||||
|
if (!sub) {
|
||||||
|
blueslip.error('get_sub_for_target() failed id lookup: ' + stream_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return sub;
|
||||||
|
}
|
||||||
|
|
||||||
// Finds the stream name of a jquery object that's inside a
|
// Finds the stream name of a jquery object that's inside a
|
||||||
// .stream-row or .subscription_settings element.
|
// .stream-row or .subscription_settings element.
|
||||||
function get_stream_name(target) {
|
function get_stream_name(target) {
|
||||||
var stream = stream_data.get_sub_by_id(get_stream_id(target));
|
var sub = get_sub_for_target(target);
|
||||||
if (stream) {
|
if (sub) {
|
||||||
return stream.name;
|
return sub.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue