Commit Graph

89 Commits

Author SHA1 Message Date
Steve Howell 7b0c6459b4 Extract static/js/pm_list.js.
This handles most of the details of building the Private Messages
section in the upper left corner of the app.
2016-11-11 12:12:13 -08:00
Steve Howell af794bec7a Remove unused stream_list.get_count(). 2016-11-11 12:12:13 -08:00
Steve Howell 6a3254f83f Clean up how we build individual stream sidebar rows.
We used to have hacky code where various functions would call
build_stream_sidebar_row() to get a jQuery object, and then they
would attach the jQuery object to the "sub" object from stream_data.js.

Now build_stream_sidebar_row() localizes the hack of attaching
a UI object to the "sub" object to just one function (and we can
clean this up in a follow-up commit).

Also, the UI object is now a JS object that can close on some useful
state information like the stream name and encapsulate how we
toggle the inactive_stream class.

Finally, we don't have build_stream_sidebar_row() needlessly append
list items to $('#stream_filters') when we know that our callers are
going to re-build the list anyway.
2016-11-11 12:12:13 -08:00
Steve Howell 13fbb96178 Remove unnecessary call to build_stream_list().
In refresh_pinned_or_unpinned_stream(), we no longer call
build_stream_list(), because that's already called in
update_streams_sidebar().
2016-11-11 12:12:13 -08:00
Steve Howell 16cb2bce8b Remove duplicate loop in build_stream_list().
The code removed in this commit added pinned streams to a list
of elems, only to have them added again by the next block of code
(but more concisely).  Through some strange quirk of appendTo() this
never created user-facing bugs, but you could clearly see in the console
that it was doing double work.
2016-11-11 12:12:13 -08:00
Steve Howell 3b7430ba82 topic lists: Refactor zoom-out logic for un-narrows.
For cases where we are zoomed in to a stream and then go
to a different narrow (Home, PMs, etc.), we now let
topic_list.zoom_out orchestrate the removal of the topic list
instead of stream_list.zoom_out.

This will help us when we move to a world where topic_list
redraws topic lists on zoom-in/zoom-out, because we won't
waste effort rebuilding lists that are about to be removed.
2016-11-10 15:55:31 -08:00
Steve Howell bfc6f57195 topic lists: Move some zooming logic into topic_list.js.
The flow for topic list zooming is kind of complicated now, but
it's mostly a consequence of the way the UI works.

* stream_list tells topic_list to set up the topic list
  click handlers to have callbacks to stream_list
* topic_list click handlers call to stream_list zoom methods
  to hide/show all the other streams
* stream_list zoom methods call back to topic_list methods to
  redraw topics as needed (this isn't happening yet, but allowing
  topic_list.js to know that it's zoomed will set the stage for
  this to happen in a more controlled manner)
2016-11-10 15:55:31 -08:00
Steve Howell 06816d19e6 topic lists: Call narrow.topic() in topic_list.js.
We no longer need stream_list.js to pass in the currently
active topic to us; we just call narrow.topic() for it.
2016-11-10 15:55:31 -08:00
Steve Howell e76422b946 Use narrow.stream() instead of stream_list.active_stream_name().
We no longer use active_stream_name(), which was mostly a
duplicate of narrow.stream().  For nonsensical queries like
"stream:foo stream:bar" the behavior may change slightly here.

We know that we don't handle non-sensical queries particularly
well, but at least if we always go through narrow.stream(),
the behavior will be consistent.

