Commit Graph

2334 Commits

Author SHA1 Message Date
Steve Howell 19cf6d0e04 list_render: Remove data-list-render markup.
We already know which list widget a `<th>`
tag is associated with when we set up the
event handler, so it's silly to read data
from the DOM to find that widget again
when the handler runs.

This commit eliminates a whole class of possible
errors and busy work.
2020-04-15 15:13:26 -07:00
Steve Howell 37eeb90695 list_render: Clean up create/update.
For some widgets we now avoid duplicate redraw
events from this old pattern:

    widget = list_render.create(..., {
    }).init();
    widget.sort(...);

The above code was wasteful and possibly
flicker-y due to the fact that `init` and
`sort` both render.

Now we do this:

    widget = list_render.create(..., {
        init_sort: [...],
    });

For other widgets we just clean up the need
to call `init()` right after `create()`.

We also allow widgets to pass in `sort_fields`
during initialization (since you may want to
have `init_sort` use a custom sort before the
first render.)

Finally, we make the second and third calls
eliminate the prior updates from the previous
widget.  This can prevent strange bugs with
double-reversing columns (although that's
been prevented in a better way with a recent
commit), as well as avoiding double work
with sorting.
2020-04-15 15:13:26 -07:00
Steve Howell 0ff62fc6a2 list_render: Use namespaces for events. 2020-04-15 15:13:26 -07:00
Steve Howell eb1344c41c list_render: Fix filtering/sorting.
This code has always been kind of convoluted
and buggy, starting with the first
sorting-related commit, which put filtering
before sorting for some reason:

    3706e2c6ba

This should fix bugs like the fact that
changing filter text would not respect
reversed sorts.

Now the scheme is simple:

    - external UI actions set `meta` values like
      filter_value, reverse_mode, and
      sorting_function, as needed, through
      simple setters

    - use `hard_redraw` to do a redraw and
      trigger external actions

    - all filtering/sorting/reverse logic on
      the *data* happens in a single, simple
      function called `filter_and_sort`
