Commit Graph

82 Commits

Author SHA1 Message Date
Steve Howell 6fc45fd941 left sidebar: Disable "gray-out" feature for new users.
If a user has 30 subscribed streams or less, don't gray
them out if they haven't had recent activity.
2019-02-12 17:43:48 +00:00
Hemanth V. Alluri 683ec852fd stream_data: Use stream rendered_description provided by the backend.
Use the results of commit #73d26c8 to remove the method
`render_stream_description` in static/js/stream_data.js and instead
use the rendered_description attribute now being sent by the backend.

This will be a valuable optimization and a step towards removing the
need for the marked.js markdown parser and speeding up the client end.
2019-02-11 12:24:27 -08:00
Shubham Dhama fbd73ba637 stream_data: Add get_invite_stream_data helper function.
This function unlike `invite_streams()` returns an array of objects having
various info (name, stream_id, invite_only, default_stream) related to
streams rather than an array of names of streams.
2019-02-01 15:35:42 -08:00
Steve Howell 625388ccf0 refactor: Call stream_data.initialize() more directly.
This function used to be called initialize_from_page_params(),
and we called it indirectly through `subs.js`.

Now we call it directly from `ui_init.js`, which gives us a
bit more control over how things are initialized.  In fact,
this sets us up for the next commit, where I fix a recent
regression I introduced.
2018-12-15 13:44:30 -08:00
Steve Howell ba243416e3 stream_color: Make stream color assignment more efficient.
We now let color_data keep its own state for
unused_colors, so that we longer have to pass in
a large list of unused_colors every time we want
to assign a new stream color.

This mostly matters at startup, where we might
be cycling through 5000 streams.  We claim all
the unused colors up front.

Each operation now has an upper bound of expensiveness,
where the worst case scenario is basically popping
off the first element of a list of <= 24 colors.

The algorithm is now deterministic, too, to make
it easier to test.  It's unclear whether random color
assignment ever had much benefit, and it made unit
testing the algorithm difficult.  Now we have 100%
line coverage.

Fixes part of #10902.
2018-11-29 13:00:25 -08:00
Steve Howell 6035304619 Extract color_data.js.
This code is pretty distinct from all the color-picking UI,
and we want to get it to 100% coverage and optimize it
more.
2018-11-28 14:51:51 -08:00
Steve Howell ecb3879d0c refactor: Break subs dependency in stream_data.
We move remove_deactivated_user_from_all_streams
into stream_events.js.  There were some minor changes
to rename variables and also to not rely on using
`stream_info`.
2018-08-04 14:06:19 -07:00
Steve Howell ab26e27fef Move stream-related uri helpers to hash_util.
This allows several modules to no longer need
to import `narrow` (or, in our current pre-import
world, to not have to use that global).

The broken dependencies are reflected in the node
tests, which should now run slightly faster.
2018-08-04 09:32:27 -07:00
Shubham Dhama db4ee05653 stream_data: Add helper function to get default streams. 2018-08-04 09:27:16 -07:00
Steve Howell 064d0f3c89 Extract stream_data.sort_for_stream_settings().
We move some data code from subs.js to stream_data.js.

It's not clear we have been using the optimal sort for
dealing with locales, but this change preserves the
current behavior.  The only subtle change here is that
we look up subs using a Dict now instead of a plain
JS object.
2018-07-30 11:25:32 -07:00
Rohitt Vashishtha 5b36a30163 zblueslip: Convert node_tests/stream_data.js to zblueslip. 2018-07-10 16:22:52 -04:00
Rohitt Vashishtha 92259094b7 node_tests: Add missing stream_id field to tests in stream_data.
These were resulting in inadvertant calls to blueslip.fatal but
the code continued beyond that point, since in our testing environment
we do not stop executing when fatal is called.