I did test this with some sensible compound narrows, like searching
for a keyword within a stream.
2016-11-10 15:55:31 -08:00
Steve Howell 7509f73f02 Clean up stream renaming in the JS code.
We now use stream_id as our key to rename streams, which
should prevent a few race conditions long term.  (We are
still possibly contending with other events that use
stream_name as a key, so this is not perfect.)
2016-11-04 11:30:18 -07:00
Steve Howell 4ace9bbd77 Remove dead code related to subs.create_sub().
Since we started handling the stream/create event properly,
create_sub() became dead code.
2016-11-04 11:30:18 -07:00
Steve Howell a0dadfd40a Widgetize topic_list.set_count().
This change makes most of the logic on set_count() live
on our per-stream topic list widget.  We can find the
jQuery object directly now rather than using the
complicated iterate_to_find() method.
2016-11-01 19:30:41 -07:00
Steve Howell eb64b32bc8 Fix "subjects" in JS comments. Say "topics" instead. 2016-10-28 13:52:25 -07:00
Steve Howell c799ac3126 Extract stream_data.is_active(). 2016-10-28 13:51:21 -07:00
Steve Howell ecbd77d8a5 Flip conditional in stream_list.add_sidebar_li(). 2016-10-28 13:51:21 -07:00
Steve Howell f98e605840 Extract topic_list.set_click_handlers(). 2016-10-27 15:49:25 -07:00
Steve Howell 8ebf48793c minor: Remove copy/pasted comment. 2016-10-27 15:49:25 -07:00
Steve Howell 9de7551f4f Extract topic_list.rebuild().
This was pulled from rebuild_recent_topics(), which still
exists to wrap passing in the stream_li parameter.
2016-10-27 15:49:25 -07:00
Steve Howell f7e6cfc892 Extract topic_list.build_list().
This used to be stream_list._build_subject_list().  The code
didn't change except for one s/subject/topic fix.
2016-10-27 15:49:25 -07:00
Steve Howell 8783a0e51d Move remove_expanded_topics() to topic_list.js. 2016-10-27 15:49:25 -07:00
Steve Howell 9b6b743a1a Move get_topic_filter_li to topic_list.js.
This also brought along:
    iterate_to_find (copied, see large comment explaining why)
    activate_topic (extracted from a one-liner)
    set_count (formerly stream_list.set_subject_count)

For get_topic_filter_li, we now pass in stream_li instead of
stream to decouple parent/child responsibilities between the
components.

Also, I made some s/subject/topic/ fixes.
2016-10-27 15:49:25 -07:00
Steve Howell 4f38cfdc7f Extract topic_list.update_count_in_dom().
This creates the new topic_list.js module, and the first
function that we extract is topic_list.update_count_in_dom().

This function needed to be decoupled from some non-topic-list
stuff which was overly complicated.
2016-10-27 15:49:25 -07:00
Steve Howell 65a2f012d4 Simplify pin/unpin code path.
I make server_events slimmer by not handling a specific
property when subs.update_subscription_properties() should
do all the dispatching (and mostly did).

And then since update_subscription_properties() has
a "sub" already, I can call directly to stream_list code
and remove a function from subs.js.  Since I lose the
wrapper function in subs.js, I rename the stream_list
function as part of this commit.

The only code that gets slightly heavier here is that
we have two lines in the 'pin_to_top' case instead of one.
2016-10-25 23:29:15 -07:00
Steve Howell 7fd74c45d7 Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.

Now there is a clear separation of concerns, with these methods
being called in succession:

    stream_data.initialize_from_page_params();
    stream_list.create_initial_sidebar_rows();

The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict.  Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.

Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:58:23 -07:00
Steve Howell d26942e72d Extract stream_list.create_sidebar_row().
This replaces add_stream_to_sidebar(), which was kind of a misleading
name, and it also adds a couple lines of code that were always
called right after calling add_stream_to_sidebar().
2016-10-17 19:58:23 -07:00
Steve Howell 0c8c1bb4ae subject/topic: Rename remove_expanded_subjects(). 2016-08-26 20:26:24 -07:00
Steve Howell 93095eca85 subject/topic: Rename rebuild_recent_subjects(). 2016-08-26 20:26:24 -07:00
Kartik Maji f8bb7503e6 Add ability to pin streams to top of the streams sidebar list.
Based on work by Lauren Long, with some tweaks by tabbott.
2016-06-30 22:26:09 -07:00
Michael Cordover a51ec44005 Search streams from left sidebar (resolves #565).
Assigns hotkey 'w' to search streams.
Only show search box when active. Activate with hotkey or by clicking
STREAMS.
Filter matches at the beginning of words in stream name.
Behaviour is otherwise almost identical to user search.
Casper tests.
2016-06-23 17:21:57 -07:00
Tim Abbott 584887e588 lint: Require folding of } on same line in else if statements. 2016-06-09 14:05:34 -07:00
Tim Abbott c35781d505 lint: Require folding of } on same line as else statements. 2016-06-09 14:02:49 -07:00
Vishnu Ks d30ea0bc44 Move recent_subjects to stream_data. 2016-06-07 17:50:16 -07:00
Kara McNair fd66d9f703 Show 5 most recent "Private messages" when clicked.
Like the Stream Subject lists, Private messages are now shown
when the user clicks on the "Private message" link. User can drill in
to get more than 5 conversations. Selecting PMs from the user or group
PM lists on the right sidebar also opens the list & highlights the
selected conversation.

