Commit Graph

181 Commits

Author SHA1 Message Date
Anders Kaseorg 6ff28577cc js: Convert static/js/message_list_data.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-23 20:36:01 -08:00
Abhijeet Prasad Bodas 9ae44c769c refactor: Rename MessageList.muting_enabled.
Previously, the `muting_enabled` property of
MessageListData class was used to indicate whether
some messages in the message list need to be
filtered due to topic muting, depending on the
narrow. For example, we exclude messages belonging
to muted topics from stream narrows, but not from
search narrows.

The name `muting_enabled` is a bit confusing, and hence is
changed to `excludes_muted_topics`.
It is also important that the name be specific, since
a similar new property will be added for user mutes
in future commits.
2021-02-10 07:53:05 -05:00
Steve Howell 5a27ed6a72 refactor: Change where we initialize scrolling code.
This is a more sensible place to initialize the
the scrolling handler, plus it breaks an annoying
indirect dependency on jQuery for the unit tests.
2021-01-29 15:21:07 -08:00
Anders Kaseorg 2c5e9f65f8 eslint: Fix new-cap errors.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-12-10 19:52:22 -08:00
ryanreh99 e5779c1ca0 message events: Refactor `reify_message_id` codepath.
The changes made in this commit are as follows:

* The `remove_messages` is moved to the `message_events.js`
  file from `ui.js`.

* We refactor `MessageListData.change_message_id` to no
  longer require an `opts` parameter as this function
  just returns whether we need to rerender or not.

  The blueslip error block can be removed since we made
  the change to no long defer the data updates in
  commit 3b5ba6b2c1,
  this case can no longer occur.
2020-11-16 17:23:15 -08:00
ryanreh99 59e5f2d8fc message events: Refactor `remove_and_rerender` codepath.
The changes made in this commit are as follows:

* We remove the now unused `ui.find_message` which was added
  in commit 1666403850.

* We change the function paramter to now accept message ids
  instead of messages to eliminate redundant message ids to
  message convertion as only the id is required.

* The remove method in MessageListData did not remove the
  messages from the hash, it removed only from the items,
  this fixes it.

* This commit also fixes a bug where messages are not added
  to the current message list if an event is recieved where
  messages are moved to this current narrow.
  Only the message removal logic was present, which has been
  refactored in this commit.
2020-11-16 17:23:15 -08:00
Anders Kaseorg 0d4af4f8e7 eslint: Fix unicorn/prefer-type-error.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-type-error.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Anders Kaseorg fb233bd994 eslint: Fix unicorn/prefer-number-properties.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-number-properties.md

MDN says these were added to Number for modularization of globals.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Anders Kaseorg fe66aef0ad blueslip: Replace fatal with throw new Error(…).
This makes it clear to humans and ESLint that execution will not
continue.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-09-25 15:17:36 -07:00
Ryan Rehman 20775e5429 minor: Rename `previously_selected` of message selected event.
This is done since we have logic in place which compares `event.id`
and `event.previously_selected`, both of which point to message ids.
2020-09-14 10:56:37 -07:00
sahil839 a01d33353f message_list: Live update trailing bookend on stream deactivation.
We were not updating the trailing bookend on deactivation of stream
if the user was narrowed to deactivated stream and this commit fixes
this.

For subscribed streams, we just show the trailing bookend with
content as 'This stream has been deactivated' and hide the
Unsubscribe button.

For unsubscribed streams, we change the content of trailing bookend
to 'This stream has been deactivated' and hide the Subscribe button.

Fixes #15999.
2020-08-31 22:28:19 -07:00
Anders Kaseorg 6ec808b8df js: Add "use strict" directive to CommonJS files.
ES and TypeScript modules are strict by default and don’t need this
directive.  ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
Ryan Rehman 15c5dadb73 message view: Move live update logic of stream name to `message_store`. 2020-07-27 11:00:31 -07:00
Ryan Rehman 131a1dd54f message view: Move live update logic of avatar url to `message_store`. 2020-07-27 11:00:31 -07:00
Ryan Rehman 06d0dc1ffa message view: Move live update logic of full name to `message_store`.
This is done to decouple our message view related update events
from MessageListData as there are plans to create multiple
MessageListData objects. Instead we update the `stored_messages`
which tracks the complete data for all messages.
2020-07-27 11:00:31 -07:00
Ryan Rehman e85bc853d6 message list: Refactor and update API to include `rerender_view`.
This is a necessary prep commit as our message live update
functions will call this function, outside the MessageList class.
2020-07-27 11:00:31 -07:00
Anders Kaseorg 7249103ab4 message_list: Convert MessageList to an ES6 class.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 17:00:05 -07:00
Anders Kaseorg 96dcc0ce6e js: Use ES6 object literal shorthand syntax.
Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:42:22 -07:00
Anders Kaseorg b65d2e063d js: Reformat with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 8046b6477a js: Remove extra consecutive spaces.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 883e2fd325 js: Remove inner spacing from object literals.
We’re configuring Prettier with bracketSpacing: false.  Generated by
ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg f3726db89a js: Normalize strings to double quotes.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg a79322bc94 eslint: Enable prefer-arrow-callback.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
YashRE42 22884e768b message_edit: Ensure message edit form is empty prior to appending.
Prior to commit 8b7e70ac27 this system
would simply just .hide() forms when they were closed and
.empty().append() every time it needed to "show_edit". This was not a
very clean way of handling the action of canceling an edit, so
8b7e70ac27 introduced a change that had
the "show_edit" function append the form and the "hide" function
.empty() the form.

However, we overlooked the fact that the user could use browser
history to navigate away and back to the form and use "e" or
"left arrow key" to successfully append another form and get to an
ugly, broken state.

This commit does not revert 8b7e70ac27
as it is still accurate to .empty() when hiding the form, but we add
an early exit if a form already exists, to avoid bugs like the above.

Using an early exit instead of eg .empty().append() ensures that the
user doesn't accidentally lose the entire content of an edit, if they
deselect the input box and press `e`.

Fixes: #15045.
2020-06-05 20:12:47 -07:00
Ryan Rehman cfc87e3925 message list: Move the `FetchStatus` object to MessageListData class.
The reason for this change is that, this is where `Filter` and
actual tracking of what messages are contiguous lives. This
will be beneficial when we will to move to a model where we
cache `MessageListData` objects for a large number of views.
2020-06-02 15:45:39 -07:00
YashRE42 8b7e70ac27 message_list: Remove edit forms rather than just hiding them.
It is more semantically accurate to remove these elements instead of
just hiding them. We were previously using a .empty().append() chain
during creation/display of these forms, hence, we clearly don't desire
to preserve the element anyway (neither are there any worthwhile
benefits of trying to).
2020-04-22 16:25:38 -07:00
Puneeth Chaganti 6f2d0c0288 message_list: More descriptive names for {show,hide}_topic_edit.
Clarify that the functions show and hide the topic edit in the recipient
row, and do not apply to the message edit rows.
2020-04-06 10:57:29 -07:00
Puneeth Chaganti cd64d2dd27 message_list: Hide topic edit pencil icon in the edit mode.
The pencil icon incorrectly appeared after it was clicked to switch to the
topic edit mode. 51a8873579 seems to have
introduced this bug.

Closes #14460
2020-04-06 10:57:29 -07:00
vaibhavrajsingh2001 51a8873579 widgets: Hide edit question icon in poll widget for non-author users.
If a non-author user clicked on view source in a poll and then close it,
the edit question icon would incorrectly get visible. This made changing
the question in local echo possible for non-author users.

Fixes: #14299
2020-03-28 15:04:36 -04:00
Anders Kaseorg dbffb2a614 js: Convert _.extend to spread syntax or Object.assign.
This is not always a behavior-preserving translation: _.extend mutates
its first argument.  However, the code does not always appear to have
been written to expect that.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-25 14:09:39 -08:00
Anders Kaseorg 28f3dfa284 js: Automatically convert var to let and const in most files.
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`.  It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00
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
Tim Abbott edee1251c8 message_list: Replace buggy rerender_the_whole_thing.
As it turns out, our rerender_the_whole_thing function (used whenever
we were adding messages and discovered that the resulting message list
would be out-of-order) was just broken and scrolled the browser to a
random location.

This caused two user-facing bugs:

* On very fast networks, if two users sent messages at very close to
  the same time, we could end up with out-of-order message deliveries,
  triggering this code path, which was intended to silently correct
  the situation, but failed.

* In some narrows to streams with muted topics in the history but some
  recent traffic, the user's browser-cached history might have some
  gaps that mean the server fetch we do after narrowing discovers the
  history is out-of-order, again triggering the
  rerender_the_whole_thing code path.

The fix is to just remove that function, adding a new option to the
well-tested rerender_preserving_scrolltop (which has explicit logic to
preserve the scroll position) instead.

Fixes #12067.  Likely also fixes #12498.
2019-09-18 11:43:21 -07:00
Vinit Singh 86073588be dependencies: Upgrade jquery-autosize 1.17.7 to autosize 4.0.2.
The API for the autosize library changed upstream, so several changes
had to be made to relevant js files for a successful upgrade.

Resolves #12695.
2019-07-18 14:33:16 -07:00
Mohit Gupta 6ec40cf9a0 search: Don't mark messages as read in search narrow.
Don't mark unread messages as read while searching.
This behavior will be extended to other narrows later.

Fixes: #12556.
2019-07-17 17:58:20 -07:00
Anders Kaseorg 15192d4417 message_list.js: Add setter for narrowed.
After migration to an ES6 module, `narrowed` would no longer be
mutable from outside the module.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-07-08 21:22:54 -07:00
Challa Venkata Raghava Reddy 8623a02d98 streams: Avoid showing more topics option when it's useless.
This makes the "more topics" option which appears below the list of
known topics in the left sidebar appear only when it's possible there
are actually more topics to be displayed.  Two specific cases it
resolves completely include:

* Newly created realms; this widget was a common source of confusion
  for new organization administrators.
* Newly created streams.

There are still some corner cases this doesn't handle, e.g. if you
just joined a private stream with protected history, but there isn't
as easy a fix for those.

Essentially rewritten by tabbott to fix code duplication and comment
extensively.

Fixes #10265.
2019-03-14 21:51:24 -07:00
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