This commit also adds checks to ensure that the subs were created.
2018-07-10 16:22:52 -04:00
Tim Abbott 106d06b235 streams: Rename change_change_subscription_type to reference permissions.
This is a preparatory refactor for when we start having other
permissions options available in this UI (e.g. announcement-only streams).
2018-05-21 16:14:18 -07:00
Tim Abbott 9df3480263 streams: Remove now-obsolete can_make_public and can_make_private.
Now that we've moved it into a bulleted set of options inside a modal,
there's no good reason to have separate variables for the corner cases
around who can manage a stream.
2018-05-21 16:12:50 -07:00
Shubham Padia 10a65a62db compose: Display error for non-admin trying to post to announce_only stream.
Partially fixes #4708.
Implements a first version (v1) for the feature. The next step would be
to allow admins to toggle `is_announcement_only` in the UI.
2018-05-16 13:35:45 -07:00
Steve Howell 42435db492 Add run_test helper for individual tests.
This run_test helper sets up a convention that allows
us to give really short tracebacks for errors, and
eventually we can have more control over running
individual tests.  (The latter goal has some
complications, since we often intentionally leak
setup in tests.)
2018-05-15 08:24:44 -07:00
Tim Abbott 6e149a7594 lint: Add JS indentation eslint rules for node_tests.
The only difference between this as the main project's lint rules is
that we dont have the OuterIIFE setting.
2018-05-06 19:35:18 -07:00
Tim Abbott 0ada5fa9d8 stream_data: Fix exception when notifications_stream is private.
If notifications_stream is private and the current user has never been
subscribed, then we would throw an exception when trying to look up
notifications_stream.  In this situation, we should just treat it like
the stream doesn't exist for the purposes of this user.
2018-05-03 08:33:07 -07:00
YJDave 24f51739eb subscription: Add real time sync for user-just-deactivated case.
Currently, stream subscriptions aren't getting updated without
hard reload when user is deactivated in realm.

Fix this issue by updating stream subscription widgets on user
deactivation event.

Fixes #5623
2018-04-08 16:54:12 -07:00
YJDave 386c56b466 stream_data.js: Replace user_email with user_id in func is_user_subscribed. 2018-04-08 16:54:12 -07:00
YJDave f15ddc93e0 create stream: Fix stream email not rendering on stream creation.
Fixes #8817
2018-04-07 20:10:45 -07:00
YJDave 2cbfcbb740 subscription: Fix unexpected blueslip warnings on add subscriber.
In stream settings, if user add subscriber to unsubscribed public
stream from `Add` input widget it gives lots of blueslip warnings,
cause user isn't subscribed to public stream.

Fix this by changing condition to `sub.can_access_subscriber` from
`sub.subscribed` in blueslip warning, cause user can access
subscribers in such cases even if not subscribed to stream.

Tweaked by tabbott to make the node tests pass.
2018-03-19 10:24:14 -07:00
YJDave 8cd3e55fae default stream: Fix default stream suggestion do not include private stream.
Private streams were not included in stream suggestions for default streams
in org settings.
Remove function, which exclude private streams from stream suggestions
for default streams.
2018-03-04 13:42:28 -08:00
cPhost 470e57db49 node tests: Enforce 100% coverage for stream_data.js. 2017-12-28 09:39:45 -05:00
cPhost 154436140b node tests: Cover stream_data.delete_sub. 2017-12-28 09:39:45 -05:00
cPhost 0966f4737b node tests: Cover stream_data.get_newbie_stream. 2017-12-23 07:32:18 -05:00
cPhost 7f4e57ddff node tests: Cover stream_data.initialize_from_page_params. 2017-12-18 09:19:05 -05:00
Jerry Zhang 14d1902386 node tests: Cover exports.create_sub_from_server_data. 2017-12-11 11:13:55 -06:00
cPhost 63e8248933 node tests: Cover stream_data.canonicalized_name. 2017-12-10 04:20:29 -08:00
cPhost 0b9e678d4d node test: Cover stream_data.render_stream_description. 2017-12-10 04:20:29 -08:00
cPhost d2a2d0b362 node tests: Cover stream_data.get_subscriber_count. 2017-12-10 04:19:33 -08:00
cPhost 7504d01066 node tests: Cover stream_data.remove_default_stream. 2017-12-07 15:05:44 -08:00
Jerry Zhang 48ebec3a29 node tests: Cover exports.get_default_status. 2017-12-07 15:02:12 -08:00
Jerry Zhang 806e9bb742 node tests: Cover exports.remove_subscriber. 2017-12-07 14:57:15 -08:00
Jerry Zhang b874693242 node tests: Cover exports.user_is_subscribed. 2017-12-07 14:57:15 -08:00
cPhost bbdf9f0306 node tests: Cover stream_data.notifications_in_home_view 2017-12-05 16:30:36 -08:00
cPhost cd9c066c0b node tests: Cover stream_data.name_in_home_view 2017-12-05 16:30:36 -08:00
Jerry Zhang 164fe28c5b node tests: Cover exports.receives_audible_notifications. 2017-12-03 13:54:41 -08:00
Jerry Zhang f0d8ce009c node tests: Cover exports.receives_desktop_notifications. 2017-12-03 13:54:41 -08:00
Steve Howell 3846e60a71 Add stream_data.get_streams_for_admin(). 2017-08-27 19:08:04 -07:00
Steve Howell 106d58df47 Add stream_data.get_non_default_stream_names().
This allows us to get the typeahead values for adding a default
stream using client-side data.
2017-08-27 19:08:04 -07:00
Steve Howell 7cfc73b040 Use zrequire in node_tests/stream_data.js. 2017-08-09 12:32:09 -07:00
Joshua Pan f253d741dd Add tests for stream_data.maybe_get_stream_name(). 2017-08-01 16:19:41 -07:00
Steve Howell 466757c3f1 node tests: Extract topic_data.js.
This mostly moves code, and it also removes some unnecessary
coupling to stream_data.js.  The topic_data code purely
works in the stream_id space, so there's no need to set up
actual stream data for it.
2017-07-27 14:26:22 -07:00
Steve Howell a9e296db74 Remove topic_data.process_message().
We now call topic_data.add_message() and
topic_data.remove_message() when we get info about
incoming messages.  The old way of passing in a boolean
made the calling code hard to read and added unncessary
conditional logic to the codepath.

