Commit Graph

2421 Commits

Author SHA1 Message Date
Cory Lynch f9d1bff167 Fix textarea resize for editing messages.
Reusing code from the main compose_message component so that resizing now
behaves correctly. This means that when the user tries to resize vertically,
the autoresize code is disabled, and the textbox reverts to manual resizing.
Fixes #4573
2017-04-28 12:15:34 -07:00
Steve Howell 0ced7cfc55 Make newly subscribed streams appear active.
When you subscribe to a stream, we now set a newly_subscribed
flag on the object, and we return true during the is_active()
call.

This solves the problem that immediately after you subscribe, you
don't have any messages in the stream, so it would appear active
by our old criteria.

This is still something of a workaround, as once you reload, the
stream will become inactive again, unless other messages come in.

A more permanent solution here would be to have the backend
indicate newly subscribed streams to us (apart from the initial
event), but we may not really need that in practice.
2017-04-28 07:40:25 -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
Cory Lynch 088d881159 compose: Improve ordering in streams typeahead.
The new logic has 4 tiers of priority:
* Whether a match is found in the name, start of description, middle
of description, etc.
* Importance to the user / activity -- more specifically, the order
used in the left sidebar. This means pinned streams first, active
streams, then inactive streams.
* Subscriber count: How big is the stream?  Bigger is better.
* Alphabetical ordering is a final tiebreak.

Fixes #4508.
2017-04-26 12:46:14 -07:00
Brock Whittaker 2fce6a4dc3 message-feed: Fix message drag uncaught errors.
There is a mechanism to prevent a user from "clicking" on a message
if they drag over it, to allow people to copy message contents without
triggering the compose box to open.

In the case that a user would start dragging from outside a message
and finish dragging within a message, data on where the cursor started
at is missing.

This is fixed by checking if start data exists and if it doesn't, we
just throw a drag distance of Infinity which will tell the program to
not count the action as a "click" on the message. This now does not
have an uncaught error because it instead validates "start" as existing
before attempting to access its properties.
2017-04-26 12:31:14 -07:00
Tim Abbott 5d7aa4fae7 hashchange: Fix buggy narrowing to wrong message.
Due to a past refactoring, the from_reload argument to do_hashchange
changed from having true/undefined as the possible values to
true/false instead.  The check that sets the from_reload and
first_unread_from_server narrow options was thus incorreclty treating
from_reload of false the same as a from_reload of undefined.

As a result, if the browser had been loaded with a
page_params.initial_narrow_pointer (aka via the background reload code
path), then for the duration of that browser session, every time one
narrowed via a hashchange rather than an explicit click handler (which
apparently includes clicking on a PM thread in the left sidebar), we'd
end up narrowing with a then_select_id of the that initial narrow
pointer, not the correct first unread message.

The fix is simply changing the check for truthiness, not undefined, in
do_hashchange.
2017-04-26 12:07:56 -07:00
Umair Khan f4a9651346 reload: Garbage collect previously preserved state.
This fixes a minor local storage data leak.

Fixes: #4545.
2017-04-26 09:14:46 -07:00
Umair Khan 58a82e7c55 localstorage: Allow regex based delete. 2017-04-26 09:11:44 -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
Cory Lynch 0d9b77c8b7 composebox_typeahead.js: Add typeahead cancelling for '# '.
If somebody types '# ', then close the typeahead dialog and
don't autocomplete. Relevant node tests were also added.

Fixes #4505.
2017-04-25 15:55:23 -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
Steve Howell 7326971380 Extract stream_edit.js.
This code makes the right pane work in "Manage Streams" when
you are editing a stream subscription.  It handles basic
functionality (submitting forms, etc.), live updates, and
showing the pane as needed.

Most of the code here was simply moved from subs.js, but some
functions were pulled out of larger functions:

    live update:
        add_me_to_member_list
        update_stream_name
        update_stream_description

    collapse/show:
        collapse
        show_sub

We also now export subs.show_subs_pane.

We eventually want stream_edit not to call into subs.js, and
this should be fairly easy--we just need to move some shared
methods to a new module.
2017-04-25 09:57:32 -07:00
Steve Howell ca2aea8d01 Extract stream_create.js.
This new modules handles the UI to create streams.  It mostly moves
code from subs.js.

It introduces an API around what used to be called meta.stream_created:

    reset_created_stream()
    set_name()
    get_name()

It only partially moves new_stream_clicked().
2017-04-25 09:57:32 -07:00
Harshit Bansal 6cb03ea78e frontend: Add UI necessary to change emoji set.
Note that this code is disabled until the infrastructure for the
feature can be finished.