2020-04-15 15:13:26 -07:00
Steve Howell 3aef11dc0e list_render: Extract get_list_scrolling_container().
We put this in `scroll_util` to make it more likely
we will eventually unify this with other scrolling
logic.  (A big piece to move is ui.get_scroll_element,
but that's for another PR.)

And then the other tactical advantage is that we get
100% line coverage on it.

I changed the warning to an error, since I don't
think we ever expect scrolling at the `body` level,
and I don't bother with the preview node.
2020-04-15 15:13:26 -07:00
Steve Howell 4e11e7ee5b Revert "list_render: Clean up initialization."
I pushed this risk commit to the end of
a PR that had a bunch of harmless prep
commits at the front, and I didn't make
it clear enough that the last commit (this
one) hadn't been tested thoroughly.

For the list_render widget, we can simplify
the intialization pretty easily (avoid
extra sorts, for example), but the cache aspects
are still tricky on subsequent calls.
2020-04-13 06:22:28 -04:00
Steve Howell 0681e4ba36 list_render: Clean up initialization.
For some widgets we now avoid duplicate redraw
events from this old pattern:

    widget = list_render.create(..., {
    }).init();
    widget.sort(...);

The above code was wasteful and possibly
flicker-y due to the fact that `init` and
`sort` both render.

Now we do this:

    widget = list_render.create(..., {
        init_sort: [...],
    });

For other widgets we just clean up the need
to call `init()` right after `create()`.

We also allow widgets to pass in `sort_fields`
during initialization (since you may want to
have `init_sort` use a custom sort before the
first render.)
2020-04-12 14:59:32 -07:00
Steve Howell 2b07512d22 list_render test: Split out scrolling/filtering.
We split one test into two simpler ones, and we
no longer bother with the load_count override,
which was only used in tests.
2020-04-12 14:59:32 -07:00
Steve Howell ced5511cdd list_render: Rename __set_events().
I rename it to set_up_event_handlers.

This commit does not attempt to fix any buggy
behavior with how we set up event handlers; it's
purely cosmetic.
2020-04-12 14:59:32 -07:00
Steve Howell 888214196c unread: Handle message edits that affect mentions.
We had a bug where if your peer mentioned you in
message, but then edited the message not to mention
you, the latter wouldn't reset your unread counts
for "Mentions".  And the same problem would happen
vice versa.

The fix basically extracts `update_message_for_mention`
and makes sure it handles all combinations of
unread/mentioned flags, instead of assuming
any invariants about which directions of change
are possible.

And then we call that new function from
`message_events.js` whenever we get message
edit events.

Fixes #14544
2020-04-11 12:00:46 -07:00
Steve Howell 32157ed6fd node test: Add message for unread/mentions test.
Add the "control" case here of a message that is
already read.
2020-04-11 12:00:46 -07:00
Steve Howell 253a740307 node tests: Use stream message in message_events.
We use a somewhat more realistic message, mostly
to prep for testing some mention/unread stuff in
a subsequent commit.

We also set message booleans.

Unfortunately, `recent_senders` is kind of awkward
for checking a single message, since its only
public API is for sorting.  I don't bother with it.

But I do check the `topic_data` interaction.
2020-04-11 12:00:46 -07:00
Steve Howell 80489843ee message store: Report type confusion errors.
We also complain if the caller sends us
`undefined`.
2020-04-09 16:11:57 -07:00
Steve Howell 9fa4ec56bb local echo: Fix type errors for message_send_error.
The function message_send_error was messing up
on calls to message.get when we were passing in
string versions of `local_id`.  Now we pass in
float ids.

This fixes a traceback where we tried to set
`.failed_request` on to an `undefined` value
that we had instead expected to be a locally
echoed message from our message store.
2020-04-09 16:11:57 -07:00
Steve Howell 1cd91ba9da compose test: Use more realistic ids.
We stop using `local_id_counter`, which was just noise,
and instead we just make the test more realistic:

    - Use 123.04 for our local id on the message that
      we're simulating sending.

    - Use 127 as the message id that the server gives
      us back in the success payload.
2020-04-09 16:11:57 -07:00
Steve Howell 5ecf74135a compose test: Stub less of echo.js.
We still stub echo functions, but for
one of our stubs (`try_deliver_locally`)
we now exercise one its actual callees
in the stub (`echo.insert_local_message`).

And we're still stubbing some callees
of `echo.insert_local_message`, since
that has all kinds of unwanted side
effects, too.

The main piece we want from
`insert_local_message`, for now,
is somewhat realistic handling of
our local message ids.

We also add a little sanity check
that our timestamp does get plumbed
through to `local_message.insert_message`.
2020-04-09 16:11:57 -07:00
sahil839 65d953b2af settings: Add option to disable video call in org settings.
Option is added to video_chat_provider settings for disabling
video calls.

Video call icon is hidden in two cases-
1. video_chat_provider is set to disabled.
2. video_chat_provider is set to Jitsi and settings.JITSI_SERVER_URL
   is none.

Relevant tests are added and modified.

Fixes #14483
2020-04-09 16:03:30 -07:00
Rohitt Vashishtha f9caf522f0 markdown: Allow setting a default language for code blocks.
This adds a new realm setting: default_code_block_language.

This PR also adds a new widget to specify a language, which
behaves somewhat differently from other widgets of the same
kind; instead of exposing methods to the whole module, we
just create a single IIFE that handles all the interactions
with the DOM for the widget.

We also move the code for remapping languages to format_code
function since we want to preserve the original language to
decide if we override it using default_code_clock_language.

Fixes #14404.
2020-04-09 16:02:02 -07:00
Vishnu KS a3164a3316 upload: Set the value of file input element to empty after upload.
Otherwise, if a user tries to upload the same file again the on change
event handler would not be called since there is no change in the value.
2020-04-09 12:38:59 -07:00
Tim Abbott c4589718fc settings: Move emoji widget code to settings_emoji.js.
It's the only bit of settings UI specific code that had ended up in
emoji.js.
2020-04-08 14:43:20 -07:00
Tim Abbott af7450ae01 filter: Fix missing test coverage.
This regression was introduced in the last commit.
2020-04-08 12:31:02 -07:00
YashRE42 52eaa7b562 filter: Add helpers for updated navbar features.
This is a prep commit for changes to the top navbar, it adds helpers
to filter.js which will help control the behavior of some aspects of
the redesigned navbar.

Modified by tabbott to add comments, internationalization tags on the
strings, support streams:public, and change various title strings.
2020-04-08 11:55:43 -07:00
Tim Abbott e0d5d5f136 filter: Fix sorted_term_types sorting of streams:public.
We had the wrong term type key in the sorting declaration, resulting
in this operator being always sorted last.
2020-04-08 11:54:27 -07:00
Tim Abbott 655993bf0f narrow: Don't advertise streams:public in is:starred.
We fix this by adding a more expressive data function, with tests, for
whether a filter is on UserMessage data, which would mean that
streams:public could never add additional matches.
2020-04-08 11:25:18 -07:00
Steve Howell e64059de79 node tests: Remove most test_log length assertions.
For all the places where we just make zero or one
blueslip call, asserting for length is either
unnecessary or overkill.
2020-04-08 11:37:27 -04:00
Steve Howell 9943a07e8c node tests: Improve handling of blueslip.fatal().
We now use `assert.throws()` to test that we're
properly calling `blueslip.fatal`.

In order to not break line coverage here, we have
to remove an unreachable `return` in `stream_data.js`.

Usually we test `fatal` for line coverage reasons.
Most places where we use `blueslip.fatal` fall in
these categories:

    * the code is theoretically unreachable, but
      we have `blueslip.fatal` for defensive reasons

    * we have some upstream bug that we should just
      fix

    * the code should recover gracefully and just
      use blueslip.errors()

It's possible that we should eliminate `blueslip.fatal`
from our API and just throw errors when really important
invariants get broken.  This will make it more obvious
to somebody reading the code that we're not going to
continue after the call, and `blueslip` already knows
how to catch exceptions and report them.
2020-04-08 11:37:27 -04:00
Steve Howell b788f18630 left sidebar: Fix topic list disappearing during pins.
When we redraw the left sidebar, we need to tell the
topic list to clear its data structures (and do other
stuff like hiding its popover), since we are clearing
its parent container.

The commit f0e18b3b3e
introduced this regression in late January 2020.
That commit made topic_list use a vdom to avoid
unnecessary updates.  Before that, topic_list did
a lot of brute-force redraws, which covered up the
fact that we weren't having stream_list telling it
when the rug was being pulled out from under it.

The boundary between stream_list and topic_list
has always been kind of complicated code, since
topic lists get embedded into the stream list.

The main interactions, though, are basically:

    * topic_zoom.clear_topics() - you're leaving
        a narrow that may or may not be zoomed

    * topic_list.clear() - you're about to redraw
        stream items in the unzoomed stream list

    * topic_list.rebuild(stream_li, stream_id) -
        you're building or updating a topic list
        for the newly active stream

Fixes #14465
2020-04-06 16:19:43 -07:00
Steve Howell e47ece6d2d tests: Remove unnecessary stubs for stream_list test. 2020-04-06 16:19:43 -07:00
Hashir Sarwar 9a6d83e731 lightbox: Use `$preview_src` as key for `asset_map`.
In case of video embeds, the previous logic used
`data-src-fullsize` or `src` as a key to look
for the metadata of video in `lightbox.open()`,
but while parsing, the key used while storing
the metadata was the video ID.

This doesn't make any sense because video's data
could never be accessed from `asset_map` and we
always needed to lookup the DOM for this.

This commit fixes this by using $img.attr('src')
as a key for `asset_map` for both, images and
videos. Since `src` is the link of preview image
in case of video embeds, it will always uniquely
determine the video ID and we won't loose
anything with the change in how videos handle
things.

Part of #14152.
2020-04-05 13:13:02 -07:00
Steve Howell 1ae07b93d8 presence: Simplify payload for webapp.
This changes the payload that is used
to populate `page_params` for the webapp,
as well as responses to the once-every-50-seconds
presence pings.

Now our dictionary of users only has these
two fields in the value:

    - activity_timestamp
    - idle_timestamp

Example data:

    {
        6: Object { idle_timestamp: 1585746028 },
        7: Object { active_timestamp: 1585745774 },
        8: Object { active_timestamp: 1585745578,
                    idle_timestamp: 1585745400}
    }

We only send the slimmer type of payload
to clients that have set `slim_presence`
to True.

Note that this commit does not change the format
of the event data, which still looks like this:

    {
        website: {
            client: 'website',
            pushable: false,
            status: 'active',
            timestamp: 1585745225
        }
    }
2020-04-03 11:44:56 -07:00
Steve Howell da6508a7af presence tests: Test for offline/reload use cases.
This gets us to 100% line coverage.
2020-04-03 11:42:59 -07:00
Steve Howell f7b432afec node tests: Auto-include zblueslip for node tests.
We already use blueslip stubs in ~45 tests, so we
may as well just auto-include it.
2020-04-03 12:56:49 -04:00
Steve Howell 09336c9e28 node test: Clean up ad hoc mocks for blueslip. 2020-04-03 12:56:49 -04:00
Steve Howell df84c52a7f zblueslip: Change API to expect/reset.
The `set_test_data` never made complete sense to
me, since it wasn't really data that we were
setting.
2020-04-03 12:56:49 -04:00
Steve Howell ec2aaa52dd zblueslip: Prevent spurious expected errors.
This also cleans up some idioms in the zblueslip
code.
2020-04-03 12:56:49 -04:00
Steve Howell 2788ebdde7 minor: Clean up blank lines in tests. 2020-04-03 12:56:49 -04:00
Tim Abbott 09a0f01586 node tests: Add test_realm_integer test for bot_creation_policy.
This fills in a missing test I noticed while reviewing the adjacent
code.
2020-04-02 17:34:43 -07:00
sahil839 72a18ba7d4 tests: Stop using ttest_realm_boolean for integer fields.
This adds a new test_realm_integer, replacing test_realm_boolean for
testing integer fields like realm_create_stream_policy,
realm_invite_to_stream_policy, and realm_invite_required in dispatch.js.

Fixes #12284
2020-04-02 17:34:43 -07:00
sahil839 50d65fffe6 tests: Change policy elements value to correct type in page_params.
Fields like realm_email_address_visibility and realm_bot_creation_policy
were strings instead of integers in page_params obeject in
settings_org.js tests.

Also use values struct defined in settings_config.js and setting_bots.js
instead of direct values for improving readability.
2020-04-02 17:34:43 -07:00
Steve Howell 02947d6b41 blueslip: Protect against drafts pitfall for rows.id.
If folks use an overly broad selector for message rows,
they will accidentally include drafts from the drafts
dialog, which won't have zids.  More specific selectors
will be more efficient and possibly prevent strange
behaviors.

For testing convenience, we extract the message.
2020-04-02 14:44:35 -07:00
Ryan Rehman 5a5fc6caa1 stream edit: Fix real-time sync of stream notification setting.
The UI in the `#settings/notifications` page is updated similarly
to what is done in the `update_global_notifications` path present
in the `server_events_dispatch` file.
2020-04-01 14:40:41 -07:00
Anders Kaseorg 1c8950900f frontend: Defensively filter unsafe links that may come from bugdown.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-01 14:01:45 -07:00
Anders Kaseorg 4f748fb627 markdown: Stop setting target="_blank".
This setting is being overridden by the frontend since the last
commit, and the security model is clearer and more robust if we don't
make it appear as though the markdown processor is handling this
issue.

Co-authored-by: Tim Abbott <tabbott@zulipchat.com>
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-01 14:01:45 -07:00
Anders Kaseorg 68cfcd6446 CVE-2020-9444: Prevent reverse tabnabbing attacks.
While we could fix this issue by changing the markdown processor,
doing so is not a robust solution, because even a momentary bug in the
markdown processor could allow cached messages that do not follow our
security policy.

This change ensures that even if our markdown processor has bugs that
result in rendered content that does not properly follow our policy of
using rel="noopener noreferrer" on links, we'll still do something
reasonable.

Co-authored-by: Tim Abbott <tabbott@zulipchat.com>
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-01 14:01:45 -07:00
Ryan Rehman c759083cb8 notification settings: Add helper function for stream notifications.
This function returns a list of objects to create a
list_render object, and each item contains the streams
whose atleast one notification setting differs from the
default set by the user.

This is done by comparing the global settings in the
`#settings/notifications` page with those settings
present in the subscribed streams.

Work towards #9228.
2020-03-31 15:36:59 -07:00
Tim Abbott 0f238f29fb unread: Remove suppress_unread_counts flag.
This flag was used to delay unread count updates while the bankruptcy
modal was visible.  Now that bankrupcty is no longer a modal, we don't
need this flag at all.
2020-03-31 15:30:52 -07:00
Stefan Weil d2fa058cc1
text: Fix some typos (most of them found and fixed by codespell).
Signed-off-by: Stefan Weil <sw@weilnetz.de>
2020-03-27 17:25:56 -07:00
sahil839 a2efe3ab64 narrow: Show starred messages from muted topics in starred message view.
Starred messages from muted topics were not shown in the starred
messages view. Condition for muting_enabled is modified accordingly
such that the starred messages from muted topics is shown in the
starred messages narrowed view.

Node tests are updated accordingly.

Fixes #13548
2020-03-27 00:17:26 -07:00
Tim Abbott 0308ded874 node tests: Fix coverage issues for recent panels.js changes. 2020-03-26 14:16:41 -07:00
Jagan 5a1df798bc banner: Notify organization admins to change default description.
We've noticed that many production organizations don't set either an
organization description or profile picture, even large open source
organizations that could definitely take advantage of this feature.

This adds a top-of-page banner that bugs organization administrators
to add an organization description and profile picture, generally
starting on the second login (as we only do it on page load after
notifications are configured).

Significantly tweaked by tabbott to get the right user experience.

Fixes #14019.
2020-03-26 13:10:37 -07:00