Commit Graph

144 Commits

Author SHA1 Message Date
Steve Howell b3594c984a message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.

Now we compute it a bit more rigorously.

It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:

    * message_list_view.js
    * notifications.js

I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)

This errs on the side of warning the user, even if the
new message is partially visible.

Fixes #11138
2019-01-07 17:17:55 -08:00
Archit Kaushik 830dd68e45 message_list: Hide the message control icons when editing.
This avoids a bunch of potential confusion around users trying to
interact with these UI in situations that don't make sense.

(E.g. showing a menu to start editing the message when the menu is
already open).

Fixes #3802.
2018-12-29 14:37:56 -08:00
Steve Howell 7a2527aed1 hashchange: Call stop_auto_scrolling() directly. 2018-12-04 12:24:39 -08:00
Yashashvi Dave c635d5476d message view: Hide subscribe button for guest users.
Guest users can't subscribe themselves to streams, so we shouldn't
display the subscription button at end of stream message view.

Fixes part of #10749.
2018-10-31 15:47:01 -07:00
Aditya Bansal 82877fa116 recipient_row.handlebars: Upgrade to font-awesome 4.7 icon prefixes. 2018-07-11 20:31:17 +05:30
Steve Howell 930f3937dc Remove feature_flags.mark_read_at_bottom.
We removed all code related to the possibility
of it being false.
2018-07-07 10:19:15 +02:00
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
Steve Howell 26e1fca7ed Add message_list.is_at_end() helper. 2018-05-28 16:49:57 -07:00
Steve Howell a074056127 Add prev/next helpers for MessageList. 2018-05-27 22:41:19 -07:00
Steve Howell ad6de6e268 message_list: Remove unused delay_render option. 2018-05-15 14:25:21 -07:00
Steve Howell ff009fadf9 refactor: Have MessageList take in a data object.
We now allow you to initialize a MessageList with
a MessageListData object that you build outside of
the initializer.
2018-05-15 14:25:21 -07:00
Steve Howell a3d3d08a80 refactor: Avoid positional params for MessageList.
We used to have positional parameters for table_name
and filter, but we don't use them for message_list.all
and we're about to replace filter in some cases.

Passing everything in on opts is more consistent and
self-documenting in the calling code, plus lots of
unit tests can get away with passing in `{}` now
for situations where table_name does not matter.

All of our callers pass in muting_enabled, so we
remove the default value for it.  And then the
collapse_messages variable doesn't have to live on
`this` as it's only being passed through down to the
view.
2018-05-15 14:25:21 -07:00
Steve Howell f61ecef138 refactor: Cleanly divide data/view for add_messages.
Before this change, the way to add messages had a lot
of ping-pong-ing between MessageList and MessageListData,
where first the data got triaged, but not actually
inserted into data structures, and then subsequent
calls would add the data and get filtered results.

Now we have a simple API for MessageListData.add_messages
that does all the data stuff up front.  Having a fully
function MLD.add_messages not only makes the ML.add_messages
function about four lines shorter, it also sets us up
to easily build standalone MLD objects before making
the heavier ML objects.
2018-05-15 14:25:21 -07:00
Steve Howell 467fe7ceec refactor: Extract message_list.append_to_view. 2018-05-15 14:25:21 -07:00
Steve Howell 56f872507c refactor: Inline message_list.prepend. 2018-05-15 14:25:21 -07:00
Steve Howell 6834745feb refactor: Inline message_list.add_and_rerender. 2018-05-15 14:25:21 -07:00
Tim Abbott 7ab8a8e820 js: Fix a bunch of indentation issues found by eslint.
This is preparation for enabling an eslint indentation configuration.
90% of these changes are just fixes for indentation errors that have
snuck into the codebase over the years; the others are more
significant reformatting to make eslint happy (that are not otherwise
actually improvements).

The one area that we do not attempt to work on here is the
"switch/case" indentation.
2018-05-06 16:25:02 -07:00
Steve Howell 264dcb6f40 refactor: Extract MessageListData class.
Most of this was straightforward.

Most functions that were grabbed verbatim and whole from
the original class still have one-line wrappers.