Tweaked by tabbott to use slightly cleaner names for the various sets.
2017-04-24 22:31:30 -07:00
wangjames 744f4aa663 Fix modals dependency cycle.
This commit forces the files that create modals to create their own
modal closing function instead of creating all of them in the modals
file. These functions are then passed to the modals.close object. This
is intended to remove modals.js's dependencies on these other files.
2017-04-24 14:30:02 -07:00
Steve Howell c999bdf823 compose: Distinguish get_message_type() from composing().
We now only call compose_state.composing() in a boolean context,
where we simply care whether or not the compose box is open.  The
function now also returns true/false.

Callers who need to know the actual message type (e.g. "stream" or
"private") now call compose_state.get_message_type().
2017-04-24 12:42:06 -07:00
Steve Howell d938afaedc Extract narrow.narrow_to_next_topic().
This borrows some code from a PR from Mahim Goyal.
2017-04-22 11:46:47 -07:00
Shayan Toqraee 534c951ec4 Add rtl.js library for detecting direction of text.
This comes complete with some documentation and node tests, and is a
key step towards implementing RTL support in Zulip.
2017-04-22 11:25:54 -07:00
Steve Howell ddbe877909 Add narrow.stream_topic(). 2017-04-21 21:59:22 -07:00
Steve Howell 6ddbf12376 Add topic_generator.get_next_topic(). 2017-04-21 21:59:22 -07:00
Steve Howell 079885770b Add unread.topic_has_any_unread(). 2017-04-21 21:59:22 -07:00
Steve Howell 4871b491f3 Add Dict.is_empty(). 2017-04-21 21:59:22 -07:00
Steve Howell b27180a645 Have next_topic() return stream/topic objects.
We now use "map" to have our inner generator of topics be
mapped to objects with both the stream and topic.  Thanks to
Mahim Goyal for helping with this design.
2017-04-21 21:59:22 -07:00
Steve Howell d332df8cc6 Add topic_generator.map(). 2017-04-21 21:59:22 -07:00
Tim Abbott 7d8d9c1bf9 Fix message-edit animations being displayed after sending.
This fixes a regression in 3041480600
that would cause anything rendered on the backend differently than on
the frontend to experience this animation.

We actually only want to do the animation when the message content was
changed in a way that generates an edit history event, i.e. a
user-facing edit, not in cases where we're either transparently
swapping in post-backend-rendering content (e.g. with link previews)
or cases where there's a discrepancy between the exact HTML from the
frontend and backend markdown processes (e.g. mentions).
2017-04-21 11:46:35 -07:00
Steve Howell cc6c0104c8 Refine compose box behavior for topic narrows.
The comments that were added in the code for this commit explain
the cases here, but essentially for topics, we need to decide
among a few possible behaviors with regard to composing:

- Leave it closed.
- Cancel the compose.
- Leave the compose box as it was before.
- Fill in the new topic.

Before this commit, we were cancelling compose in all cases (or
leaving it closed).

Now we leave it alone in some cases where there is already content.
And we fill in the topic when the stream was correct and the topic
was empty.

Fixes #3300
2017-04-20 16:15:07 -07:00
Brock Whittaker 83d51b2bdb Hide status message on edit.
When editing a /me, the status message element should be hidden.
2017-04-20 14:36:17 -07:00
Brock Whittaker 323ff6edca /me: Fix presentation and markup for /me statuses.
This fixes the /me elements to be display inline-block and inline
rather than display block with top and left properties.

This also fixes an unrelated issue with emoji reactions not being
able to be clicked on with /me messages.

Fixes: #4218.
2017-04-20 14:36:17 -07:00
Joshua Pan 728594c74a activity.js: Stop opening compose box in user search.
This prevents compose box from opening when you
just press enter with an empty search field in
user search.

Fixes #4376.
2017-04-19 22:18:08 -07:00
Brock Whittaker 3041480600 message-edit: Fade in message on update.
When a message update comes back from the server and replaces an
old message, it should fade in. There are two components to the fade:

1. The message fades in from opacity: 0 =>  1.
2. The "edited" text will transform from X: -10 => X: 0.
2017-04-19 22:14:58 -07:00
Steve Howell c7a9a02667 Consolidate code for narrow/compose interactions.
This commit extracts the method compose_actions.on_narrow()
to handle changing the compose box (as appropriate) after
any narrowing action.

This change should be mostly non-user-facing, but it's not
exactly a trivial extraction.

For the case where the user already had content in their
compose box, we continue to leave the compose box alone,
but we now update compose fading 150+ lines later in
narrow.activate().

Likewise, for cases where we cancel composing, this will
also happen later in the function.

