Commit Graph

3082 Commits

Author SHA1 Message Date
sahil839 235601d3b6 stream_data: Modify remove_subscriber to use stream id.
This commit changes stream_data.remove_subscriber to use stream id
instead of stream name. We are using stream ids so that we can
avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 ddbfbdc386 stream: Modify stream_data.add_subscriber to use stream_id.
Thsi commit changes stream_data.add_subscriber to use stream_id
instead of stream name. We are using stream ids so that we can
avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 320d0ca806 stream: Remove stream_edit.rerender.
This commit removes stream_edit.rerender function. We directly
call subs.rerender_subscriptions_settings directly from
server_events_dispatch.js, which was the only caller of rerender
function, as we already have sub object.
We are using stream ids so that we can avoid bugs related to live
update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 30c55a1ea7 recent_topics: Use get_sub_by_id in format_topic to get stream info.
We can use get_sub_by_id instead of get_sub to get the stream info,
as we already have stream id from the message object. We are using
stream ids so that we can avoid bugs related to live update after
stream rename.
2020-06-22 13:39:47 -07:00
sahil839 f3604fbb1e stream_edit: Refactor receives_notifications to use stream ids.
This commit changes receives_notifications function to use
stream_ids instead of stream names. We are using stream ids so
that we can avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
Mohit Gupta 02ea52fc18 filter: Implement has: filters on client side.
Prior to this commit has:link, has:attachment, has:image
filter couldn't be applied locally and deferred filtering to
web server. This commits make sure client filters all messages
it can instead of completely deferring to the server and hence
improve speed.

A tradeoff is also made to turn off local echo for has: narrows
as messages with link sent to has:link narrow were locally echoing
to another narrow and not appearing in the active has:link narrow.

Fixes: #6186.
2020-06-21 10:26:09 -07:00
MariaGkoulta b10f156250 settings: Add automatic theme detection feature.
With this implementation of the feature of the automatic theme
detection, we make the following changes in the backend, frontend and
documentation.

This replaces the previous night_mode boolean with an enum, with the
default value being to use the prefers-color-scheme feature of the
operating system to determine which theme to use.

Fixes: #14451.

Co-authored-by: @kPerikou <44238834+kPerikou@users.noreply.github.com>
2020-06-21 01:09:01 -07:00
Aman Agrawal a052d24231 recent_topics: Support arrow key navigation.
Add arrow key navigation support for recent topics.

Simple jquery is used to allow navigation for filter buttons,
a grid system is used for navigation inside table.
2020-06-20 22:50:47 -07:00
Ryan Rehman d59ccd4c0f message view: Fix link generation logic of the end of results notice.
This improves the logic and fixes the bug where the href was calculated
based on the current URL and not the filter of the current message list.

We now add the '/streams/public/' operator at the start of the operators,
similar to how it is represented in all other cases.

Fixes #15405
2020-06-20 16:26:25 -07:00
Ryan Rehman 21cdc26193 search: Support multiple search pills creation.
This reverts part of b0d632577f.
The problem was that multiple queries were combined as a single
search pill. And since we create the pills then narrow / search,
we added a comma seperator between them for the typeahead lookups
as required by the logic in `input_pill.js`.

This however introduced a new bug where the search suggestions
were incorrect as the typeahead lookup table wasn't updated, so
every time an item from the type ahead was selected it updated
the input string with an invalid operator.

Thus to resolve the first problem, we follow a simpler approach
by extracting all operators from the search string using our
`Filter.parse` logic and next add the pills, one by one.
2020-06-19 16:18:52 -07:00
Ryan Rehman 70b92c7eb3 search: Clicking on a search pill should not lose searchbox focus.
Whenever a search pill is selected or deleted by a click the navbar
gets rendered as the searchbox loses focus. This allows the user to
be able to continue editing the search query without having to refocus
the searchbox.
2020-06-19 16:18:52 -07:00
Ryan Rehman 63643c9d9d search: Fix blur event handler for `search_query_box`.
A main change is that we now display the navbar if the search box
is not focused. This was already present in the search pills version
but adding it to the legacy version is an improvement.

We sufficiently increase the timeout so that the pills are actually
deleted. This was required when `filter.is_common_narrow()` is true,
as then only we render the narrow description and close the search bar.

This commit also matches another behaviour of the legacy search.
i.e. We narrow every time a search suggestion is clicked.

The now redundant "focusin" and "focusout" event handler tests are
also removed.
2020-06-19 16:18:52 -07:00
Steve Howell 00e60c0c91 events: Use stream_id for peer_add/peer_remove.
Two things were broken here:
    * we were using name(s) instead of id(s)
    * we were always sending lists that only
      had one element

Now we just send "stream_id" instead of "subscriptions".

If anything, we should start sending a list of users
instead of a list of streams.  For example, see
the code below:

    if peer_user_ids:
        for new_user_id in new_user_ids:
            event = dict(type="subscription", op="peer_add",
                         stream_id=stream.id,
                         user_id=new_user_id)
            send_event(realm, event, peer_user_ids)