Many functions are just-the-data versions of functions that
remain in MessageList:  see add, append, prepend, remove as
examples.  In a typical pattern the MessageList code becomes
super simple:

    prepend: function MessageList_prepend(messages) {
        var viewable_messages = this.data.prepend(messages);
        this.view.prepend(viewable_messages);
    },

Two large functions had some minor surgery:

    triage_messages =
            top half of add_messages +
            API to pass three lists back

    change_message_id =
            original version +
            two simple callbacks to list

For the function update_muting_and_rerender(), we continue
to early-exit if this.muting_enabled is false, and we copied
that same defensive check to the new function
named update_items_for_muting(), even though it's technically
hidden from that codepath by the caller.
2018-05-05 06:31:51 -07:00
Steve Howell da0c01e4ba Fix regression with topic edits clearing narrows.
We had a recent regression that had kind of a funny symptom.
If somebody else edited a topic while you were in a topic
narrow, even if wasn't your topic, then your narrow would
mysteriously go empty upon the event coming to you.

The root cause of this is that when topic names change,
we often want to rerender a lot of the world due to muting.
But we want to suppress the re-render for topic narrows that
don't support the internal data structures.

This commit restores a simple guard condition that got lost
in a recent refactoring:

        see 3f736c9b06

From tabbott: This is not the correct ultimate place to end up,
because if a topic-edit moves messages in or out of a topic, the new
behavior is wrong.  But the bug this fixes is a lot worse than that,
and no super local change would do the right thing here.
2018-05-04 16:33:23 -07:00
Steve Howell 0067ccb931 refactor: Add filtering helpers to message_list.js. 2018-05-04 10:59:56 -07:00
Steve Howell af24f51f0d Add MessageList.is_search().
This prevents MessageListView from having to know about
list.filter.
2018-05-04 10:59:56 -07:00
Tim Abbott 3f736c9b06 message_list: Clean up API for rerender_after_muting_changes.
This was only called from two places in one function, and we can just
check muting_enabled in the caller.

This refactor is important, because we might need to update muting
after other changes (specifically, message editing to move a topic to
be muted/non-muted).
2018-04-27 08:52:24 -07:00
Tim Abbott dbbd3627b5 message_list: Show empty narrow notice after emptying narrow.
If muting, topic editing, or deletion causes a narrow loses its last
message, we should show the empty-narrow notice; similarly, if
un-muting adds the first message, we should hide the notice.

We do this in `rerender()` since that's the common code path for
re-rendering the message list after events that might change this.

This has likely been broken since the very first muting
and topic editing implementations.
2018-04-13 16:31:18 -07:00
Tim Abbott ee939f4c1a message_list: Fix unnecessary work re-rendering all_msg_list.
Since all_msg_list is never displayed, there's no reason to do work
re-rendering it in these code paths.
2018-04-02 18:58:51 -07:00
Tim Abbott 2804a8c4f4 message_list: Fix scrolling upwards when users change names.
This fixes a messy bug where users would be randomly scrolled upwards
a large amount whenever a user's name was changed in Zulip.

Fixes #8921.
2018-04-02 18:58:51 -07:00
Tim Abbott e840e5b3a8 Revert "Ignore new messages when lists are behind."
This reverts commit bcdd12773e.

We need to do some improvements in handling FetchStatus for initial
narrows before this will be safe to deploy in production.
2018-03-30 11:52:14 -07:00
Steve Howell bcdd12773e Ignore new messages when lists are behind.
If individual messages arrive before we get the latest
messages from the server, they can create gaps in rendering,
and would often be offscreen anyway, so we just ignore them.
2018-03-28 09:12:25 -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 616a06e5b2 Use msg_list.fetch_status instead of load_enabled.
We now attach a fetch_status to message lists, so that they
can track their fetch status individually.  When you go
back in a narrow and get all the older messages, we turn
off future fetches.

The narrow.js code no longer needs to orchestrate anything
here.  The "home" message list won't have as many redundant
fetches after this commit, because we don't need to reset
flags every time we do `narrow.deactivate`.

