Commit Graph

161 Commits

Author SHA1 Message Date
Steve Howell 57f17ae543 Extract top_left_corner.js.
Here are the functions in top_left_corner:

    get_global_filter_li: pure code move
    update_count_in_dom: simplifed copy of similar function in stream_list.js
    update_dom_with_unread_counts: pure code move, split out from function
       of same name in stream_list.js
    delselect_top_left_corner_items: pure code move
    handle_narrow_activated: pure code move + rename
    handle_narrow_deactivated: pure code move, split out from from function
       of smae name in stream_list.js
2017-08-14 13:03:57 -07:00
Steve Howell 0f3b565d40 Create explicit handlers for stream activate/deactivate.
Calling explicit functions ensurest that the sidebars
get activated for narrows before less important things
happen, and it also makes testing easier.
2017-08-14 13:03:57 -07:00
Steve Howell 8655fae910 Make deselect_top_left_corner_items() more accurate.
This function was actually de-selecting stream sidebar items
before.  Now we just explicitly de-select top-left items in it,
and we do stream-sidebar stuff in update_stream_sidebar_for_narrow().
2017-08-14 13:03:57 -07:00
Steve Howell 24e9dbe80b Use data-stream-id for zooming topics. 2017-08-11 13:01:39 -07:00
Steve Howell fad024ebda Simplify stream sidebar narrows.
This fix simplifies how we re-render topic lists when we
re-narrow or zoom out from a topic list.

    * The topic_list.zoom_out() no longer gets called as
      part of re-narrowing, and we eliminate the clear_topics
      option.

    * For all situations where we narrow to a filter that does
      not have a topic, we simply call the new function
      clear_topics().

    * The stream_list code no longer calls remove_expanded_topics()
      in cases where the new narrow has a topic.  This allows us
      to optimize away scroll/flicker churn a little more easily.

As part of this, we rename maybe_activate_stream_item() to
update_stream_sidebar_for_narrow(), since the function clears
stuff as well as turning stuff on.
2017-08-11 13:01:39 -07:00
Steve Howell 089670ac1c Extract stream_list.show_all_streams(). 2017-08-11 13:01:39 -07:00
Steve Howell d2686bdcdd Simplify maybe_activate_stream_item().
We extract get_sidebar_stream_topic_info() and just call
topic_list.rebuild() directly, which allows us to eliminate
rebuild_recent_topics().
2017-08-11 13:01:39 -07:00
Steve Howell cd4dd90641 Extract stream_list.update_top_left_corner_for_narrow().
This is mostly a pure code extraction.  It makes the call
to reset_to_unnarrowed() happen later in sequence.

The order of operations here is mostly unimportant, but
there may actually be some tiny user-facing benefit
in terms of having the logic happen more sequentially.

BEFORE:
    reset streams
    fix top left
    redraw streams

AFTER:
    fix top left
    reset streams
    redraw streams
2017-08-11 13:01:39 -07:00
Steve Howell c5d95a2db8 stream list: Rename method to scroll_stream_into_view.
The old name was scroll_to_active_stream, but it can be used
when pinning a stream, so "active" isn't necessarily accurate.
2017-08-11 13:01:39 -07:00
Steve Howell 9201137059 Fix scrolling glitches when zooming out to streams.
If you go into "more topics" for a stream with many topics,
and then scroll down, and then zoom out again with "All
streams", we make sure the active stream is still in view.
2017-08-11 13:01:39 -07:00
Steve Howell 9dd78c803c Make auto-scrolling less aggressive.
We have code that can automatically scroll an element into "view"
in its container.  We use this for stream sidebar rows inside the
stream list.

Generally the stream sidebar rows are small enough to fit into
the container, and the prior algorithm worked correctly for that
scenario.

If you have lots of topics, however, and a short screen, the
algorithm was being too aggressive.  For example, if the top
wasn't showing, it would scroll the top into view, but at the
cost of scrolling the bottom out of view.

This fix makes the general scrolling algorithm more tame.

Part of the user-facing problem is that the element we pass
into the scrolling code for the stream sidebar rows is bigger
than the part of the row that actually should be shown on
screen.  Nevertheless, it makes sense here to make the general
algorithm more robust.
2017-08-11 13:01:39 -07:00
Steve Howell c11c5c3795 Extract stream_list.scroll_delta() and add tests. 2017-08-11 13:01:39 -07:00
Steve Howell fe74e79a17 Rename subject_count -> topic_count.
This fixes all names in the JS codebase.
2017-07-31 08:04:20 -04:00
Cory Lynch d32e89aae4 jQuery: Remove broken use of "removeAttr".
This function no longer sets properties to false, so the supported
way of doing this is to instead use prop(foo, false). Some tests
had to be fixed to accommodate this.
2017-07-24 10:54:47 -07:00
Steve Howell 1ed35be88c stream_list: Use more direct code in build_stream_list.
We eliminate `.get(0)` calls in buld_stream_list.