Note that this only affects the webapp, as mobile/ZT
don't use this.
2020-06-19 14:48:42 -07:00
sahil839 821e25ffb0 streams: Show message retention policy details in subscription_type text.
This commit adds message retention policy details in the subscription_type
text below the stream description.

We do not show any text when realm-level settings is set to forever and
stream-level is set to either forever or realm_default.
2020-06-18 17:13:04 -07:00
sahil839 d9b7228444 streams: Add frontend to set/update message_retention_days of a stream.
This commit adds frontend support for setting and updating message
retention days of a stream from stream settings.

Message retention days can be changed from stream privacy modal of the
stream and can be set from stream_creation_form while creating streams.

Only admins can create streams with message_retention_days value other
than realm_default.

This commit also contains relevant changes to docs.
2020-06-18 17:00:34 -07:00
Rohitt Vashishtha 6ea3816fa6 markdown: Use html5 <time> tag for timestamps.
Previously, we had implemented:
    <span class="timestamp" data-timestamp="unix time">Original text</span>
The new syntax is:
    <time timestamp="ISO 8601 string">Original text</time>
    <span class="timestamp-error">Invalid time format: Original text</span>

Since python and JS interpretations of the ISO format are very
slightly different, we force both of them to drop milliseconds
and use 'Z' instead of '+00:00' to represent that the string is
in UTC. The resultant strings look like: 2011-04-11T10:20:30Z.

Fixes #15431.
2020-06-18 14:11:33 -07:00
Tim Abbott ba1f2dfdfa pointer: Merge pointer.js into message_scroll.js.
Ths remaining code here is naturally message scrolling logic, and fits
well into the existing file for handling that.
2020-06-18 12:55:59 -07:00
Tim Abbott 94e6cb9abd pointer: Remove frontend logic tracking furthest_read.
Since we are no longer using the "pointer" value sent in
page_params.pointer for anything, there's no value in continuing to
send it from the server to the client.

The remaining code in pointer.js is logic managing state for the
currently selected message.
2020-06-18 12:55:59 -07:00
Steve Howell 9fdd98cf88 refactor: Clean up add/remove_sidebar_row.
The stream_events tests were kinda messy, but
I mostly just consolidated a few sections of
code so that we didn't have to keep
re-stubbing the same functions.

For the actual code, I extracted add_sidebar_row
and then removed the unnecessarily complicated
jQuery trigger mechanisms.
2020-06-18 09:08:46 -07:00
Ryan Rehman 69f9c72edc search suggestions: De-duplicate legacy search codepath.
This merges the `exports.get_search_result_legacy` and
`exports.get_search_result` function.

The key differences between the two code paths are as follows:

* We only want to generate suggestions for the queries which
  the user is typing or can edit.
  For the legacy version, suggestions are displayed for the
  entire search string in the searchbox. (`all_operators`)
  For the pills enabled version, suggestions are displayed
  only for the input which hasn't been converted to pills.
  (`query_operators`)
  `all_operators` = `base_query_operators` + " " +  `query_operators`.
  trim is added at the end just to handle the legacy case
  where we pass the `base_query` as ''.

* It is not possible to detect whether the user wants to
  continue typing in the legacy version. However if the
  the searchbox is still focused even after pill creation
  we can assume the user still wants to continue typing.
  To handle this we push an empty term as the `last` operator.
  This is possible since the previous queries have been
  completely entered as evident from it's generated pill.

* When using the legacy version, `search_operators` are
  the same as `all_operators`, as mentioned in point 1.
  In the pills enabled version we perform most of the
  computations from the `query_operators`, but we do
  require all `all_operators`, only for filtering the last
  query's suggestion.

* And there is just one block unique to the legacy search
  system. More details are mentioned in the comments of that
  block.

We also refactor both the search suggestions node tests,
mainly to make them similar and easier to detect differences
when we switch over to the new version.
2020-06-18 01:44:15 -07:00
Ryan Rehman 531a803bfc typeahead: Allow automated selection for `contenteditable` elements.
This adds the support of our auto completion behaviour of the legacy
search code into the search pills version.
2020-06-18 01:35:19 -07:00
Tim Abbott f28b38bd8c message_fetch: Use first unread anchor for home view.
This fixes one of our oldest important user experience issues, namely
that if you never visit the home view, the Zulip webapp would often
load "deep in the past" because the pointer had not advanced.

Fixes #1529.
2020-06-17 18:08:48 -07:00
Aman Agrawal 77bbbf7ae0 message_fetch: Raise fatal error in an impossible case.
When fetching older/new messages, we used to resort to the pointer
to act as anchor when message list was empty.

This appears to be an impossible case, as
`fetch_status.can_load_newer_messages`
should be false in this case and user cannot be scrolling an
empty message_list in the first case.