[Edited by tabbott@mit.edu to fix some small bugs.]
2015-12-15 07:52:54 -08:00
Tim Abbott 29fa601328 Rename active-subject-filter to active-sub-filter.
This makes the name more generic so we can reuse it for private
message filters as well.
2015-12-15 07:52:54 -08:00
Tim Abbott 87acb2be09 stream_list: Factor out reset_to_unnarrowed helper. 2015-12-15 07:52:54 -08:00
Tim Abbott c404f3189c stream_list: move remove_expanded_subjects earlier in file. 2015-12-15 07:52:54 -08:00
Tim Abbott 7bb11fe09a topic zoom: Clean up unnecessary jquery selectors. 2015-12-15 07:52:54 -08:00
Allen Rabinovich 7822be5cd9 Fix failing stream sidebar node test
(imported from commit 3187a8f34389bf1f0b37e80edec9fb56f7281306)
2014-02-18 12:50:32 -07:00
Steve Howell 10b24f77b6 Fix misc. uses of search tuples.
(imported from commit c7dc47c1396eb0d9f6821cafcb3dc90d283b4764)
2014-02-10 15:11:43 -05:00
Steve Howell bb0608b55a Use real stream ids in our stream-related UI widgets.
Before this change, we were using sequentially generated ids
on the client side to identify streams.  Now we just use
the ids from the server.  The goal here is to reduce the
confusion of having two different ids attached to a stream.
Also, not that it matters a ton, but this also means that
the browser basically has an immutable id for each stream
that is future-proof to reloads, multiple create_sub calls, etc.
It also a bit easier to grep for ".stream_id" than ".id".

(imported from commit 057f9e50dfee127edfe3facd52da93108241666a)
2014-02-10 13:23:27 -05:00
Tim Abbott 004fd0eab8 Move unread-related functions from zulip.js to unread.js.
(imported from commit efc0dd84c2cd30b0203b906af6991475d8a63985)
2014-01-31 14:59:03 -05:00
Steve Howell bca0311b53 Created stream_list.redraw_stream_privacy().
This function can redraws the lock icon (or lack of lock icon)
for a stream in the stream sidebar.  It can be called when
admins change the stream privacy.

(imported from commit 880133d02525137094c48ecad8cf2dfff59f3307)
2014-01-17 16:38:06 -05:00
Steve Howell 137a1b7799 Rename stream_list.build_narrow_filter() to build_stream_sidebar_row.
The new name is more descriptive of what the function does, and it
also has the side benefit of cleaning up greps for the backend
function called build_narrow_filter().

(imported from commit 4b88fa863d7c1751946c78977f2ffaf19dd3ae5e)
2014-01-17 16:37:46 -05:00
Steve Howell 84ea28ae25 Remove type parameter from build_narrow_filter().
The type parameter was always passed in as "stream", and we
only render the stream_sidebar_row template, so let's not
pretend like we support arbitrary message types here.

(imported from commit 8a852a68ddda336024793f6fdafa648883bb815e)
2014-01-17 16:37:46 -05:00
Steve Howell c7bf349e70 Deprecate stream_list.add_narrow_filter().
We now call add_stream_to_sidebar() instead.  The old function was
only ever called for streams, so the newly named function is more
descriptive of what it does.

(imported from commit 7ae373279ea9987d3637cdbdc427680ac989fe86)
2014-01-17 16:37:45 -05:00
Steve Howell 56dc4e0b8e Add test_add_stream_to_sidebar().
This is a node test that verifies that
stream_list.add_stream_to_sidebar() creates the right
DOM when it renders the stream_sidebar_row template.
The test also makes sure that the DOM gets put in the
correct place to be retrieved by stream_list.get_stream_li()
calls.

(imported from commit ed4c0148da2261870e3db5a9b553913788b4eccd)
2014-01-17 16:37:43 -05:00
Steve Howell fb0c78b946 Remove transitional topic_zooming flag.
(imported from commit 62722f49a2f9db262c63c56826b8446333c86389)
2014-01-02 08:31:36 -05:00
Steve Howell c53845a69c Add unit tests for stream_list.
(imported from commit 1d04a2e6115f29b7949466260ec2ba3126b882e6)
2013-11-27 15:09:20 -05:00
Steve Howell eb9f7a04b7 Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items.  The reproducible bug was that unread counts
on unshown streams weren't updating.

In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.

I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations.  In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).

When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway.  (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)

(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 18:19:49 -05:00
Steve Howell 90bb398784 Revert "[staging] Double-clicking on stream row toggles its zoom level."
This reverts commit 6fdb3cacd68635f313f2a8a81edf2d6101cce2cb.

(imported from commit 6e95bd8caa1b7e327f91a8b7aded72b787d1420a)
2013-11-26 18:19:48 -05:00