Commit Graph

1012 Commits

Author SHA1 Message Date
Tim Abbott 9081f2cf44 reactions: Store the emoji codepoint in the database.
This is the first part of a larger migration to convert Zulip's
reactions storage to something based on the codepoint, not the emoji
name that the user typed in, so that we don't need to worry about
changes in the names we're using breaking the emoji storage.
2017-08-15 09:29:27 -07:00
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
Harshit Bansal 99d3668523 emoji_picker: Change emoji picker to be category based. 2017-08-14 12:52:35 -07:00
Steve Howell 60cca43d5e Always show "more topics" link if you have server history.
Until we have an easy way to consistently determine whether a
stream has more topics than have been loaded already, we err
on the side of showing a "more topics" link.  This in some ways
leads to a more consistent experience where you can zoom in on
any stream, even one that's really new.
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 2146e17709 node tests: Improve topic_list tests.
We test a little deeper now, covering rebuild (albeit mostly with
stubs) and active_stream_id.
2017-08-11 13:01:39 -07:00
Steve Howell f706efe12e Add topic_list.active_stream_id(). 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 5608dc0add Fix bug with topic edits on read messages.
If you read a message, then got a topic edit for it, we were
adding the message to our data structure of unread stream/topic
messages.

Now we guard against this in unread.update_unread_topics. I
no longer expose an update() method in unread_topic_counter,
since we really want to do the unread check at a higher level
to keep other data structures consistent.
2017-08-10 14:36:18 -04:00
Steve Howell e64277879f Use zjquery to test topic_list.js.
We no longer use real jQuery to test topic_list.  This changes
the nature of the tests to be higher level checks on how the DOM
is constructed.  The actual details of how templates get
rendered should be in templates.js.
2017-08-09 12:32:09 -07:00
Steve Howell 5c5ce3c1b9 Use zjquery in user_events test.
We don't use zjquery in a meaningful way, but we need to be careful
about leaking the real version of jQuery from prior tests.
2017-08-09 12:32:09 -07:00
Steve Howell 779a29e70e Use zrequire in node_tests/stream_list.js. 2017-08-09 12:32:09 -07:00
Steve Howell 7cfc73b040 Use zrequire in node_tests/stream_data.js. 2017-08-09 12:32:09 -07:00
Steve Howell 890794ac8f Use zrequire in node_tests/pm_list.js. 2017-08-09 12:32:09 -07:00
Steve Howell d6b618e2eb Use zrequire in node_tests/activity.js. 2017-08-09 12:32:09 -07:00
Steve Howell 9e054c8b3b Use zrequire in node_tests/narrow.js. 2017-08-09 12:32:09 -07:00
Steve Howell 2f775c3e0b node tests: Extract zrequire helper.
We are phasing out the following in tests:

    add_dependencies - this is just kind of a clunky UI
    require - normal JS requires cause test leaks

In order to plug require leaks, we are effectively doing what
we always have done inside of add_dependencies, which is to
keep track of which modules we have done `require` on, and
these get cleared between tests.

Now we just use `zrequire` every time we want to pull in real
code to our global namespace.
2017-08-09 12:32:09 -07:00
Steve Howell 3b88e592d0 Add topic_data.get_server_history().
This isn't connected to anything yet, but you can now get
all the historical topics for a stream by calling
topic_data.get_server_history().
2017-08-08 17:07:09 -04:00
Jack Zhang c69b5d7d65 hotkey: Add support for hotspots on enter. 2017-08-05 18:32:37 -07:00
Steve Howell ff54d52589 Extract message.set_read_flag().
This code adds 'read' to message.flags and sets message.unread
to false.

It's not clear that the boolean message.unread is used in any
meaningful way, but we set it to false to avoid confusion.  The
bankruptcy code was not doing this before.

Another quirk that existed before was that you could get two
'read' flags in a message when you declared bankruptcy.  It's
also plausible that this could happen if you marked a message
as read via two different ways.  It probably did not cause
user-facing bugs, but it would be confusing for troubleshooting.

Fixes #5032.
2017-08-04 13:31:26 -07:00
Steve Howell 7cae3fa916 Use bucketers in unread_topic_counter. 2017-08-04 13:31:26 -07:00
Steve Howell 241f095213 Extract unread_ops.process_read_messages_event().
The new method borrows some code from the event loop
and unread_ops.mark_messages_as_read, and it is now
flexible about message_ids being marked as unread
even when there is no corresponding message in the
message store.  For that scenario we still want to
update our data structures, which wasn't happening
before this change.  (Generally, this was a non-issue
up until now, but it will become a bigger issue when
we start loading unread message ids from the server.)
2017-08-04 13:31:26 -07:00
Steve Howell 8125667f90 Add unread.id_flagged_as_unread().
This function allows us to see whether unread.js thinks a message
id is unread (as opposed to looking at the message itself).  This
method is useful when we get notifications from the server that a
message has been read.  In the future, we may not actually have
a local copy of an unread message, but we'll still know that it is
unread based on page_params.  We'll want to update the data in that
case.

Going forward, we'll want to deprecate message.flags for most use
cases and just use the unread.js data structures to track unread
messages.
2017-08-04 13:31:26 -07:00
Steve Howell c32b9a5d19 Remove dead code related to unread_in_current_view. 2017-08-03 11:32:54 -07:00
Steve Howell 325d7f0f57 unread: Simplify code to mark messages as read.
We now call the function mark_as_read(), and it only requires
passing in a message_id.
2017-08-03 11:32:54 -07:00
Steve Howell eac155d3b8 unread: Use reverse_lookup in unread_topic_counter. 2017-08-03 11:32:54 -07:00
Steve Howell 1927a6ca45 Simplify unread_topic_count.update().
The prior implementation was needlessly complex.  Both del() and
add() are cheap and idempotent.

With this change we no longer bother to delete a topic from a
dictionary when its last message is mark as read, since it doesn't
really help performance.  We add a line to the tests to maintain
100% line coverage.
2017-08-03 11:32:54 -07:00
Steve Howell b446d96ed6 Add people.pm_lookup_key 2017-08-02 09:40:47 -07:00
Steve Howell 8a7397fef6 people.js: Explicitly sort user_ids numerically.
It's not always clear whether user_ids are strings or integers, so
we explicitly convert them to integers for sorting when creating
keys for PMs.

To keep the tests passing, this commit removes some unneeded
defensive code in message_store.js that only applies to contrived
test input.
2017-08-02 09:40:47 -07:00
Rishi Gupta 0286a41c4c tutorial: Remove is_running and defer logic. 2017-08-01 22:38:22 -07:00
Rishi Gupta be7f6db854 tutorial: Remove rest of tutorial.
Replaces the call to welcome() in tutorial.start with finale(true), and then
iteratively removes all orphaned code.
2017-08-01 22:38:22 -07:00
Joshua Pan f253d741dd Add tests for stream_data.maybe_get_stream_name(). 2017-08-01 16:19:41 -07:00
Joshua Pan b7fe2fe7d8 Move maybe_get_stream_name to stream_data.js.
This also gets rid of the unnecessary set_global
in settings_org.js test, which made tests fail after
moving the code.
2017-08-01 16:19:41 -07:00
Steve Howell 3f06f28ad7 sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:

    * sending data to /json/report_send_time
    * restarting the event loop if events don't arrive on time

The code related to /json/report changes the following ways:

    * We track the state almost completely in the new
      send_messages.js module, with other modules just
      making one-line calls.

    * We no longer send "displayed" times to the servers, since
      we were kind of lying about them anyway.

    * We now explicitly track the state of each single sent
      message in its own object.

    * We now look up data related to the messages by local_id,
      instead of message_id.  The problem with message_id was
      that is was mutable.  Now we use local_id, and we extend
      the local_id concept to messages that don't get rendered
      client side.  We no longer need to react to the
      'message_id_changed' event to change our hash key.

    * The code used to live in many places:
        * various big chunks were scattered among compose.js,
          and those were all moved or reduced to one-line
          calls into the new module
        * echo.js continues to make basically one-line calls,
          but it no longer calls compose.report_as_received(),
          nor does it set the "start" time.
        * message_util.js used to report received events, but
          only when they finally got drawn in the home view;
          this code is gone now

The code related to restarting the event loop if events don't arrive
changes as follows:

    * The timer now gets set up from within
      send_messages.message_state.report_server_ack,
      where we can easily inspect the current state of the
      possibly-still-in-flight message.

    * The code to confirm that an event was received happens now
      in server_events.js, rather than later, so that we don't
      falsely blame the event loop  for a downstream bug.  (Plus
      it's easier to just do it one place.)

This change removes a fair amount of code from our node tests.  Some
of the removal is good stuff related to us completing killing off
unnecessary code.  Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.

There is also some minor cleanup to echo.resend_message() in this
commit.

See #5968 for a detailed breakdown of the changes.
2017-08-01 08:58:56 -07:00
Harshit Bansal a13535ff1f alert_words: Don't muck up rendered HTML content while munging.
Prior to this we were also performing highlighting inside HTML tags
which was wrong and causing weird behavior. Like, for example, if
someone added `emoji` as an alert word then any message containing
both emoji and alert word was rendered with a jumbo emoji.

Fixes: #4357.
2017-07-31 21:20:21 -07:00
Steve Howell 90c5b53da3 Remove send_times_log feature.
We no longer use this in development.
2017-07-31 14:57:34 -07:00
Tim Abbott 6a50e13156 uploads: Remove legacy /json/upload_file endpoint.
This migrates Zulip to use the equivalent API endpoint that has been
present for a while.
2017-07-31 13:08:06 -07:00
Tim Abbott 1e5aee054b settings: Migrate main settings-change code to API.
This was one of the few major remaining endpoints that were still on
the old-style legacy API.
2017-07-31 13:08:06 -07:00
Harshit Bansal a26b1188c6 minor: Indentation fix. 2017-07-31 12:42:36 -07:00
Harshit Bansal 3796292913 markdown: Fix the rendering of realm filters.
A realm filter should match only after the start of a line, whitespace
or opening delimiters. But markdown was not configured to respect those
rules which was causing some weird rendering behavior. This commit fixes
the regex used for matching realm filters. On the backend we are using
regex with negative lookbehind to perform matches but since javascript
regex don't support lookbehind we are using a workaround on the frontend
using `contains_backend_only_syntax()` function which detects if a realm
filter can be rendered correctly by backend only and if so it stops the
message from getting echoed locally.

Fixes: #5154.
2017-07-31 12:42:36 -07:00
Steve Howell 19ebf1e23b bankruptcy: Clear unread counts for mentions. 2017-07-31 08:30:46 -04:00
Steve Howell bf81782e59 Rename num_unread_for_subject -> num_unread_for_topic. 2017-07-31 08:11:18 -04: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
Tim Abbott 76c92ad676 markdown: Enforce backend-only-syntax checks in node tests.
While we do have some known cases where syntax diverges intentionally,
this change should make it a lot easier to maintain
markdown.contains_backend_only_syntax over time.
2017-07-28 18:17:25 -07:00
Tim Abbott 1360e1c5fd markdown: Add support for specifying marked output when not matching.
This lets us document cases where the syntax is intentionally
different in ways that we don't think are problematic.
2017-07-28 18:13:15 -07:00
Tim Abbott 4b7c23f133 markdown: Rename bugdown-data.json to a more reasonable name. 2017-07-28 17:54:01 -07:00
Tim Abbott 4f4d28477d markdown: Rename markdown.contains_bugdown.
This name was confusing, since "bugdown" doesn't exactly suggest
"backend markdown processor" to people.
2017-07-28 17:51:33 -07:00
Jack Zhang 7ec51a540e hotspots: Unit test hotspots.js. 2017-07-28 16:34:15 -07:00