Hence, we raise a fatal error to inform user of the same.
2020-06-17 18:08:48 -07:00
jagansivam28 548107632c settings org: Use `image_upload_widget.hbs` for realm day/night logo.
Now we can use common HTML image upload widget template
`image_upload_widget.hbs` for realm day/night logo and
we should access those day/night logo elements using
e.g., "#realm-day/night-logo-upload-widget .realm-logo-elements".
since we use image_upload_widget.hbs for realm day/night logo upload
widget we need to extract CSS for realm day/night logo and
place them separately under `#realm-day-logo-upload-widget`
and `#realm-day-logo-upload-widget` css id.
2020-06-17 17:47:49 -07:00
jagansivam28 e132db3480 settings org: Use `image_upload_widget.hbs` for realm icon.
Now we can use common HTML image upload widget template
`image_upload_widget.hbs` for realm icon. we can access icon
element using "#realm-icon-upload-widget .realm-icon-elements".
also we need to extract CSS for realm icon and place them
separately under `#realm-icon-upload-widget` css id.
2020-06-17 17:47:49 -07:00
Clara Dantas ddbde66af5 realm: Remove Google Hangouts integration.
Google  has removed the Google Hangouts brand, thus we are removing
them as video chat provider option.
This commit removes Google Hangouts integration and make a migration
that sets all realms that are using Hangouts as their video chat
provider to the default, jitsi.

With changes by tabbott to improve the overall video call documentation.

Fixes: #15298.
2020-06-16 17:02:27 -07:00
Sara Gulotta 1cb040647b markdown: Add support for spoilers.
This adds support for a "spoiler" syntax in Zulip's markdown, which
can be used to hide content that one doesn't want to be immediately
visible without a click.

We use our own spoiler block syntax inspired by Zulip's existing quote
and math block markdown extensions, rather than requiring a token on
every line, as is present in some other markdown spoiler
implementations.

Fixes #5802.

Co-authored-by: Dylan Nugent <dylnuge@gmail.com>
2020-06-16 16:14:10 -07:00
jagansivam28 0e5c6fa578 user avatar: Remove `user_avatar_upload_button` id.
The upload text element is wrongly named as id=user_avatar_upload_button.
now  we can remove that id and access upload text element from
`#user-avatar-upload-widget .settings-page-upload-text` so that we
can have only one id at top-level  and 'image_upload_widget.hbs` can
be more dynamic so we can use for other similar widgets also.
2020-06-16 12:12:21 -07:00
jagansivam28 b3fca96254 user avatar: Remove user_avatar_delete_button id.
we can remove `user_avatar_delete_button` id and access delete button
from `#user-avatar-upload-widget .settings-page-delete-button` so that
we can have only one id at top level and 'image_upload_widget.hbs`
can be more dynamic so we can use for other similar widgets also.
2020-06-16 12:12:21 -07:00
Priyank Patel cb7237c3aa puppeteer: Update the structure of common.get_rendered_messages.
This structure will allows us to verify correct interleaved view.
Design of the API was by Tim.
2020-06-16 11:40:30 -07:00
Ryan Rehman 62aab0d9ee message view: Fetch again when "newest" is discarded.
The previous commit introduced a bug where it was not intuitive
for the user to scroll again.
For the current narrow, new messages were fetched again only when
scrolled to the bottom as usually there are many messages displayed.

However when the edge case mentioned in the previous commit
occured, it was not very obvious that a scroll should be done
or we could already be at the bottom and could not scroll again
to trigger a fetch.
`message_viewport.at_bottom` has a relevant comment explaining
this behaviour.

The previous commit handled the rare race condition. However,
there is a possibility that the rare race condition might occur
again while we are handling the previous condition.

This commit resolves these 2 problems by performing a re-fetch
while also resetting the `expected_max_message_id` and this
approach has two benefits:

1. The reset prevents an infinite loop, if somehow the expected
   max message's id gets corrupted resulting in a situation
   where the server can never send an id greater than that even
   after fetching.

2. Even though we stop after just one re-fetch the race condition
   might recursively occur while we handle the previous race
   condition. And even though the reset prevents multiple re-fetches,
   we don't have the missing message problem.

   This is because we treat the next race condition as a new race
   condition instead of it being a continuation of the previous.

   The `expected_max_message_id` gets updated again, on receiving
   a new message. Thus it can again enter the `fetch_status` block
   as the reset value is updated again.
2020-06-16 11:11:16 -07:00
Ryan Rehman 6637f2dbb7 message list: Render new messages only after "newest" is found.
If a user sends a message while the latest batch of
messages are being fetched, the new message recieved
from `server_events` gets displayed temporarily out of
order (just after the the current batch of messages)
for the current narrow.

We could just discard the new message events if we havent
recieved the last message i.e. when `found_newest` = False,
since we would recieve them on furthur fetching of that
narrow.
But this would create another bug where the new messages
sent while fetching the last batch of messages would not
get rendered. Because, `found_newest` = True and we would
no longer fetch messages for that narrow, thus the new
messages would not get fetched and are also discarded from
the events codepath.

Thus to resolve both these bugs we use the following approach:

