Commit Graph

33 Commits

Author SHA1 Message Date
Anders Kaseorg d17b577d0c js: Purge useless IIFEs.
With webpack, variables declared in each file are already file-local
(Global variables need to be explicitly exported), so these IIFEs are
no longer needed.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-10-25 13:51:21 -07:00
Thomas Ip a2872c107e typescript: Move TS files into JS directory.
This is just a code reorganization to avoid making it difficult to
find things as we migrate more file to TypeScript.
2019-03-25 12:11:37 -07:00
Thomas Ip 7d050ab0cf typescript: Migrate dict.js to typescript. 2019-03-21 10:48:44 -07:00
Steve Howell 8121d19122 minor: Change "subject" to "topic" in comments. 2018-12-29 11:38:39 -08:00
Steve Howell 35b904b184 subject -> topic: Fix subject in opts.
It's kinda difficult to track down all the interactions
with the opts that go through compose_actions.start(),
but I think I got everything.
2018-12-16 11:26:18 -08:00
Steve Howell b615f0df4d subject -> topic: Fix stream/subject in comments. 2018-11-14 23:24:06 -08:00
Steve Howell c407ba5175 Add narrow_state.is_reading_mode(). 2018-07-10 14:20:24 +05:30
Steve Howell bec40af614 Remove redundant narrow_state.get_current_filter().
We now use narrow_state.filter() everywhere.  The
two functions did the same thing, and I slightly
prefer the concise name, which was already in use
in lots of places.
2018-07-10 14:20:24 +05:30
Armaan Ahluwalia 6d255efe4c app: Prepare JS files for consumption by webpack.
This commit prepares the frontend code to be consumed by webpack.

It is a hack: In theory, modules should be declaring and importing the
modules they depend on and the globals they expose directly.

However, that requires significant per-module work, which we don't
really want to block moving our toolchain to webpack on.

So we expose the modules by setting window.varName = varName; as
needed in the js files.
2018-07-05 10:53:36 +02:00
Shubham Dhama 80a2d5bc59 eslint: Enable `conditionalAssign` config of no-trailing-spaces rule. 2018-06-11 07:51:24 -04:00
Shubham Dhama dcb6254a4e eslint: Enable `no-extra-parens` rule.
Following sub-configuration is disabled:
                "nestedBinaryExpressions": false,
2018-06-11 07:51:24 -04:00
Steve Howell 7642ed66cf Expand get_unread_ids() to all local narrows.
This commit makes it so that any query for
which we do a local filter leads to us
examining the full list of unread message
ids in our cache to find a potentially
unread message that passes the filter.  This
can often allow us to more immediately
jump to a new narrow with an appropriately
selected message.

Fixes #9319
2018-05-31 08:44:18 -07:00
Steve Howell 4c235bfe65 Handle non-local case in get_first_unread_info().
We want to be able to call get_first_unread_info() even
if we cannot apply a search locally.  It was returning
the correct value before, but this change removes a
blueslip warning that will allow our callers to remove
some guard code in a subsequent commit.
2018-05-31 08:44:18 -07:00
Shubham Padia 0ffcb7fccf search: Remove blueslip warnings for invalid emails in 'pm-with' filter.
Fixes #3380.
The blueslip warning mentioned in #3380 were from paths ending at
people.email_list_to_user_ids_string. Some additional blueslip warnings
were raised after using that function.
Although we can put a validation check somewhere in the call stack of
people.email_list_to_user_ids_string, this function itself is used to
validate the operand by the higher order functions, so it wouldn't make
sense to put a validation check before that. Instead, removing the
blueslip warning altogether was chosen.
people.email_list_to_user_ids_string was replaced by
people.reply_to_to_user_ids_string which is a blueslip-free version
of the same. Other blueslip warnings were removed.
2018-05-30 07:49:59 -04:00
Shubham Padia d9b0ab2ae7 narrow: Show non-existing user message for invalid emails.
Also adds people.is_valid_bulk_emails_for_compose and refactors
narrow_state.set_compose_defaults to use it.
2018-05-28 10:45:42 -07:00
Shubham Padia 6ea6f5e0af search: Do not open compose box if invalid recipient present in `pm-with`.
If atleast one of the private_message_recipients is invalid, compose
box will not be opened.
Thanks to Aastha Gupta <aastha.gupta4104@gmail.com> for some preliminary
work on this.
2018-05-28 10:45:42 -07:00
Steve Howell 0c9cf12933 Avoid some server fetches for sender:foo queries.
If we find unread messages for a sender, we will
try to render locally narrow for sender searches.