And then actual narrows get a new message list every time
you narrow, so their fetch status gets reset implicitly
as part of constructing the MessageList object.
2018-03-09 14:20:58 -08:00
Tim Abbott c1f12e3f8a scrolling: Fix out-of-order bug in the message list.
The issue has a lot of extra details, but in short, if several
messages were sent at very close to the same time, it's possible that
the event queues will receive the "new message" events out-of-order.
This, in turn, could cause `get_events` to return an incorrectly
sorted block of messages.  These would then be passed into
`message_list.add_messages`, which doesn't handle that sort of
unsorted situation correctly (in short, the `self.first.id()`
comparison checks are not accurate for that situation, since we don't
update the boundaries after the first messages is processed).

The end result of this bug was that it was possible for the message
list to be out-of-order, which in turn would cause exceptions when
scrolling with the mouse.

Fixes #6948.
2017-10-11 15:57:11 -07:00
Tim Abbott 82b708b721 eslint: Add and enforce space-in-parens lint rule. 2017-10-06 12:36:59 -07:00
Tim Abbott 27bb680aa5 message_list: Fix exception with nonexistent streams.
If the stream no longer exists, we don't need to try to show a stream
resubscribe UI.
2017-09-15 01:59:24 -07:00
Tim Abbott c330c75e3c message_list: Refactor stream->stream_name local variable. 2017-09-15 01:59:24 -07:00
Sampriti Panda 073bc318cf compose: Fix rendering error with message edit forms.
Fixes #6412
2017-09-11 09:24:11 -07:00
Tim Abbott 3c8eb3c743 message_edit: Create recipient_bar_controls span.
This refactor will facilitate making it possible to set CSS properties
on this controls span; in particular, we're hoping to disable user
selection of the whitespace in this region.

The main side effect of this refactor is that we need to add JS code
to also hide the icon-vector-pencil element, since it's now in a new
span.
2017-08-27 22:18:05 -07:00
Steve Howell 5a10137ad9 Extract message_list.first_unread_message_id().
This de-duplicates code that solved the same problems using
two different phrasings.
2017-08-03 11:32:54 -07:00
Cory Lynch 802ea9abf5 Refactor to delete mousewheel.js.
This old third party library added support
for a "mousewheel" event to detect scrolling.
However, it is not compatible with jQuery 3
and is obsolete now that there is a standard
"wheel" event that accomplishes the same thing.
2017-07-03 11:04:20 -04:00
Cory Lynch ff9498f85b bookend: Hide re-subscribe button for private streams.
Fixes #5181
2017-06-20 20:56:26 -04:00
Steve Howell 081e0405dc Avoid error in closest_id().
If we get a potential_idx that is not in items, we now just
warn about it instead of letting a type error happen.
2017-06-15 18:33:26 -04:00
Steve Howell a9622b0e4f Fix lint error from recent commit (error_data). 2017-06-15 17:47:44 -04:00
Steve Howell 1f34077fa1 minor: Add closest_id to blueslip error data. 2017-06-15 16:33:38 -04:00
Akhil b6b22fbb47 message-edit: Trigger mouseleave on row when hiding message_edit div.
For the pencil icon to appear, message_unhover has to be called before
message_hover (both in ui_init.js). This happens when the mouseleave
event is triggered on a row. But, when clicking the save button and
the edit box is hidden, the mouseleave event is not triggered and
hence message_unhover not called.

Fix this with a manual mouseleave event.

Fixes: #4287.
2017-06-15 12:24:40 -07:00
Tim Abbott bbbd924bdf bookend: Add i18n tags for bookend notices. 2017-06-05 16:55:56 -07:00
Cynthia Lin 11e68606b4 design: Improve design of Subscribe/Unsubscribe buttons in message view.
Tweaked by tabbott to use an existing button style.

Fixes #5196.
2017-06-05 16:55:56 -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
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
Steve Howell 24ee369d43 Improve error message in message_list.select_id(). 2017-03-27 10:26:30 -07:00
Steve Howell 293c89ba94 message edit: Only enable left-arrow-editing for content.
We no longer let the left arrow put you into the message edit
UI for a message where you can only edit topics, since that is
just confusing to most users.

This change also improves error handling a bit, and it removes
an unnecessary call to rows.id().

Finally, it moves some logic out of message_list.js, so that we
don't have a circular dependency for this codepath.

Fixes #4259
2017-03-27 10:02:19 -07:00