* We do not add the new batch of messages for the current narrow
  while `has_found_newest` = False.
* We store the latest message id which should be displayed at the
  bottom of the narrow in `fetch_status`.
* Ideally `expected_max_message_id`'s value should be equal to the
  last item's id in `MessageListData`.
* So the messages received while `has_found_newest` = False,
  will be fetched later and also the `expected_max_message_id`
  value gets updated.
* And after fetching the last batch where `has_found_newest` = True,
  we would again fetch messages if the `expected_max_message_id` is
  greater than the last message's id found on fetching by refusing to
  update the server provided `has_found_newest` = True in `fetch_status`.

Another benefit of not discarding the events is that the
message gets processed not rendered i.e. we still get desktop
notifications and unread count updates.

Fixes #14017
2020-06-16 10:47:52 -07:00
sahil839 791e5de5de api: Remove is_old_stream property from the stream objects.
This commit removes is_old_stream property from the stream objects
returned by the API. This property was unnecessary and is essentially
equivalent to 'stream_weekly_traffic != null'.

We compute sub.is_old_stream in stream_data.update_calculated_fields
in frontend code and it is used to check whether we have a non-null
stream_weekly_traffic or not.

Fixes #15181.
2020-06-16 10:26:33 -07:00
Ryan Rehman c7e39ef090 narrow: Move the top of narrow notices to `message_scroll.js`.
We refactor these 2 notices to match with the loading indicators,
thus they have been moved to `message_scroll.js`.

After a successful message fetch, we have logic to decide whether
we want to display the notices and also whether we want to hide
the loading indicators (which are already displayed).

We also conservatively hide the notices similar to the indicators
every time we narrow.
The only exception is that we show the history limit notice on
deactivating the narrow (visiting `home_msg_list`).
2020-06-16 00:21:21 -07:00
Ryan Rehman a630f291b9 message view: Refactor top loading indicators.
This commit makes the `loading_older_messages_indicator` similar
to the `loading_newer_messages_indicator`.
Now all the decisions about whether to show a loading indicator
will be made from the `fetch_status` API. We still hide the
indicators everytime the view is changed, as explained in the
previous commit.
2020-06-15 22:26:35 -07:00
Ryan Rehman e0b1fdb81c message view: Show home view bottom loading indicators.
As explained in 67053ff479,
multiple message fetches may be taking place at the same time.
So some other narrows / the home message list's indicator might
get shown for the current narrow.

This commit moves the updation of the indicators display logic
to the `fetch_status` API.
Now the `loading_newer_messages_indicator` gets displayed along
with the `loading_newer` = true updation for that narrow's message
list, i.e. just before we send the API request. But only if the
message list we are fetching matches with our current message list.

The same indicator is hidden similarly, along with the
`loading_older` = false updation for that narrow's message list,
i.e. just after the success response is recieved. But only if
the message list whose data we recieved  matches with our current
message list.

Also the indicators are hidden everytime we activate narrow
or deactivate narrow (`home_msg_list`). And on entering
`narrow.activate` we fetch for it's messages so they get
displayed again, if need be.
This is the reason `message_scroll.hide_indicators();` was
moved to a location above `fetch_messages`.

Fixes #15374.
2020-06-15 22:25:41 -07:00
Ryan Rehman 9c5d9c961c search: Parse search string correctly.
This is the exact same bug as observed in
02ab48a61e.

The bug is in the way we invoke `Filter.parse`.
`Filter.parse` returns a list of operators which
can contain only one 'search' term at max.
All strings with the 'search' operator present
in the query are combined to form this 'search'
term.

However on concatenating two filters we may get
two terms containing the 'search' operator. This
will lead to the search suggestions getting
generated based on only the last 'search' operator
term instead of all the terms having the 'search'
operator.

This is evident from the test change as suggestions
should be based on "s stream:of" but instead they
were based on just the latest query.
2020-06-15 20:16:40 -07:00
YashRE42 46247623fc navbar: Fix navbar for unknown streams.
In commit 35c8dcb599 we introduced the
`_stream_params` object within filter.js but we didn't correctly
handle cases where `_stream param`s is undefined within `get_title()`,
`generate_url()` and `get_icon()`, which cause the navbar to if eg a
guest user tries to access a stream they weren't subscribed to.

This commit fixes this by:
  * Adding the relevant checks
  * Adding node tests that include non-existent streams.
  * Adds the 'question-circle-o' icon for non-existent stream narrows.

A side note here is that "non-existent streams" fall under
"common narrows" as per our current definitions, which doesn't really
make sense but shouldn't bother us.

Fixes: #15387.
2020-06-15 16:48:24 -07:00
Tim Abbott 3087fbe854 stream_topic_history: Pluralize remove_message.
Since this function now does a bulk operation with several messages,
we should make sure it's named appropriately.
2020-06-15 10:52:04 -07:00
Aman Agrawal 0cffaa7b5d ui: Upgrade remove_message to allow removing messages in bulk.
We simply pass the visible message ids to remove_and_rerender
which supports bulk delete operation.