The easy case is that we stop building jQuery objects
for the splitters only to pull out the DOM immediately.

The more subtle case is that we also don't do `.get(0)` calls
to get DOM out of our individual list items.  By passing
in full jQuery objects to `append()`, we should prevent ourself
from orphaning the old objects, which may in the future have
things like tooltip logic attached to them.
2017-07-18 09:58:16 -07:00
Harshit Bansal d3d6712fa3 left-sidebar: Update the size of the scrollbar after narrowing to a stream. 2017-07-03 09:53:41 -07:00
Steve Howell 29416c4b39 Move pm_list.set_click_handlers() call.
Instead of calling it from stream_list.initialize(), we
call it from the new pm_list.initialize().
2017-06-14 13:58:54 -04:00
Steve Howell 499962bb6b Change arg for stream_list.redraw_stream_privacy().
We now pass in a sub, not a stream name.
2017-06-14 11:24:42 -04:00
Steve Howell fb5d10af14 Extract stream_list.get_global_filter_li().
Now we use a consistent approach to find the list items for
Home/Starred messages/Mentioned in the upper corner.

In particular, we get rid of the complicated
iterate_to_find() function.
2017-06-14 09:27:50 -04:00
Steve Howell 7c2683d765 minor: Export stream_list.update_count_in_dom() for testing. 2017-06-13 18:37:02 -04:00
Steve Howell 79acbcd1bf Refine error handling for stream_list.get_stream_li calls.
We avoid false warnings in get_stream_li and for updating
unread counts.  We also early-exit for A/D keys if there is
no current stream.
2017-06-03 06:16:45 -06:00
Steve Howell 24d443a061 Have stream_list.get_stream_li() use stream_sidebar.get_row().
Given a stream id, we now find list items using the internal
data structures we created when we built the sidebar, rather than
using a jQuery selector.
2017-06-02 16:32:39 -07:00
Steve Howell ed49673555 stream_list: Use append() instead of appendTo().
Using append() is easier to unit test, and we avoid
creating a temporary jQuery object from the array
of sidebar rows.
2017-06-02 14:11:11 -07:00
Steve Howell fdea8f9334 Create stream_list.initialize(). 2017-06-02 14:11:11 -07:00
Steve Howell e7345bdd7f Improve error reporting in maybe_activate_stream_item.
This change should lead to clearer tracebacks when our
assumption about the stream list's list items get
violated, and we also short circuit some code in the
caller that tries to scroll to the active stream.
2017-05-30 21:26:55 -07:00
Steve Howell 561fba65d2 Remove spurious call to unread_ops.process_visible().
In stream_list.js we have some code to handle narrow activations,
and we were calling unread_ops.process_visible() only for
stream activations, not for PM-related activations, etc., so
our approach was inconsistent.

It also turns out that the call is redundant, since we call
unread_ops.process_visible() when the message pane scrolls as
part of updating the content.