We also have vague plans to change how we handle
removing topics, since increment/decrement logic is now
kind of fragile, so making the "remove" path more explicit
prepares us to something smarter in the future, like just
figure out when the last topic has been removed by calling
a filter function or something outside of topic_data.js.

Another thing to note here is that the code changed here
in echo.js is dead code, since we've disabled
message editing for locally edited messages.  I considered
removing this code in a preparatory commit, but there's
other PR activity related to local echo that I don't want
to conflict with.

One nice aspect of removing process_message() is that
the new topic_data.js module does not refer to the legacy
field "subject" any more, nor do its node tests.
2017-07-27 14:26:22 -07:00
Steve Howell 5a8bccfe08 topic_data.js: Refactor topic history internals.
This commit introduces a per-stream topic_history class
inside of topic_data.js to better encapsulate how we store topic
history.

To the callers, nothing changes here.  (Some of our non-black-box
node tests change their way of setting up data, though, since the
internal data structures are different.)

The new class has the following improvements:

    * We use message_id instead of timestamp as our sorting key.
      (We could have done this in a prep commit, but it wouldn't
      have made the diff much cleaner here.)

    * We use a dictionary instead of a sorted list to store the
      data, so that writes are O(1) instead of O(NlogN).  Reads
      now do sorts, so they're O(NlogN) instead of O(N), but reads
      are fairly infrequent.  (The main goal here isn't actually
      performance, but instead it just simplifies the
      implementation.)

    * We isolate `topic_history` from the format of the messages.
      This prepares us for upcoming changes where updates to the
      data structure may come from topic history queries as well
      as messages.

    * We split out the message-add path from the message-remove
      path.  This prepares us to eventually get rid of the "count"
      mechanism that is kind of fragile and which has to be
      bypassed for historical topics.
2017-07-27 14:26:22 -07:00
Steve Howell bc0761b22b Extract topic_data.js.
This new module tracks the recent topic names for any given
stream.

The code was pulled over almost verbatim from stream_data.js,
with minor renames to the function names.

We introduced a minor one-line function called stream_has_topics.
2017-07-27 14:26:22 -07:00
Steve Howell b95e785335 recent topics: Extract get_recent_topic_names().
We now have all of our callers into recent_topics code just
receive a list of topic names from get_recent_topic_names().

This is more encapsulated than handing off tiny little
structures to the three callers, two of whom immediately
mapped the objects to names, and one of whom needlessly
used the now defunct name canon_subject field.

The consolidation here removes some "subject" references, and
now all lookup are by stream id, not stream name.

The diff here is a bit daunting, but it's mostly simplification
of tests and calling code.  Two of the callers now need to look
up stream ids, but they are otherwise streamlined.

The main change here is to stream_data.js, and we replace the
`canon_subject` and `subject` fields with `name`.
2017-07-27 14:26:22 -07:00
Aditya Bansal 7531a85c4d stream_data: Add get_subscriber_count() function. 2017-06-29 10:34:47 -04:00
Steve Howell 6c722843ef node tests: Fix namespace leaks related to require().
The node tests have purged modules from cache that were
included via things like set_global(), but calling require
directly would leak modules into the next test, which made
a couple tests only work when you ran the whole suite.  I
fixed those tests to work standalone.  And then I now make
dependencies explicitly clear the require cache before we
require them in namespace.js.
2017-06-19 22:36:58 -04:00