This helps us avoid deleting messages in a loop which freezes the
UI for the duration of the loop.
2020-06-15 10:41:12 -07:00
Aman Agrawal ccc0c8706c delete_message: Support `bulk_message_deletion`.
Fixes #15285
This event will be used more now for guest users when moving
topic between streams (See #15277). So, instead of deleting
messages in the topic as part of different events which is
very slow and a bad UX, we now handle the messages to delete in
bulk which is a much better UX.
2020-06-15 10:41:12 -07:00
sahil839 c7a68d60f3 realm owner: Add frontend implementation of owner role.
This commit adds the option of owner role in user role dropdown
and also takes care of the restrictions while adding/removing
owner status of the user.
This commit also handles the places where we dispaly role of
the user in UI.
2020-06-14 21:20:30 -07:00
Dinesh 1201ecf332 puppeteer: Add 02-message-basic tests.
We plan to combine 02-site.js, 03-narrow.js of casper test into one
03-messages-basics.js tests in puppeteer.
2020-06-14 13:19:35 -07:00
Priyank Patel 0c239c9ede puppeteer: Add get_renderered_messages and check_messages_sent.
The get_rendered_messages now returns a Map, that is formatted as:
{
  'Verona > topic 1': ['message 1', 'message 2'],
  'You and Cordelia Lear': ['private message 1']
}

We also add check_messages_sent (which was expected_messages in
casper). It now takes in a object, formatted similar to
get_rendered_messages above, instead of an array with topic and
messages.
2020-06-14 13:19:35 -07:00
Dinesh 535fce8c45 puppeteer: Add common methods needed for 02-messages-basics.js.
We include all method needed from casper except
get_rendered_messages, and expected_messages. We will want to tweak
their API when we migrate them.

We also rename bunch of method here while migrating them.
2020-06-14 13:19:35 -07:00
Ryan Rehman 542a3dea77 minor: Refactor the top of narrow notices.
The changes made here are as follows:
* We rename `show_history_limit_message` and `hide_history_limit_message`
  to `show_history_limit_notice` and `hide_history_limit_notice`
  respectively.
* We rename `hide_or_show_history_limit_message` to
  `update_top_of_narrow_notices` as now this function is responsible
  for updating the history limit notice as well the end of results
  notice.
* We extract 2 functions responsible for hiding and showing the end
  of results notice, similar to that of the history limit notice.
  All instances of `$(".all-messages-search-caution").hide();` are
  replaced with the call of `hide_end_of_results_notice` function.
2020-06-14 11:06:54 -07:00
Ryan Rehman e0b1096253 narrow: Show streams:all notice only after "oldest" is found.
The streams:all advertisement notice in search should only appear
after all results have been fetched to indicate we've gotten to the
beginning of the target feed.

The notice gets hidden at the start of `narrow.activate` and is
shown just after we've fetched an older batch of messages if the
"oldest" message has been found.
Previously it would get displayed after the first fetch which
takes place from `narrow.activate`. Thus we move this logic to
`notifications.hide_or_show_history_limit_message` which gets
called after a successful message fetch.

Since the home message view contains all the messages we are not
required to display this notice. However if it is already shown
we hide it as a part of `handle_post_narrow_deactivate_processes`.

To accomplish this we need to add `has_found_oldest` key to the
`fetch_status` API.
We also removed the `pre_scroll_cont` parameter as this was it's
only use case and is now redundant.
2020-06-14 11:06:54 -07:00
Tim Abbott ff7f69e9d2 emoji_picker: Add test that all emoji are in categories.
This should prevent the category of bug seen in the last commit.
2020-06-14 10:41:07 -07:00
Gittenburg 12671fbc66 emoji_picker: Add missing Flags category.
Apparently iamcal/emoji-data has a dedicated category for flag emojis.

And get_all_emoji_categories() in emoji_picker.js doesn't return the
Flags category, because we haven't declared that category in our emoji
data logic.

Note that the category looks quite sparse because it lacks country
flags, since we don't yet support emojis combined with a ‍Zero Width
Joiner (ZWJ) (see #992 & #11767).

Fixes #15303.
2020-06-14 10:41:00 -07:00
Aman Agrawal 9b862cd73f recent_topics: Select the filter text on lauch.
This will allow users to easily search for new topics
without losing the last filtered text.
2020-06-13 16:29:19 -07:00
Aman Agrawal 79d829bda1 Revert "recent_topics: Set 'unread' and 'participated' as default filters."
This reverts commit 0aeadd2c86.
2020-06-13 16:29:19 -07:00
Aman Agrawal 2d6ada4360 recent_topics: Use get_topic_key everywhere.
This deduplication helps with readability.

Pass get_topic_key in recent_topic_row instead of
computing it in DOM.

Fix broken test_update_unread_count
after this change. This was a regression
which went unnoticed.
2020-06-13 16:29:19 -07:00
Aman Agrawal d7d5bc208c recent_topics: Rename count_senders for clarity. 2020-06-13 16:29:19 -07:00
Aman Agrawal 0eda671299 recent_topics: Remove depricated arg in process_message.
This arg was used to determine rerender mechanism after the
message is processed.
2020-06-13 16:29:19 -07:00
Steve Howell 686ae3eef4 node tests: Use less mocking for stream events.
We now use the real implementation of
`stream_data` in our tests (as well as `people`),
while still just checking stubs for "heavier"
functions that we dispatch to.

Also, we use our regular blueslip helpers.
2020-06-13 15:35:39 -07:00
Steve Howell 78836378e5 node tests: Extract dispatch_subs.js.
This is mostly a code move.  There is a bit of
boilerplate at the top, and I just use
`assert.deepEqual` instead of `assert_same`.

I also use a little wrapper to provide
output like this:

    Starting node tests...
    running tests for dispatch_subs
            test: add
            test: peer add/remove
            test: remove
            test: update
            test: add error handling
            test: peer event error handling

One little piece of code that was obsolete
simply got deleted, not moved.

One of the goals here is to un-stub the
stream_data layer.
2020-06-13 15:35:39 -07:00
Steve Howell 22bf4696f5 refactor: Avoid triggers in stream_edit.
We extract stream_edit.rerender to make
the live-update code easier to follow.

The function should eventually be inlined,
but I want to clean up some other stuff first.
2020-06-13 15:35:39 -07:00
Steve Howell 186973cde2 refactor: Extract add_peer and remove_peer helpers.
These are basically shims for some deeper refactorings.

I basically just try to make the code express the
problems more clearly:

    - use stream_name instead of sub
    - make early-exit more explicit
    - make it clear that add_subscriber needlessly
      requires a name
    - make it clear we have an unnecessary loop

I also fixed some phony data in the test.
2020-06-13 15:35:39 -07:00
Steve Howell b965766f87 refactor: Call compose_fade without triggers.
We are trying to phase out the trigger-event way
of telling modules to do something.

In this case we not only remove the indirection
of the event handler, but we also get to remove
`compose_fade` from the `ui_init` startup sequence.

This also has us update `compose_fade` outside
the loop, although that's only a theoretical
improvement, since I don't think `peer_add` events
every actually include multiple streams.

To make the dispatch tests a little flatter, I
added a one-line change to zjsunit to add
`make_stub` to `global`.

To manually test:
    * have Aaron reply to Denmark (keep compose box open)
    * have Iago add Hamlet to Denmark
    * have Hamlet unsubscribe
2020-06-13 15:35:39 -07:00
Dinesh a92b31db05 node_tests: Fix incorrect stub of discard button.
The discard button stub in createSaveButtons is set same
as that of save button. This isn't desired because it hides
the save button on running `change_save_button_sate` instead
of hiding discard button. It was previously working as we weren't
testing visibility of save button anywhere.
2020-06-12 19:20:46 -04:00
Steve Howell cc7e11f868 node tests: Extract lib/events.js.
The immediate goal here is to make it a little
easier to share code among the node tests.
2020-06-12 14:00:53 -07:00
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00
YashRE42 6506447bf1 navbar: Only set searchbox text when displaying the searchbox.
Previously, the navbar failed at managing the searchbox text state in
cases where, eg, the user performs navigation by browser history.

This commit resolves the issue by ensuring that the searchbox text is
only (and always) set when the searchbox is made visible, and as such
there is no "state" to manage and we will always display the correct
text.

It also adds a test in `search_legacy.js` to make sure that the search
text is placed as intended.

Fixes: #14771.
2020-06-11 15:49:12 -07:00
jagansivam28 b40597cf3e settings_org: Combine upload_realm_logo and upload_realm_icon function.
This combines `upload_realm_logo` and `upload_realm_icon` into single
function called `upload_realm_logo_or_icon`.  The functions wer near
duplicates.

Additional refactoring should be able to deduplicate the logic further.

Part of #14730.
2020-06-10 17:05:29 -07:00
Anders Kaseorg 67e7a3631d python: Convert percent formatting to Python 3.6 f-strings.
Generated by pyupgrade --py36-plus.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-10 15:02:09 -07:00
YashRE42 96e272081d navbar: Add globe icon to navbar for web public streams.
Prior to this commit, the navbar didn't display web public streams as
any different from ordinary streams.

Now, we show a globe icon for web public streams. This commit also
adds a node test for the same.

We also modified the navbar behaviour table, which is the following
dropbox paper:
https://paper.dropbox.com/doc/Navbar-behavior-table--A0sp57z~7R5PeHuxHL__Gn5ZAg-cNOGtu7kSdtnKBizKXJge
2020-06-10 14:25:18 -07:00
Aman Agrawal 9b9154be91 recent_topics: Set focus on input element on launch. 2020-06-09 22:08:31 -07:00
Aman Agrawal ad2e7026c8 recent_topics: Add functionality to sort rows via header.
Add custom sorting for stream and topic headers.
2020-06-09 22:08:31 -07:00
Aman Agrawal 084cbd4ff7 recent_topics: Use list_render to display topic rows.
This fixes the laggy behaviour when there are 2k+ rows to processes,
since list_render uses lazy render based on what rows are visible
to the user.
2020-06-09 22:08:31 -07:00
Aman Agrawal 0aeadd2c86 recent_topics: Set 'unread' and 'participated' as default filters.
Decided after a poll on czo.
2020-06-09 22:08:31 -07:00
Aman Agrawal 33ace41ffe recent_topics: Add filter button to show muted topics.
We don't show muted streams/topics by defualt. Only when user
turns on muted filter.
2020-06-09 22:08:31 -07:00
Aman Agrawal 9f50825610 recent_topics: Only rerender when recent_topics is visible.
We update the data in the background but only update the view
when recent topics is visible to user.
Also, we always do a complete rerender on launch.
2020-06-09 22:08:31 -07:00
Aman Agrawal e8cc9da4c7 recent_topics: Don't complete_rerender on filter change.
We store the relevant data to hide/show a topic in the row itself,
and use jquery to hide/show it on filter change.

This also fixes search breaking the set filters.
2020-06-09 22:08:31 -07:00
Aman Agrawal e6611089fd recent_topics: Update stored message id of locally echoed messages.
This fixes the bug that message was undefined since we used to store
locally echoed message id and were not updating it after new message
id for the same message was received from the server.
2020-06-09 22:08:31 -07:00
Aman Agrawal d8a312eddb recent_topics: Append proper prefix before stream name.
We reuse the existing logic for displaying and updating stream color
from the stream left sidebar.

Tests fixtures were extracted and updated for this commit.
2020-06-09 22:08:31 -07:00
Aman Agrawal 515334dfb2 recent_topics: Extract test fixture into a function. 2020-06-09 22:08:31 -07:00
Aman Agrawal ee7faf13cc recent_topics: Show checkbox icons for active filters. 2020-06-09 22:08:31 -07:00
Aman Agrawal 4f1b7542ed recent_topics: Toggle topic display according to filters. 2020-06-09 22:08:31 -07:00
Aman Agrawal bc7136590a recent_topics: Add avatars of recent senders to topic. 2020-06-09 22:08:31 -07:00
Aman Agrawal 52529107d2 recent_topics: Clean unused starred data.
The approach that supposed to use this data was not implemented
and hence this data will no longer be used.

If this feature is implemented in future,
this data will still not be used since we would depend upon
starred_messages.js library to provide us the required information.
2020-06-09 22:08:31 -07:00
Aman Agrawal 464b541363 recent_topics: Display recent topics in a table.
* Add action to mute topics.
* We don't need to store muted data per topic as previously planned.
* Moved launch topic test to the top so that they run on non-modified
  data.
2020-06-09 22:08:31 -07:00
Aman Agrawal 9328dc8437 templates: Show Overlay of Recent Topics.
* Show an empty overlay of recent topics.
* Register click event to open recent topics.
* Launch recent topics on "t" keypress.

This is based on the draft overlay.
2020-06-09 22:08:31 -07:00
Tim Abbott e242ddc848 page_params: Add community_topic_editing_limit_seconds.
This was previously hardcoded with agreement between the Zulip backend
and frontend as 86400 seconds (1 day).  Now, it's still hardcoded in
the backend, but arranged in a way where we could add a setting
without any changes to the mobile and terminal apps to update logic.

Fixes #15278.
2020-06-09 14:40:12 -07:00
jagansivam28 adb1f56760 settings: Change user avatar spinner implementation.
Change user avatar spinner implementation to match
realm icon spinner implementation and have common css class
since similar implementation between similar widgets may help
in future deduplication.
2020-06-08 22:48:04 -07:00
Tim Abbott fa25738159 message_fetch: Select the anchor message in home view.
In the past, the anchor message has always been the same as the
pointer, but we're about to change that as part of removing the
pointer entirely.

Using the anchor is logically what we meant, anyway, since we always
want to select a message that's actually within the range we just
fetched.
2020-06-08 22:36:35 -07:00
Tim Abbott 2beaf2cab2 pointer: Remove have_initial_messages code.
This was implemented in 2012 to avoid showing a loading indicator for
fetching messages for users with no message history.  However, the
Zulip onboarding UI always creates some message history, and fetching
history is fast, so this is likely clutter more than a useful
optimization.
2020-06-08 22:36:18 -07:00
Anders Kaseorg 8dd83228e7 python: Convert "".format to Python 3.6 f-strings.
Generated by pyupgrade --py36-plus --keep-percent-format, but with the
NamedTuple changes reverted (see commit
ba7906a3c6, #15132).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-08 15:31:20 -07:00
Priyank Patel f5fbc64aef node_tests: Remove stray assert.
The activity.process_loaded_messages code path was called when these
tests were originally written in f8e0137. We stopped calling that
code path in 43e5b2d (#15118). This assert test code is no longer
relevant; tested by adding console.log in the function. I came
across this when working on removing activity from the window.
2020-06-07 13:01:35 -07:00
Dinesh fcebf2905e puppeteer_tests: WaitForNavigation until DOMContentLoaded for log_in().
Waiting till DOMContentLoaded event is triggered helps avoid flakes since
puppeteer is very fast and starts doing another task before
everything on the page is loaded. Adding this to log_in function
as almost all tests depend on this which leads to flaky tests if
the other parts of tests just start without even the page being
loaded.
One example this commit helps is for the test `02-site.js`
which is dependent on a function that runs some jquery on the site.
But because of the page not being loaded, we miss jquery and thus
the test fails. `02-site.js` and related code is added in the next
commit.

Co-authored-by: Priyank Patel <priyankp390@gmail.com>
2020-06-07 12:29:59 -07:00
Dinesh 264513a0be puppeteer_tests: Use default user test credentials for log_in().
When no credentials are sent to `log_in` function we want to
use the default generated test credentials. This saves us the
work of importing test_credentials everytime we run this function
in a different test which doesn't focus on what credentials are sent
to login.
2020-06-07 12:29:59 -07:00
Ryan Rehman b0d632577f search pills: Update multiple pills creation event behaviour.
If typeahead is used, this adds comma separated search queries
so that multiple search pills don't get combined as one and the
search behaviour remains same as search_pills_enabled = False case.

If typeahead is not used, this prevent the typing of a single comma
after the pill gets created.
2020-06-05 17:16:20 -07:00
Ryan Rehman 9faf238e8e search tests: Refactor search according to search_legacy.
Now node_tests/search.js and node_tests/search_legacy.js have
almost identical test besides the search pills related data
processing work.
This is possible since we no longer depend on the values stored
in the input pills and can narrow or search for term based on
the `#search_query` box value.
This was done in commit 02ab48a61e.
2020-06-05 17:16:20 -07:00
Ryan Rehman aeb4419d52 search: Open typeahead on initiating search.
This fixes a bug where the hotkeys used to search messages
doesn't work for pills enabled case.
2020-06-05 17:16:20 -07:00
sahil839 bd943941e4 people: Remove 'get_active_user_for_email' function.
This commit removes the 'get_active_user_for_email' function
from people.js. We have removed the use of this function
in the previous commits, which changed the functions using
'get_active_user_for_email' to use user_ids instead of emails.
2020-06-05 16:08:26 -07:00
sahil839 40475a41b0 compose_fade: Change would_receive_message to use user_id.
This commit changes the would_receive_message to use user_id
instead of emails.

This change is done because user_ids are immutable and using
user_ids is the correct way of uniquely identifying user.

The change in 'would_receive_message' also leads to change
in util.is_pm_recipient to use a string of user_ids instead
of emails.

We also know that user_ids passed to 'would_receive_message'
are active user_ids, since we get them from buddy_list.
So we don't need to check whether the user is active, which
was previously being checked by get_active_user_for_email.
2020-06-05 16:08:26 -07:00
sahil839 25aed90da1 compose: Change needs_subscribe_warning to use user_id.
This commit changes the needs_subscribe_warning function to
use user_id instead of emails.

This change is done because user_ids are immutable and using
user_ids is the correct way to uniquely identify a user.

We already know that user_ids being passed in this function are
active user_ids, since they come from typeaheads.
So, we only need to call 'people.get_by_user_id', to get the user
object from user_id and do not need to check the active status of
user, which was done previously using 'get_active_user_for_email'.
2020-06-05 16:08:26 -07:00
Anders Kaseorg f0a19ed8e6 puppeteer_tests: Use assert in strict mode.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-05 16:05:51 -07:00
sahil839 4b67259294 compose: Change compose_invite_users template to use data-user-id.
This commit changes the compose_invite_users template to use
data-user-id as property intead of data-useremail.

This is changed to maintain consistency with other parts of the
code where user_ids are used for referring to users.

This also helps in removing some of the checks for the case of
undefined emails.
2020-06-04 14:24:41 -07:00
sahil839 48ac1082c1 stream_edit: Use user_ids for subscribing/unsubscribing users to a stream.
We now send user_ids to the backend API for subscribing/unsubscribing
users to a stream instead of emails.

This change is done now because we have just migrated the backend API to
support sending user_ids in 2187c84, so it wasn't possible before.

This change is helpful because sending user_ids is more robust, as those
are an immutable reference to a user, rather than something that can
change with time.
2020-06-04 14:24:41 -07:00
Clara Dantas e1e755c887 people.js: Change functions to return a list of ids instead of objects.
The get_active_humans and get_non_active_humans functions used
to return a list of user objects. The get_active_humans is used
on settings_users.js and settings_bots.js, and in both places the
only attributes needed of the person object are the user_id and
full_name.

To make the function return smaller, instead of a list of active
humans, we are returning a list of active human ids, saving memory.
With the ids we can call the people API to get the full_name attribute.
2020-06-04 14:23:52 -04:00