Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

2.0 KB
Raw Blame
"use strict";

let last_issued_stream_id = 20000;

const get_stream_id = () => {
    last_issued_stream_id += 1 + Math.floor(Math.random() * 10);
    return last_issued_stream_id;
};

exports.make_stream = (opts = {}) => {
    // Since other fields are computed from these, we need to
    // pull these out of opts early.
    const stream_id = opts.stream_id ?? get_stream_id();
    const name = opts.name ?? `stream-${stream_id}`;

    const default_channel = {
        audible_notifications: false,
        /* BUG: This should always be a group ID. But it's annoying to
         * fix without assuming groups exist in the data set. */
        can_remove_subscribers_group: 0,
        can_administer_channel_group: 2,
        can_create_topic_group: 2,
        color: "abcd12",
        /* This is rarely going to be the case, but a valid possibility. */
        creator_id: null,
        date_created: Date.now(),
        description: `Description of ${name}`,
        desktop_notifications: false,
        email_address: "[email protected]",
        email_notifications: false,
        /* This will rarely be the case, but is a valid possibility*/
        first_message_id: null,
        history_public_to_subscribers: true,
        invite_only: false,
        is_announcement_only: false,
        is_muted: false,
        is_web_public: false,
        message_retention_days: null,
        name,
        newly_subscribed: false,
        pin_to_top: false,
        previously_subscribed: false,
        push_notifications: false,
        rendered_description: `<p>Description of ${name}</p>`,
        stream_id,
        /* STREAM_POST_POLICY_EVERYONE */
        stream_post_policy: 1,
        stream_weekly_traffic: 0,
        /* Most tests want to work with a channel the current user is subscribed to. */
        subscribed: true,
        topics_policy: "inherit",
        wildcard_mentions_notify: false,
        folder_id: null,
    };

    return {...default_channel, ...opts};
};