Ideally, we want a more rigorous approach where we make this
call precisely when the new messages become visible to the user,
but the purpose of this fix is to de-clutter the stream_list
logic.
2017-05-30 21:26:55 -07:00
Rohitt Vashishtha 2d73e03e37 ui-refactor: Rename modals.js to overlays.js.
Fixed #4702.
2017-05-29 11:24:46 -07:00
Steve Howell 8eb9723283 stream_list: Call update_streams_sidebar() on renames.
If you rename a stream, call update_streams_sidebar() to
make sure we redraw the active stream correctly.
2017-05-15 14:47:41 -07:00
Steve Howell 76f68e9836 Fix buggy update_streams_sidebar().
If you were narrowed to an unpinned stream, and then pinned it,
we were mostly redrawing the sidebar correctly, but we weren't
setting the active-filter class.  Now we accomplish this by
calling maybe_activate_stream_item(), which also reduces some
code duplication.  (The new code introduces a bit of extra logic
to do `stream_li.addClass('active-filter')`.
2017-05-15 14:47:41 -07:00
Steve Howell 5b6bd6767b refactor: Extract stream_list.maybe_activate_stream_item(). 2017-05-15 14:47:41 -07:00
Steve Howell 1a11042fdf refactor: Use stream id more in topic_list.js. 2017-05-15 14:47:41 -07:00
Steve Howell 762194f98d Add stream_data.id_is_subscribed().
We use this function in stream_list.js.
2017-05-15 14:47:41 -07:00
Steve Howell 5d33d02235 Track unread counts using stream_id. 2017-05-15 14:47:41 -07:00
Steve Howell c125ba1d08 Fix how we find if streams are muted.
This commit changes stream_data.in_home_view() to
take a stream_id parameter, which will make it more
robust to stream name changes.

This fixes a bug.  Now when an admin renames a stream
you are looking at, it will correctly show itself to
be un-muted. (Even with this fix, though, the stream
appears to be inactive.)

Some callers still do lookups by name, and they will
call name_in_home_view() for now, which we can
hopefully deprecate over time.
2017-05-15 14:47:41 -07:00
Steve Howell d3a7aa3a37 Have get_stream_li() take a stream_id.
Rather than having get_stream_li() look up stream id using
stream name, we force the callers to pass in the stream id.

This adds an extra line to most of the callers for now, but
this will eventually change as we fix some of the callers to
have their callers pass in stream_id.

In places where we now call stream_data.get_stream_id() to
get the stream id, we will be more resilient toward stream
renamings, at least until the next reload, since
stream_data.get_stream_id() can resolve old names that
are stored when we process stream-rename events.
2017-05-15 14:47:41 -07:00
Steve Howell a48419310e Simplify get_filter_li() and get_stream_li().
We no longer have get_stream_li() delegate to get_filter_li(),
which simplifies the logic in get_filter_li() and makes
get_stream_li() more direct.

We also move the two functions closer to each other in the file.
2017-05-15 14:47:41 -07:00
Steve Howell 292b0ac64d Extract set_stream_unread_count. 2017-05-15 14:47:41 -07:00
Steve Howell cfdf256c62 refactor: Call get_stream_li() in a few places.
This is a step toward simplifying get_filter_li().
2017-05-15 14:47:41 -07:00
Steve Howell 742c55f514 Speed up key handling by adding modals.is_active().
The function modals.is_active() can see if modals are open
without having to look at the DOM.  This should make it snappier
to type in the compose box.  Even if the speedup is pretty minor,
not having to worry about jQuery slowness should make it easier
to diagnose future compose box issues.

The new function gets used in other places, too, where performance
isn't so much an issue.
2017-05-08 22:04:56 -07:00
Steve Howell 23df948457 left sidebar: Scroll to newly pinned streams.
If we pin a stream, we now scroll up as needed to make sure the
stream is still in view after pinning it.  (Note that we don't do
this in the un-pinning case, since users un-pinning stuff may be
doing cleanup on pinned streams they no longer care about.)

Fixes #1714.
2017-05-01 16:39:37 -07:00
Steve Howell 07633b3872 left sidebar: Scroll to newly activated streams.
When we activate a stream (or one of its topics), we now scroll
the sidebar so that the stream comes into view.  We scroll it
just enough to get it to the top or the bottom, depending on
where it had been offscreen before.
2017-05-01 16:39:37 -07:00
Steve Howell f9b3ff8f68 Change argument type for stream_data.is_active().
The function now takes a "sub" object instead of a stream
name.
2017-04-28 07:39:52 -07:00
Brock Whittaker c506a92d05 left-sidebar: Restyle to have new look.
This restyles the color swatches to either be locks or hashes,
and changes the notifications to be rounded rather than squared.
2017-04-25 17:47:36 -07:00
Steve Howell 8eb86335b9 Extract narrow_state.js.
Despite the length of this commit, it is a very straightforward
moving of code from narrow.js -> narrow_state.js, and then
everything else is just s/narrow.foo()/narrow_state.foo()/
(with a few tiny cleanups to remove some code duplication
in certain callers).

The only new functions are simple setter/getters that
encapsulate the current_filter variable:

    narrow_state.reset_current_filter()
    narrow_state.set_current_filter()
    narrow_state.get_current_filter()

We removed narrow.predicate() as part of this, since it was dead
code.

Also, we removed the shim for narrow_state.set_compose_defaults(),
and since that was the last shim, we removed shim.js from the app.
2017-04-25 09:57:32 -07:00
Tim Abbott 326cf9a73e stream_list: Add divider before dormant streams in list.
Fixes #4309.
2017-04-19 09:18:29 -07:00
Steve Howell 7962710132 Remove 40-streams criterion for flagging dormant streams.
Before this change, we would move "dormant" streams to the bottom
of your stream sidebar, but only if you had 40+ streams.

Now we do this in all cases to be more consistent.

This commit also changes the redraw strategy when we remove rows.
Before this change, we were doing incremental updates, but now we
call build_stream_list to do a complete rebuild.  This was partly
motivated by adding the new divider, which would have complicated
the incrememental approach when you removed the last remaining
dormant stream.
2017-04-19 09:18:18 -07:00
Steve Howell 9591b3a95b Extract stream_sort.js. 2017-04-19 09:16:37 -07:00
Raghav Jajodia d4e1f0a9a8 stream_filter: Add clear-search button to Search stream input field. 2017-04-17 11:12:01 -07:00
Brock Whittaker ffa654f780 left-sidebar: Remove <hr> divider if last pinned stream is unpinned.
The <hr> is supposed to separate the pinned streams from the unpinned
streams, so if the <hr> is the first element (checked by doing
$hr.prev().length === 0), then it means there are no longer any pinned
streams and therefore it isn’t necessary to have a divider.

Fixes: #4395.
2017-04-11 17:06:37 -07:00
Steve Howell d026344b37 Extract js/ui_util.js. 2017-03-19 11:05:45 -07:00