streams: Add support for setting stream description during creation.

Add new box for stream description in the stream creation form,
modify backend so its contents end up as the stream description.

Fixes: #2283.
This commit is contained in:
Calvin Lee 2016-11-20 14:33:41 -05:00 committed by Tim Abbott
parent b8d7f8008a
commit 4e5c4c5ffb
3 changed files with 18 additions and 6 deletions

View File

@ -637,17 +637,18 @@ function hide_new_stream_modal() {
$('#stream-creation').modal("hide");
}
function ajaxSubscribeForCreation(stream, principals, invite_only, announce) {
function ajaxSubscribeForCreation(stream, description, principals, invite_only, announce) {
// Subscribe yourself and possible other people to a new stream.
return channel.post({
url: "/json/users/me/subscriptions",
data: {"subscriptions": JSON.stringify([{"name": stream}]),
data: {"subscriptions": JSON.stringify([{"name": stream, "description": description}]),
"principals": JSON.stringify(principals),
"invite_only": JSON.stringify(invite_only),
"announce": JSON.stringify(announce)
},
success: function (data) {
$("#create_stream_name").val("");
$("#create_stream_description").val("");
$("#subscriptions-status").hide();
hide_new_stream_modal();
// The rest of the work is done via the subscribe event we will get
@ -813,6 +814,7 @@ $(function () {
$("#stream_creation_form").on("submit", function (e) {
e.preventDefault();
var stream = $.trim($("#create_stream_name").val());
var description = $.trim($("#create_stream_description").val());
if (!$("#stream_name_error").is(":visible")) {
var principals = _.map(
$("#stream_creation_form input:checkbox[name=user]:checked"),
@ -823,6 +825,7 @@ $(function () {
// You are always subscribed to streams you create.
principals.push(page_params.email);
ajaxSubscribeForCreation(stream,
description,
principals,
$('#stream_creation_form input[name=privacy]:checked').val() === "invite-only",
$('#announce-new-stream input').prop('checked')

View File

@ -12,6 +12,11 @@
placeholder="{{ _('Stream name') }}" value="" autocomplete="off" />
<div id="stream_name_error"></div>
</div>
<div>
<b>{% trans %}Stream description (optional){% endtrans %}</b><br />
<input type="text" name="stream_description" id="create_stream_description"
placeholder="{{_('Stream description') }}" value="" autocomplete="off" />
</div>
<div id="make-invite-only">
<b>{% trans %}Stream accessibility{% endtrans %}</b><br />
<label class="radio">

View File

@ -963,11 +963,13 @@ def do_create_stream(realm, stream_name):
subscribers = UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)
bulk_add_subscriptions([stream], subscribers)
def create_stream_if_needed(realm, stream_name, invite_only=False):
# type: (Realm, text_type, bool) -> Tuple[Stream, bool]
def create_stream_if_needed(realm, stream_name, invite_only=False, stream_description = ""):
# type: (Realm, text_type, bool, text_type) -> Tuple[Stream, bool]
(stream, created) = Stream.objects.get_or_create(
realm=realm, name__iexact=stream_name,
defaults={'name': stream_name, 'invite_only': invite_only})
defaults={'name': stream_name,
'description': stream_description,
'invite_only': invite_only})
if created:
Recipient.objects.create(type_id=stream.id, type=Recipient.STREAM)
if not invite_only:
@ -985,7 +987,9 @@ def create_streams_if_needed(realm, stream_dicts):
for stream_dict in stream_dicts:
stream, created = create_stream_if_needed(realm,
stream_dict["name"],
invite_only=stream_dict.get("invite_only"))
invite_only=stream_dict.get("invite_only", False),
stream_description=stream_dict.get("description", ""))
if created:
added_streams.append(stream)
else: