Commit Graph

1001 Commits

Author SHA1 Message Date
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
Jack Zhang 5a8b1e6253 hotspots: Implement hotspots frontend. 2017-07-28 16:34:15 -07:00
Jack Zhang 6a7a4132b4 hotspots: Create hotspot_overlay template. 2017-07-28 16:34:15 -07:00
Joshua Pan e6611fec99 markdown.js: Remove paragraph break from numbered lists.
Fixes #5902.
2017-07-28 12:32:20 -07:00
Tim Abbott e729814cfd recent_senders: Fix exception in certain typeahead flows.
It appears that a regression introduced in
3f60074c33 caused undefined to be passed
as the subject to the recent_senders library much more often; this
fixing that, and makes the library handle such cases reasonably
without an exception regardless.

This was causing a huge number of "Tried to call a Dict method with an
undefined key." exceptions.
2017-07-28 11:04:11 -07:00
Steve Howell 724e988102 Add topic_data.add_history(). 2017-07-27 14:26:22 -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
Steve Howell 611f44b339 node tests: Test topic casing for unread counts.
We use multiple casings of "lunch" as a topic in our tests, so
that we verify that unread counts respect that topics are
not case sensitive.

We also eliminate an obsolete stub.
2017-07-27 14:26:22 -07:00