Commit Graph

7632 Commits

Author SHA1 Message Date
Vishnu KS def1e01512 i18n: Translate quote and reply mention text.
Fixes #17479
2021-03-25 10:38:33 -07:00
Abhijeet Prasad Bodas 423770f189 refactor: Extract starred_messages_ui.js module.
This is a direct code move which will allow us
to enforce 100% coverage on the data handling
parts of starred_messages.js.
2021-03-25 02:26:44 -07:00
Nishant Mittal b845694e72 dropdown_list_widget: Display default_text for invalid values.
Fixes #16946.
2021-03-25 01:25:18 -07:00
Aman Agrawal 0b9578f457 recent_topics: Load filters from localstorage before rendering.
We were loading filters from localstorage after rendering the
filters block which caused the incorrect icons being displayed
for filters.

Since usually recent_topics renders a couple times when it
is loaded directly and the filters were being loaded as part of
show_selected_filters after we rendered recent_topics filters,
it meant the correct filters were being displayed in the
second render.

But, when user loads any other narrow directly when Zulip is loaded,
and opens recent_topics, recent_topics is only rendered once,
hence the bug gets noticed.

Fixes #17496
2021-03-25 01:22:19 -07:00
m-e-l-u-h-a-n 2699048208 markdown: Extend user mention syntax to support user_id for mentioning.
Extend our markdown system to support mentioning of users
by id also. Following these changes, it would be possible
to mention users with @**|user_id** and silently mention
using @_**|user_id**.

Main intention for extending the mention syntax is to make
it convenient for bots to mention a users using their ids. It
is to be noted that previous syntax are also supported.

Documentation tweaked by tabbott for better readability.

The changes were tested manually in development server, and also
by adding some new backend and frontend tests.

Fixes: #17487.
2021-03-25 00:44:56 -07:00
YashRE42 abd959cf6a server_events_dispatch: Throw blueslip from typing based on event.op. 2021-03-24 15:04:00 -07:00
YashRE42 a93adbfa76 server_events_dispatch: Throw blueslip from stream based on event.op. 2021-03-24 15:04:00 -07:00
YashRE42 f69de35267 server_events_dispatch: Throw blueslip from realm_user based on op. 2021-03-24 15:04:00 -07:00
YashRE42 27ac45e71b server_events_dispatch: Throw blueslip from realm_domains based on op. 2021-03-24 15:04:00 -07:00
YashRE42 4ffdfb5f00 server_events_dispatch: Throw blueslip if wrong op in realm_bot case. 2021-03-24 15:04:00 -07:00
YashRE42 d50bc7441a server_events_dispatch: Refactor realm_bot case to use switch/case.
This should make no functional changes.
2021-03-24 15:04:00 -07:00
YashRE42 b89363cec3 server_events_dispatch: Refactor realm event to use switch/case.
This should make no functional changes.
2021-03-24 15:04:00 -07:00
YashRE42 195b1b28ee server_events_dispatch: Throw blueslip if update_dict without prop. 2021-03-24 15:04:00 -07:00
YashRE42 e3b6cc61f3 server_events_dispatch: Throw from "reaction" based on event.op. 2021-03-24 15:04:00 -07:00
YashRE42 bf86422116 server_events_dispatch: Refactor 'reaction' case to use switch/case. 2021-03-24 15:04:00 -07:00
YashRE42 bc69521caa server_events_dispatch: Throw from "subscription" based on event.op. 2021-03-24 15:04:00 -07:00
Anders Kaseorg 6de39ae92d js: Clean up typeof … === "undefined" checks.
The only reason to use typeof foo === "undefined" is when foo is a
global identifier that might not have been declared at all, so it
might raise a ReferenceError if evaluated.  For a variable declared
with const or let or import, a function argument, or a complex
expression, simply foo === undefined is equivalent.

Some of these conditions have become impossible and can be removed
entirely, and some can be replaced more idiomatically with default
parameters (note that JavaScript does not share the Python misfeature
of evaluating the default parameter at function declaration time).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-24 13:15:01 -07:00
Steve Howell 57d79e8fd6 refactor: Extract color_class module.
This breaks some indirect dependencies on subs
and message_view_header.
2021-03-24 12:22:27 -07:00
Steve Howell f3b1e723e0 typeahead: Eliminate render caches.
These were introduced in ff9a929d7a
with no explanation of why they were necessary.