Note that our current implementation brute forces
through all the unread ids.  We can improve this,
although it's not really a bottleneck until we
also support buckets for general filtering.
2018-05-13 08:47:55 -07:00
Steve Howell 815f54cda4 Use local messages for more narrow searches.
We now try harder to find the first unread message in an
upcoming narrow, which has the user-visible effect that we
select the unread message before waiting for search results.

Before this change, we only applied this logic to searches
that were things like exactly stream/topic or exactly is-private.

Now we will also handle things like stream/topic/sender.  For
the stream/topic piece we look up candidate unread ids using
the steam/topic buckets in unread.js, but then we still filter
those messages by stream/topic/sender as we look for the first
unread id.
2018-05-10 06:36:13 -04:00
Steve Howell 5d6d1ca8f9 refactor: Rename narrow_state.get_unread_ids().
I renamed get_unread_ids() to _possible_unread_message_ids().
The name is deliberately verbose, since we're about
to make it have kind of unusual semantics that only make sense
for its one caller.

The outside code will continue to call get_first_unread_info().

In the tests I wrap this function in a wrapper with the more
pleasant name of "candidate_ids", since in the test there's
less worry about unwittingly exposing a kind of janky function.
2018-05-10 06:36:13 -04:00
Steve Howell 9b15c2cd46 minor: Re-order code blocks.
This is setting up for a subsequent commit to have a smaller
diff.  The current ordering of the code blocks doesn't matter,
since only one of the conditions will be true, so this won't
change any behavior.  (Later commits will make the order matter.)
2018-05-10 06:36:13 -04:00
Steve Howell a176380df5 refactor: Introduce filter.is_exactly().
This new API replaces some more specific functions that were
only recently introduced:

        is_stream_only
        is_stream_topic_only
        is_pm_with_only
        is_for_only

We use the deterministically sorted "term_type" values for
matching.  (Notably "stream" will come before "topic".)
2018-05-08 12:13:55 -07:00
Steve Howell a68fa980d3 Add starred messages to our new API for unread ids.
Even though starred messages are never unread, it's useful
for us to have helper functions for them.

This change makes it so that clicking on "Starred Messages"
takes you to the last read message immediately, without a
server delay.
2018-05-03 14:36:34 -07:00
Steve Howell 3e19efca36 Change narrow.get_first_read_id -> get_first_read_info.
This function, which is only used in tests so far, needs
to return something more meaningful than undefined when
we don't find an id.
2018-05-03 12:44:30 -07:00
Steve Howell 66cd2edee4 Add narrow_state.get_first_unread_id(). 2018-05-02 13:34:54 -07:00
Steve Howell 230ecb24ed Add narrow_state.get_unread_ids(). 2018-05-02 11:23:58 -07:00
Steve Howell 7222dbd99b refactor: Simplify narrow_state.is_for_stream_id().
This takes advantage of the new function narrow_state.stream_id().

We now assume the incoming stream_id is a valid stream_id, so we
no longer need to test some of the error checking.  (It's possible that
the incoming stream_id may no longer be for a stream you subscribe
to, but the nice benefit of working more in "id space" is that if
it doesn't match the narrow's stream id, we know false is a safe
return value.)
2018-05-02 09:16:24 -07:00
Steve Howell a62c85c015 Add narrow_state.stream_sub() and narrow_state.stream_id(). 2018-05-02 09:16:24 -07:00
Rohitt Vashishtha b22e8dc2b7 lint: Replace 'return undefined;' with 'return;'.
Also adds a custom rule to eslint. Since the recommended way of extending
eslint is to create plugins as standalone npm packages, the separate rule
is published as 'eslint-plugins-empty-returns'.

Fixes #8669.
2018-03-13 08:22:42 -04:00
Steve Howell 13abed229c Add narrow_state.pm_string(). 2018-02-12 09:34:59 -08:00
cPhost 8d0ccd29fe narrow_state: Make set_compose_defaults return opts. 2017-12-03 14:01:19 -08:00
Joshua Pan c4914eeec9 narrow.js: Create narrowed_by_stream_reply().
This function returns if you are narrowed
to a stream.
2017-06-27 14:06:59 -04:00
Steve Howell 252d0a6e15 Use stream_data.get_name() in narrow_state.stream().
Using get_name() is more robust for stream name changes.  This
fixes, for example, the situation where you narrow to a stream,
edit it via the sidebar, and then close the modal, and the message
redraw logic thinks you have unsubscribed.

Fixes #4686.
2017-05-13 21:59:08 -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