Finally, for PM narrows, where we auto-open the compose box, we
no longer call compose.cancel() before calling compose.start(),
because either a) the compose box would have not been open
in the first place or b) the start() function can handle
clearing the old fields.
2017-04-19 10:06:00 -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
Joshua Pan 4fb450d4a9 hotkey.js: Add reactions popover navigation.
Fixes #4197.
2017-04-18 23:25:45 -07:00
Joshua Pan a7327422a8 reaction.js: Create reaction_navigate(). 2017-04-19 06:17:15 +00:00
Joshua Pan abda711c66 reaction.js: Extract reaction_show_list functions.
This creates get_emoji_at_index() and
find_index_for_emoji() functions, which search for
emojis and indices in reactions_show_list. Update
maybe_select_emoji with newly created functions.
2017-04-19 06:17:15 +00:00
Joshua Pan e075c84ca5 reaction.js: Maintain reaction_show_list.
This updates reaction_show_list whenever the popover
gets opened and whenever the search filter for reactions
gets used.
2017-04-19 06:17:15 +00:00
Joshua Pan cd28ea6d07 reaction.js: Update toggle_reaction().
Created get_selected_emoji() function.
toggle_reaction() now doesn't require emoji_name
and automatically looks for a selected_emoji
if possible.
2017-04-19 06:16:30 +00:00
Tim Abbott 540bfce83f reactions: Use perfectScrollbar for emoji reactions scrollbar.
This fixed the fact that the scrollbar for this popover was super ugly
on Linux, while also ensuring that we have a consistent 6 emoji per
row in the popover (an important detail for the arrow hotkeys).
2017-04-18 22:58:11 -07:00
Steve Howell 70b7d4c00b Extract compose_state.js.
This is mostly just moving methods out of compose.js.

The variable `is_composing_message`, which isn't a boolean, has
been renamed to `message_type`, and there are new functions
set_message_type() and get_message_type() that wrap it.

This commit removes some shims related to the global variable
`compose_state`; now, `compose_state` is a typical global
variable with a 1:1 relationship with the module by the same
name.

The new module has 100% line coverage, most of it coming
via the tests on compose_actions.js.  (The methods here are
super simple, so it's a good thing that the tests are somewhat
integrated with a higher layer.)
2017-04-18 12:26:58 -07:00
Tejas Kasetty 7e4155cd42 update_emojis: Handle the case involving deletion of realm emoji. 2017-04-18 12:18:52 -07:00
Tejas Kasetty d227a8e35c compose: Re-render emoji picker when realm_emoji is added/deleted.
* reset the emoji popover in case of an event
regarding update of realm_emoji.
* test-node-with-js: Add dependency - popovers module;
In dispath.js to support popovers object.
2017-04-18 12:18:52 -07:00
Tejas Kasetty b7aa81f122 compose: Render the emoji picker only once.
* Whenever the emoji picker is opened a call is made to render
  the emoji's. This rendering happend everytime the emoji picker
  was opened. Thus, resulting in duplicates of emoji's getting
  appended in the emoji picker over multiple open and close.

* This commit, is a fix to render the emoji's only once when the
  emoji picker is opened for the first time. Further calls just
  toggles the emoji picker showing the already rendered emoji's.
  This enhances the performance of Emoji picker considerably
  because there is no overhead of making a request to get the emoji's
  from the server, each time the emoji picker is opened.

* Other changes -- on closing the emoji picker, the compose box
  remains in focus.

Fixes: #4300.
See Also: #3952.
2017-04-18 12:18:52 -07:00
Joshua Pan 6fe567846c Extract drafts_scroll() function.
Fixes #4334.
2017-04-18 12:14:41 -07:00
Joshua Pan 0377b5aba6 Extract drafts_initialize_focus().
This function takes care of focusing a draft if a draft
is not already focused in draft modal.
2017-04-18 12:14:41 -07:00
Joshua Pan 6fe26b6c04 Extract drafts process enter key to drafts.js.
Extracted draft code from hotkey.process_enter_key to drafts.js.
2017-04-18 12:14:41 -07:00
Steve Howell 78803b2e56 Add narrowed_by_topic_reply() helper. 2017-04-17 22:54:36 -07:00
Steve Howell 9d4f0bf704 Open compose box more aggressively for PM narrows.
We now auto-open the compose box whenever somebody narrows to
a "pure" PM narrow.  We already did this for buddy list clicks,
so this make it work the same for other ways of narrowing to
PM conversation.  Here, we optimize for composing, vs. reading,
since PM conversations tend to have lots of back and forth.

(Contrast this to stream conversations, where there's a higher
likelihood of lurking or doing a quick narrow to re-read some
message from the stream.)
2017-04-17 22:54:36 -07:00
Steve Howell bdca28a14b Avoid opening compose box for topic sidebar clicks.
We don't want to auto-open the compose box for topic
sidebar clicks, because we want to convenience folks
reading messages, not writing messages, since on
stream narrows, people tend to do much more reading
than writing.  (Also, opening the compose box explicitly
is super easy.)

The part of this change that affects behavior is that
we remove the call to compose_actions.start('stream').

Then the simplification is that we replace the checks
to narrowed_by_reply() and !narrowed_to_topic() with
a single call to narrowed_by_pm_reply().

Fixes #3886.
2017-04-17 22:54:36 -07:00