Generally you only render a few things, and it's
important that they're up to date.

We weren't doing a good job of invalidating the cache.

Eliminating the cache will fix bugs (like presence circles
being out of date) and break some dependencies.

I removed some very fragile test code that was relying
on invalid values taken out of the cache.  (We now have
less line coverage, but if we want to test our rendering,
there are much cleaner ways to do it.)

As part of testing this, I renamed Hamlet to "aaron", so
that there are two aarons, and then I logged on as Iago
to see the "secondary" code in action that shows their
emails to distinguish them.
2021-03-24 12:15:36 -07:00
Anders Kaseorg fb688e8e5d server_events_dispatch: Fix Prettier formatting.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-23 14:17:08 -07:00
YashRE42 592eb1a197 server_events_dispatch: Refactor user_group to use switch/case. 2021-03-23 13:56:21 -07:00
YashRE42 8d578c248f server_events_dispatch: Refactor typing event to use switch/case. 2021-03-23 13:56:21 -07:00
YashRE42 60b7211b1f server_events_dispatch: Refactor stream case to use switch/case. 2021-03-23 13:56:21 -07:00
YashRE42 1b4fc178c1 server_events_dispatch: Refactor realm_user to use switch/case.
This should make no functional changes.
2021-03-23 13:56:21 -07:00
YashRE42 33fb78af42 server_events_dispatch: Refactor realm_domain to use switch/case.
This should make no functional changes.
2021-03-23 13:56:21 -07:00
YashRE42 d575517035 server_events_dispatch: Refactor update_dict op of realm case.
This should make no functional changes.
2021-03-23 13:56:21 -07:00
YashRE42 f4afe770e4 server_events_dispatch: Refactor subscription case to use switch/case.
This commit should make no behavioural changes.
2021-03-23 13:53:23 -07:00
shanukun cfe0fa3788 event_schema: Add schema check for realm/deactivated event.
This add the schema checker, openapi schema, and also a test for
realm/deactivated event.

With several block comments by tabbott explaining the logic behind our
behavior here.

Part of #17568.
2021-03-23 12:16:16 -07:00
Steve Howell 65ec8f2000 refactor: Move suspect_offline logic into watchdog.
This breaks some indirect dependencies in presence.js.
2021-03-23 14:08:39 -04:00
YashRE42 5b0db2e7ed templates.js: Remove unused "plural" helper.
This helper was added in eac6463031 and
used by the "message.handlebars" file. This is no current call for
this helper in the codebase, hence it is removed to improve coverage.

This commit also marks template.js to have 100% test coverage.
2021-03-23 10:46:04 -07:00
Anders Kaseorg 9553f11387 eslint: Forbid CommonJS variables in ES6 modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-23 01:42:43 -07:00
Abhijeet Prasad Bodas 42aea49784 left sidebar: Add support to unstar all messages in topic.
This adds support for unstarring all (starred)
messages from a particular topic, from the topic
popover.

The earlier implementation of this in #16898
was reverted in bc55aa6a01 (#17429)
because it had two problems-

1. The crash reported in bc55aa6a01
was due to message_store returning undefined. This happens
when the message itself hasn't been fetched from the server
yet, but we know that the message is starred from the ids
in `page_params` in `starred_messages.js`.
This commit handles this case explicitly.
Note that, we simply ignore those messages which
we haven't fetched, and because of this, it may
happen that we don't unstar some messages from that
topic. The correct implementation for this would
be to ask the backend for starred IDs in a topic.

2. The earlier implementation actually unstarred **all**
messages. This was because it grabbed the topic and stream_id
from the topic popover `data` attributes, after the topic
popover had been closed. This passed `undefined`, which
the function then interpreted as an action to unstar all
messages.
With this commit, we use the confirm_dialog widget,
which eliminates the need to store this data in the DOM.
2021-03-23 00:17:15 -07:00
Abhijeet Prasad Bodas f17a52b2f3 refactor: Use confirm_dialog for unstar-all-messages.
This replaces the separate modal shown on clicking
"Unstar all messages" from the left sidebar to use
the confirm_dialog widget instead.
2021-03-23 00:17:15 -07:00
Abhijeet Prasad Bodas eb7b699ac9 confirm_dialog: Make it usable outside settings.
* Currently, the confirm_dialog is used only in
the settings pane, which already has the `new-style`
class in the main `settings_overlay.hbs` file. So,
the confirm modal is rendered correctly there. But to
make it available for use outside of the settings pane,
we add the `new-style` class to the confirm container
itself, without which, the buttons look ugly.

* The other change here is the click handler for
removing the modal element. Previously, when the
modal was closed (with any of the "yes"/"no"/"cross"
buttons), there was a small time interval of around
a second during which the modal had disappeared,
but the background content was still in the faded-out
state. This change fixes this glitch. This glitch was
probably not noticable earlier, because the settings
pane itself causes the background to be slightly faded
out.
2021-03-23 00:17:15 -07:00
Abhijeet Prasad Bodas 1cc6f6158e left sidebar: Fix exception on opening all/starred popovers.
This code was added in 2d414fa897, after
the `window.exports` variable was removed from
`stream_popovers.js`, while converting it to an ES6 module
in c71af35461. This resulted
in opening the starred messages or all messages
popovers throw `Error: exports in undefined.`.
2021-03-22 23:56:50 -07:00
Anders Kaseorg d22a61443e notifications: Remove in_browser_notify and bootstrap-notify.
Follow up to #14768.  This feature was already non-functional due to
.alert-display { display: none; }, and if we want to reimplement it,
we should do it using a modern library.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-22 23:40:38 -07:00
Anders Kaseorg aff8a32bc1 notifications: Simplify sound playing.
Remove the unused notifications-area wrapper.  Remove the feature
detection code as all browsers recognize the <audio> element.  Create
the <audio> statically with the page template.  Use multiple <source>s
to let the browser detect the appropriate format instead of trying to
do its job for it.  Remove the absurd loop="yes" attribute, which had
fortunately been specified on the wrong element.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-22 23:36:38 -07:00
Steve Howell 72e0f2e901 bots: Lift render_bots calls to dispatcher code.
This is mostly a refactoring to break the unnecessary
dependency of bot_data on settings_bots.

This is a bit more than a refactoring, as I remove all
the debounced calls to render bots during the
initialization of bot_data. (The debouncing probably
meant we only rendered once, but it was still needless
work.)

We don't need to explicitly render bots during
bot_data.initialize(), which you can verify by loading
"#settings/your-bots" as the home page. It was just an
artifact of how add() was implemented.

Note that for the **admin** screen, we did not and
still do not do live updates for add/remove; we only do
it for updates. Fixing that is out of the scope of this
change. The code that was moved here affects
**personal** bot settings.

Note that the debounce code is quite fragile. See my
code comment that explains it. I don't have time to go
down the rabbit hole of a deep fix here. The puppeteer
tests would fail without the debounce, even though I
was able to eliminate the debounce in an earlier
version of this fix and see good results during manual
testing. (My testing may have just been on the "lucky"
side of the race.) I created #17743 to address this
problem.
2021-03-22 19:40:06 -07:00
Gaurav Pandey dea5245590 right-sidebar: Fix design bugs with keyboard-shortcuts.
The keyboard-shortcuts icon currently has a fix position
causing design related bugs such as overlapping with userlist
in the sidebar.

The fix wraps the invite-more-users link and keyboard icon inside
a div with display property as flex instead of just using the anchor
tags inside the side-bar items.
2021-03-22 19:29:46 -07:00
Steve Howell 746cc9e1f6 refactor: Extract browser_history module.
This mainly extracts a new module called
browser_history. It has much fewer dependencies
than hashchange.js, so any modules that just
need the smaller API from browser_history now
have fewer transitive dependencies.

Here are some details:
    * Move is_overlay_hash to hash_util.
    * Rename hashchange.update_browser_history to
      brower_history.update
    * Move go_to_location verbatim.
    * Remove unused argument for exit_overlay.
    * Introduce helper functions:
        * old_hash()
        * set_hash_before_overlay()
        * save_old_hash()

We now have 100% line coverage on the extracted
code.
2021-03-22 13:29:32 -07:00
Steve Howell 67a487db79 refactor: Extract message_parser module.
I moved four functions, verbatim, to a new module.
They were in message_util before, which led to
filter.js having several accidental indirect
dependencies.

I considered just putting these four functions in
filter.js, but I think it's a nice abstraction boundary
that filter.js delegates actual message parsing, and
the original author apparently had a similar thought
process.

I also wanted to make it so that a casual reader of
filter.js doesn't think we are manipulating DOM. It's
true that we still indirectly require jquery here, but
it's only for parsing, and it seems plausible we would
eventually use a more low-level parser.

I can see us maybe using these functions in something
like MessageListData in the future, so speculatively
splitting them out might future-proof us from some
cyclical dependencies.

I also think it's plausible that we will just modify
our two markdown processors to attach that kind of
metadata to the messages.

Last but not least, I think there might be opportunity
here to simplify the filter tests and remove some of
the zjquery hacks. We would instead just mock the
message_has_* helpers for the filter tests, and then
do more detailed direct testing on the functions
themselves.
2021-03-22 13:21:56 -07:00
Steve Howell 1cee29c2d1 refactor: Extract stream_bar.decorate.
This makes input_pill no longer depend on
stream_data and stream_color, and it
probably reduces some other dependencies.
2021-03-22 13:21:56 -07:00
Steve Howell dbf19fe8d7 refactor: Extract watchdog module.
We now have 100% code coverage on this somewhat
fiddly code.

We also break activity's dependency on server_events.
2021-03-22 13:17:37 -07:00
Steve Howell d644e42dc1 refactor: Move desktop_icon_count_display_values. 2021-03-22 13:17:37 -07:00
Steve Howell a429ecbb1b refactor: Move get_notifications_table_row_data.
The only caller for this function was settings_config,
so we put it there.

For the stream_edit test we no longer mock the function.
(The reason we mocked the function was more about avoiding
the heavy settings_notifications import than the function
itself.)  This gives some incidental coverage, but then I
also add some more real coverage on it.
2021-03-22 13:17:37 -07:00
Steve Howell 855ac26c48 compose fade: Extract compose_fade_users class.
We extract compose_fade_users and compose_fade_helper.

This is a pretty verbatim extraction of code, apart from adding a few
exports and changing the callers.

This change makes the buddy_data module no longer sit "above" these
files in the dependency graph (at least not via compose_fade):

    * jquery
    * lodash (not a big deal)
    * compose_state
    * floating_recipient_bar
    * message_viewport
    * rows

The new moules have dependencies that buddy_data already
had directly for other reasons:

    * people
    * util

And then buddy_data still depends on stream_data indirectly through
the compose-fade logic for stream_data. Even without compose-fade, it
would depend indirectly on stream_data via hash_util.

Note that we could have lifted the calls to compose_fade out of
buddy_data to move some dependencies around, but it's useful to have
buddy_data fully encapsulate what goes into the buddy list without
spreading responsibilities to things like activity.js and
buddy_list.js. We can now unit-test the logic at the level of
buddy_data, which is a lot easier than trying to do it via modules
that delegate drawing or do drawing (such as activity.js and
buddy_list.js).

Note that we still don't have 100% line coverage on the
compose_fade.js module, but all the code that we extracted now is
covered, mostly via buddy_data tests.
2021-03-21 20:16:08 -07:00
Steve Howell ec46827ebd refactor: Move user_can_change_* to settings_data.
This simplifies our dependency graph and puts easily
testable functions into a module where we enforce
100% coverage.

All the code was moved verbatim.
2021-03-21 17:07:41 -07:00
Steve Howell 0014bc1549 node tests: Add test() wrapper for channel. 2021-03-20 11:00:48 -04:00
Anders Kaseorg 0d218a4b76 eslint: Enable @typescript-eslint/consistent-type-imports.
TypeScript type-only imports will probably become important eventually
for reducing our circular import problem.

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-18 17:26:19 -07:00
Abhijeet Prasad Bodas 206fe1ef3b node tests: Introduce message_store.create_mock_message() helper.
Previously, it was tedious to create actual message
objects in message_store for use in node tests.
This was mainly because, `add_message_metadata`
in message_store has many dependencies and
validation checks. Since it was difficult to create
actual message objects, many tests just mocked
the `message_store.get()` method to return the desired
message.

This commit adds a new helper method (`create_mock_message`)
to message_store, for use in node tests. This just stores
the object passed to it in the `stores_messages` map,
without any validation. We do not add any
default fields to the message object before saving
it from this helper, because doing so would decrease
the utility of this helper, and, if a test
depends on some field having a particular value,
then it would be better to just pass the field: value
pair from the test itself, for readability, rather
than relying on the helper to add the field for us.

This helper allows us to write deeper tests.

This commit also replaces some instances of mocking
`message_store.get()` to use this new helper method.
2021-03-18 15:55:39 -07:00