Commit Graph

5204 Commits

Author SHA1 Message Date
Steve Howell bb8750c22b refactor: Export buddy_data.level().
This is mostly for testing purposes.  The code
structure here is pretty stable--we will probably
always use level() here to either sort or
group users, and being able to test it directly
is nice, rather than bringing in all the other
machinery.
2019-01-02 09:16:31 -08:00
Steve Howell 4fed3d2014 frontend: Add event handling for user status.
The UI part of this commit isn't really turned on
yet, but it works in theory.
2019-01-02 09:16:31 -08:00
Steve Howell d8d703af45 frontend: Add basic user_status module.
So far this processes page_params, but it's otherwise
an unused internal API.
2019-01-02 09:16:31 -08:00
Hemanth V. Alluri e3aed0f7bc custom profile fields: Markdown rendering for custom profile field values.
This makes it possible it include our standard markdown formatting in
one's custom profile fields, allowing for links, emphasis, emoji, etc.

Fixes #10131.
2019-01-01 21:06:21 -08:00
Hemanth V. Alluri 28d344b4b5 custom profile fields: Pass value as part of a dictionary.
While we're at it, we remove the JSON parsing that was part of the
user field code path, since this function isn't responsible for
rendering user fields.
2019-01-01 21:05:28 -08:00
Tim Abbott bdaeccbca1 custom profile fields: Remove unnecessary JSON parsing step.
Apparently, our custom profile fields feature was parsing the "user
list" field type in multiple places, and ignoring the results in one
of them.  That code had been causing some confusion; the correct
solution is to just delete it, since the template rendering process
ignores that value for this field type.
2019-01-01 21:04:23 -08:00
Steve Howell 0c668d13b6 subject -> topic: Make get_event_topic() more flexible. 2019-01-01 20:52:10 -08:00
Steve Howell 1ad30c6858 subject -> topic: Sweep "message.subject" in frontend.
These were the last remaining files.  After this, only
util.js has a non-email-related use of "subject".
2019-01-01 20:49:38 -08:00
Steve Howell 7e17b8a392 subject -> topic: Use util.set_message_topic() to set subject. 2019-01-01 20:49:34 -08:00
Cynthia Lin 55c1a2e525 settings: Add guest avatar marker to account settings. 2018-12-30 11:07:00 -08:00
Cynthia Lin 053c4a2250 popovers: Add guest avatar marker to user profile popover. 2018-12-30 11:07:00 -08:00
Cynthia Lin 4d97909764 popovers: Add guest avatar marker to user info popover. 2018-12-30 11:07:00 -08:00
Vishnu Ks 806fa1a834 billing: Make card change use create_ajax_request. 2018-12-30 08:00:23 +05:30
Vishnu Ks 41fbc699ad billing: Make invoice upgrade use create_ajax_request. 2018-12-30 08:00:23 +05:30
Vishnu Ks 938438364f billing: Use form.serializeArray in create_ajax_request. 2018-12-30 08:00:23 +05:30
Vishnu Ks b655cfe379 billing: Extract autopay ajax request code as function. 2018-12-30 08:00:23 +05:30
Vishnu Ks 93b1795ed1 billing: Don't pass csrf token in Ajax requests.
The Ajax request will automatically fetch the value
from input[name='csrfmiddlewaretoken'] and set the
headers. This is done in csrf.js.
2018-12-30 08:00:23 +05:30
Tim Abbott 25793aefa7 hotkey: Fix using pageup/pagedown inside message edit.
Our logic for doing pageup/pagedown calculation inside compose was
written too tightly, and ended up breaking the keys inside message
editing.

Fix this by using generic selectors that don't hardcode compose.
2018-12-29 15:59:28 -08:00
Vaibhav 93914d8cd8 markdown: Parse '/me' for multi-line messages.
Previously, messages with more than one line did not parse '/me' at
the beginning of the message.  Since there's a reasonable way to
render multi-line messages, this commit adds support for doing so.

This change does potentially break with the expected behavior of other
slash commands, but it seems worth providing useful functionality over
a blind focus on consistency.

Fixes #11025.
2018-12-29 15:32:50 -08:00
Vishnu Ks 96bb27fa84 signup: Fix bug in import settings when subdomain is root.
If branch for showing the profile details would
not have executed if the subdomain was root ("").
The check was changed to check for select input
instead of checking for subdomain.
2018-12-29 15:01:09 -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 053a41d816 subject -> topic: Fix notifications.js. 2018-12-29 14:34:06 -08:00
Steve Howell 56a893cd94 subject -> topic: Fix hash_util.js.
This includes using a more modern URL for topic links.
(We already supported "../topic/..." urls.)
2018-12-29 14:34:06 -08:00
Steve Howell 95e213df87 subject -> topic: Fix message_list_view.js. 2018-12-29 14:34:06 -08:00
Steve Howell 4fec91d5b1 subject -> topic: Fix message_events.js. 2018-12-29 14:34:06 -08:00
Steve Howell 3fc8597119 popovers: Avoid passing message to actions popover template.
We instead get the specific fields from message
that we use.  This is particularly helpful
for subject -> topic migration; we no longer
have to account for "subject" fields in
client-side templates.
2018-12-29 14:19:18 -08:00
Steve Howell 1903cc8ac7 refactor: Use message/topic in muting_ui.toggle_mute(). 2018-12-29 14:15:43 -08:00
Steve Howell 411743e6dd narrow: Use get_message_topic() helper. 2018-12-29 14:15:43 -08:00
Steve Howell dc5321fed3 message_edit: Add util.get_edit_event_topic(). 2018-12-29 14:14:43 -08:00
Steve Howell 9b4f804fd1 message_edit: Add util.get_edit_event_orig_topic().
This extracts this bit of parsing logic for message_edit events.
2018-12-29 14:14:40 -08:00
Steve Howell bcc92744c2 compose fade: Use "topic" internally. 2018-12-29 11:40:59 -08:00
Steve Howell 773e85309c topics: Make util more flexible about subject/topic. 2018-12-29 11:40:57 -08:00
Steve Howell 4e0969bb49 Rename util.set_topic -> set_message_topic(). 2018-12-29 11:38:39 -08:00
Steve Howell 4b2181ffa2 Rename util.get_topic -> get_message_topic().
The specific name will help us when we fully cut
over to "topic" on message objects.
2018-12-29 11:38:39 -08:00
Steve Howell 2fdb44803d filter: Eliminate a few "subject" references.
This continues the effort to isolate "subject" references
to util calls.

Also, we fix a comment.

Finally, we use canonicalized operators in a switch
statement.
2018-12-29 11:38:39 -08:00
Steve Howell 8121d19122 minor: Change "subject" to "topic" in comments. 2018-12-29 11:38:39 -08:00
Steve Howell 76a73e00f4 unread: Use topic_name as var. 2018-12-29 11:38:39 -08:00
Hemanth V. Alluri b928bb3b26 static: Replace an if-else block in popovers.js with a switch statement. 2018-12-29 11:24:10 -08:00
Steve Howell 015af605cf Use stream_id in web app for muting endpoints.
This is set up by the previous commit, which allows
stream_id as alternative for stream on the server side.
2018-12-27 20:26:30 -08:00
Rishi Gupta b4a28f3147 billing: Rename seat_count to licenses where appropriate. 2018-12-22 13:30:15 -08:00
Rishi Gupta 7ab1406962 billing: Prepare for moving Plan to CustomerPlan.billing_schedule. 2018-12-22 13:30:15 -08:00
Vishnu Ks 8176d112fe billing: Add frontend for license-based billing system. 2018-12-22 13:30:15 -08:00
Vishnu Ks d086efd33f billing: Deduplicate get_form_input in billing.js. 2018-12-22 13:30:15 -08:00
Steve Howell 72576b3a77 compose: Fix recent autocomplete regression.
As part of giving the stream/topic fields in the
compose box longer ids, I broke the autocomplete
code that handles re-focusing the cursor after
a user hits enter.  The worst symptom of this was
that we tried to send a message before compose
finished (although it wouldn't fully deliver the
message).

The new code should be a bit easier to grep for
if we rename these fields again, as we explicitly
use selector syntax.
2018-12-22 08:07:23 -08:00
Steve Howell ca22302763 minor: Avoid ui_util.focus_on() call.
The helper is unnecessary at this point and obscures
greps for selectors.  We completely eliminate it in
the next commit.
2018-12-22 08:07:23 -08:00
Vishnu Ks 30a61d7505 billing: Fix plan input bug in upgrade. 2018-12-21 09:34:27 -08:00
Steve Howell 1656fd7729 Fix recent regression with mute undo.
The undo button was bound to the stream id
and topic for only the first call, when
the click handler was set.
2018-12-20 15:58:05 -08:00
Tim Abbott ba77303ee4 message_list: Slightly optimize content editing logic.
Previously, we were searching the whole message_row object for emoji,
mentions, etc., which has a bunch of UI elements that can't contain
the syntax we want to modify.  This should be a slight improvement in
the performance of message post-processing, which runs a lot of times
and thus is fairly important.
2018-12-18 14:50:05 -08:00
varunvaruns9 c2ced75d5a message_list_view: Rerender names of user groups and streams on change.
Rerender the mentions for user groups and streams when
they are not in search.

Fixes part of #11026.
2018-12-18 14:44:11 -08:00
varunvaruns9 424127012f message_list_view: Add highlight for user group mentions.
Add green highlight to mentions of user groups the current user
is a member of.

Fixes part of #11026.
2018-12-18 14:43:32 -08:00
varunvaruns9 eca1ce7f1f message_list_view: Remove check for mention class.
This check caused us to only run the code inside that block if the
message mentioned the current user (since that's when the `mention`
class is added to the main message row).

While this was a useful performance optimization, it probably was a
small one, not worth it for the correctness cost.
2018-12-18 14:41:46 -08:00
varunvaruns9 8426785286 message_list_view: Fix mention text in search condition.
Use length property of find function to check if highlight
class was present because find return an object even if
highlight class was not present.
2018-12-18 12:55:03 -08:00
Joshua Pan ad1df0ebeb settings: Add support for customizing the top-left logo.
This adds a new realm_logo field, which is a horizontal-format logo to
be displayed in the top-left corner of the webapp, and any other
places where we might want a wide-format branding of the organization.

Tweaked significantly by tabbott to rebase, fix styling, etc.

Fixing the styling of this feature's loading indicator caused me to
notice the loading indicator for the realm_icon feature was also ugly,
so I fixed that too.

Fixes #7995.
2018-12-18 12:44:52 -08:00
Tim Abbott 34f5218a0d ui_report: Add support for passing "".
I'm not really a fan of the "Failed:" pattern in some places, and this
lets us avoid it.
2018-12-18 12:33:42 -08:00
Vaibhav 7371fd2647 notifications: Refactor code using logic from message_viewport.
Logic for checking if the last message in the current table is visible was
already written in message_viewport.js; Code in notifications.js is changed
to reduce redundancy.
2018-12-18 11:53:08 -08:00
Steve Howell f4f59a7557 presence: Rename presence.set_user_status() -> set_info_for_user(). 2018-12-18 11:01:10 -08:00
Steve Howell ba69dcc74c presence: Rename activity.set_user_status().
We are trying to carve room for a more specific
"user_status" concept, which refers to statuses
that users specifically set, like "I'm away".

So we call this function "update_presence_info",
which reflects that it's more about actual
"presence"--i.e. the user really is present
in the browser, even though the actual human
may not want to be disturbed.
2018-12-18 11:01:06 -08:00
Steve Howell 2c719bdb3f buddy list: Exclude current user from searches.
The current user gets excluded from all non-empty
searches, even ones that match the user, since
it can look funny when the user's at the top of a
search, and you'd never need to search for yourself
(again, since the current user is at the top of
the buddy list).
2018-12-18 11:01:06 -08:00
Steve Howell bf152b94b5 presence: Put current user back at the top of the buddy list.
We tried this out, reverted it, and then put it back.
2018-12-18 11:01:01 -08:00
Tim Abbott bdb3da4504 eslint: Add key-spacing linter rule.
Apparently, we didn't have one of these, and thus had a moderate
number of generally very old violations in the codebase.  Fix this and
clear the ones that exist..
2018-12-18 10:41:06 -08:00
Tim Abbott 12b3e79661 settings: Rename "settings_filters" to "settings_linkifiers".
This makes the JS codebase match the UI for how to describe this
feature.  No user-facing effect.
2018-12-17 12:28:55 -08:00
Steve Howell 7a44d99b96 settings: Eliminate admin_sections module.
We move all of its logic into settings_sections.

Note that this is slightly more than a refactor.
We are slightly more aggressive about resetting
sections.  For example, if you go into Settings,
then exit the overlay, then go into Manage
Organization, we will now reset sections for both
groups.
2018-12-17 10:13:20 -08:00
Steve Howell 0543e8fbc1 settings: Call maybe_disable_widgets() in set_up() methods.
We now rely on set_up() methods to call their
own module-specific versions of maybe_disable_widgets()
in the codepath for admin_sections.load_admin_section().

And then for live updates, we just explicitly call
all four modules that support maybe_disable_widgets().

This should make switching between sections slightly faster,
and it also reduces the risk of module A messing with
module B's state.  (Granted, we have lots of other ways
that modules can mess with each other's state.)
2018-12-17 10:13:18 -08:00
Steve Howell b88a5700f6 settings: Extract multiple versions of maybe_disable_widgets(). 2018-12-17 10:13:16 -08:00
Tim Abbott cb9b526f0c third: Extract bootstrap typeahead to its own module.
Bootstrap's typeahead is the main part of the project that we've
forked, and moving it to its own module should help unlock our ability
to upgrade bootstrap itself.
2018-12-17 09:06:52 -08:00
Steve Howell d8c454b097 todo lists: Make lists sharable.
We no longer restrict who can add tasks or check
them off.

Fixes #10440
2018-12-17 07:40:27 -08:00
Tim Abbott 7485cb2a50 widgets: Rename voting_widget to poll_widget.
This ensures greater consistency with our other widgets' naming
convention.
2018-12-16 19:46:48 -08:00
Tim Abbott 2cca6a1be8 csrf: Improve API for when no CSRF input is available.
Since we're adding this to a large number of portico pages, there's no
guarantee that these pages actually have a CSRF input.

Though given that the logout template contains a CSRF input,
realistically it should always be present.
2018-12-16 16:19:23 -08:00
Tim Abbott adebe1bd4e js: Extract csrf.js and include in common bundle.
This should make it possible to use this AJAX setup code in logged-out
code as well, which is necessary to use blueslip from portico pages.
2018-12-16 16:18:42 -08:00
Tim Abbott ed9430f3a6 Revert "js: Extract csrf.js and include in common bundle."
This reverts commit dbffa66b6d.

This broke the logged-in app, due to some webpack issue.
2018-12-16 16:16:06 -08:00
Tim Abbott 6416737e70 Revert "csrf: Improve API for when no CSRF input is available."
This reverts commit 9198fa4ec9.
2018-12-16 16:15:54 -08:00
Steve Howell 7d23076a0e drafts: Fix bug in finding current element.
We weren't using the actual sorted data to find
the last element.  This probably worked by accident
in some cases, but this commit makes it more
deterministic.
2018-12-16 15:46:41 -08:00
Steve Howell ebd6d84326 refactor: Call format_drafts() more directly.
We want the return value from this for the next
commit, so we no longer call `format_drafts` indirectly
from `populate_and_fill`, and we rename the latter
to `render_widgets`.
2018-12-16 15:46:41 -08:00
Steve Howell 1584789916 refactors: Move format_draft() to module level.
This is a pure code move.
2018-12-16 15:46:41 -08:00
Steve Howell e22a50a3e3 drafts: Use lists instead of dicts.
We were using a dict to return a sorted list of
formatted drafts, instead of building a list.
2018-12-16 15:46:41 -08:00
Steve Howell 29052b36a5 minor: Rename last_draft -> curr_draft. 2018-12-16 15:46:41 -08:00
Steve Howell c82233c435 drafts: Avoid callback mechanism.
We had an anonymous callback for drafts that was
hard to read.  It's much easier to flatten the code,
give functions actual names, and stub them as needed
in the unit tests.
2018-12-16 15:46:41 -08:00
Tim Abbott 9198fa4ec9 csrf: Improve API for when no CSRF input is available.
Since we're adding this to a large number of portico pages, there's no
guarantee that these pages actually have a CSRF input.

Though given that the logout template contains a CSRF input,
realistically it should always be present.
2018-12-16 15:35:54 -08:00
Tim Abbott dbffa66b6d js: Extract csrf.js and include in common bundle.
This should make it possible to use this AJAX setup code in logged-out
code as well, which is necessary to use blueslip from portico pages.
2018-12-16 15:35:54 -08:00
Steve Howell 840210a0ba minor: Move setup_event_handlers() in code.
We place this code under populate_and_fill().

And instead of calling this at the end of
populate_and_fill(), we call it AFTER
populate_and_fill().
2018-12-16 14:38:28 -08:00
Steve Howell e38496ddc0 drafts: Show active element clearly. 2018-12-16 14:38:28 -08:00
Tim Abbott 0779d343fa message_list: Fix handling of unknown email in mentions.
If a user has an old mention and has since been renamed, there's
really nothing for us to do to render it; we should just return as
though we have no data.
2018-12-16 14:36:26 -08:00
Tim Abbott 728c601ff4 poll widget: Only show "Add option" if a question has been set.
This makes the UI less confusing.
2018-12-16 11:59:21 -08:00
Steve Howell 35b904b184 subject -> topic: Fix subject in opts.
It's kinda difficult to track down all the interactions
with the opts that go through compose_actions.start(),
but I think I got everything.
2018-12-16 11:26:18 -08:00
Steve Howell 057ee6633a reload: Use "topic" to encode compose topic. 2018-12-16 11:26:18 -08:00
Steve Howell 9861cdfeb6 drafts: Use "topic" internally.
We still have to support "subject" for old drafts,
but we write "topic" for new drafts.
2018-12-16 11:26:18 -08:00
Steve Howell 9ba7b4fcbb drafts: Extract drafts.restore_message().
We make our deep-copy more explicit, change
the var name from draft_copy to compose_args,
and clean up some code formatting.
2018-12-16 11:26:16 -08:00
Steve Howell d7aa5fcc38 compose: Remove obsolete references to replying_to_message.
The `replying_to_message` field was used in some
early versions of compose fade, but it has no more
use in the current code.

The drafts implementation didn't really make any sense,
anyway, as we were claiming to reply to the same
message we were drafting.
2018-12-16 11:26:02 -08:00
Tim Abbott bdc4876948 notifications: Fix missing translation tags for above-compose alerts.
Apparently, these had never made it to being translated.  Since
they're an important part of the user experience, we add translation
tags for them now.
2018-12-16 11:14:09 -08:00
Tim Abbott 6c7725d21f notifications: Compute link earlier in mix notifications code.
This should make it more obvious how to later add a feature to include
a link for out-of-view-scroll-down notifications, should we ever want
that.
2018-12-16 11:02:52 -08:00
Vaibhav 372cb20f9e notifications: Notify when sent message is scrolled down in view.
A common source of confusion for new users is sending a message when
you're scrolled up in the message feed; in this case, it's nice to
communicate to the user why the message is not in view.

Fixes #10792.

Restructured by tabbott to replace overly complex logic for getting
the position of the new message with a `message_list.get_row()` call.
2018-12-16 10:59:25 -08:00
Tim Abbott 008722b809 portico: Fix logic for whether a password field is present.
Now, we correctly avoid calling various password quality/strength
functions in the registration flow in the event that there isn't a
password form on the current page.

Before, some code wasn't inside a block at all, while other code was
using an incorrect check (an empty jQuery object is not falsey).

The overall result was that this would often crash on certain
pages/flows, stopping JS execution and causing various secondary
problems.
2018-12-15 13:58:38 -08:00
Steve Howell a4c80089f3 page load: Fix two bugs related to muting/unreads.
The first bug fixed here has been around for a long
time--we were redundantly updating unread counts
indirectly via muting_ui.initialize(). The
unread counts also get updated in
unread_ui.initialize(), when we have more valid
state.  (And it's worth noting here that the unread
counts get updated yet again once message fetches
complete.)

The second bug was a very recent regression from
my recent stream name -> stream id cleanup in the
muting system.  We now depend on stream_data to
initialize muting data, so we need to initialize
muting.js slightly later in the process.

These fixes are intertwined, because they were both
somewhat caused by the anti-pattern of having
muting_ui.js initialize unread_ui.js and muting.js,
instead of doing more direct, fine-grained initialization
from ui_init.js.

Essentially we replace this code:

    exports.update_muted_topics = function (muted_topics) {
        muting.set_muted_topics(muted_topics);
        unread_ui.update_unread_counts();
    };

with this:

    exports.initialize = function () {
        exports.set_muted_topics(page_params.muted_topics);
    };

And the modules load like this:

    stream_data
    ...
    muting
    ...
    unread_ui

And we don't need any page-load initialization for muting_ui,
which is mostly used for Settings/Muted topics.
2018-12-15 13:44:30 -08:00
Steve Howell 625388ccf0 refactor: Call stream_data.initialize() more directly.
This function used to be called initialize_from_page_params(),
and we called it indirectly through `subs.js`.

Now we call it directly from `ui_init.js`, which gives us a
bit more control over how things are initialized.  In fact,
this sets us up for the next commit, where I fix a recent
regression I introduced.
2018-12-15 13:44:30 -08:00
Steve Howell c8cee5d900 topic list: Remove unnecessary markup.
The data attribute here has some value if you're
inspecting the HTML in the browser, but it's not
worth the extra code.

All the list items have data-stream-id, so there's
no need for the parent to have it.
2018-12-14 16:05:40 -08:00
Steve Howell 012bb7b6c7 Use stream_id for by_stream__uri().
The stream_list test that was fixed here was sort of
broken.  It accomplished the main goal of verifying
what gets rendered, but now the data setup part is
more like the actual app code (and simpler, too).
2018-12-14 16:05:40 -08:00
Steve Howell aea074e744 Use stream_id for by_stream_topic_uri(). 2018-12-14 16:05:40 -08:00
Steve Howell 7a22d47338 Use stream_id for mark-topic-read handler. 2018-12-14 16:05:40 -08:00
Steve Howell 87851b0db0 muting: Use stream_id in muting.get_muted_topics(). 2018-12-14 16:05:37 -08:00
Steve Howell f18ce4f923 muting: Use stream_id in markup for action menus. 2018-12-14 16:05:37 -08:00
Steve Howell d75ff80eb2 muting: Add stream_id to markup for mute settings.
We also prefer `attr` over `data` (it's more greppable).
2018-12-14 16:05:35 -08:00
Steve Howell bf6f5e7bc5 muting: Pass stream_id to muting_ui.mute and unmute.
We temporarily allow settings_muting to have
incomplete line coverage--we will fix this soon.
2018-12-14 16:02:48 -08:00
Steve Howell 10b045f91b muting: Use stream_id as arg for notify_with_undo_option.
Also remove the unused meta.stream and meta.topic variables.
2018-12-14 16:02:40 -08:00
Steve Howell ba04ec7e85 muting: Use stream_id for persist_mute/persist_unmute. 2018-12-14 16:02:37 -08:00
Steve Howell a8718c9051 muting: Use stream_id for internal data structures.
This fixes the most core data structures inside of
muting.js.  We still use stream names for incoming
data to set_muted_topics and outgoing data from
get_muted_topics.

This will make us more resilient to stream name changes.
Before, if you were logged on when a stream rename
occured, topics that were muted under that stream would
appear to be unmuted.  (You could fix it with a reload,
but it can be jarring to have a bunch of unread messages
appear in your feed suddenly.)

Fixes #11033
2018-12-14 15:58:35 -08:00
Vishnu Ks 0fd6ff722b billing: Migrate /upgrade endpoint to JSON.
The fixture changes are because self.upgrade formerly used to cause a page load
of /billing, which in turn calls Customer.retrieve.

If we ran the full test suite with GENERATE_STRIPE_FIXTURES=True, we would
likely see several more Customer.retrieve.N.json's being deleted. But
keeping them there for now to keep the diff small.
2018-12-13 17:01:12 -08:00
Vishnu Ks e5b3d39ce9 messages: Show banner when message history is limited.
This communicates to users clearly about the situation when the
history_limited flag is set by the backend (because message history
was cutoff).
2018-12-13 09:02:11 -08:00
Tim Abbott 1054d63820 message_fetch: Deduplicate logic for finish_newer_batch.
Like the other similar commits, we were doing the same work in all
code paths, just with a much more error-prone approach.

We can also now remove the now-unused finish_initial_narrow function.
2018-12-13 08:43:56 -08:00
Tim Abbott ce187b0899 message_fetch: Deduplicate logic for start_newer_batch.
Like the other commits in this series, we were already doing this in
all of the callers of load_messages; this centralizes that logic in a
less ad-hoc feeling way.

We no longer use or need the start_initial_narrow function.
2018-12-13 08:43:56 -08:00
Tim Abbott 7febf724f3 message_fetch: Deduplicate logic for start_older_batch.
We were doing this work individually in all the callers of
load_messages; better is to just do it in one place.
2018-12-13 08:43:56 -08:00
Tim Abbott 9ccb3a2ad1 message_fetch: Deduplicate logic for finish_older_batch.
Previously, each individual caller of load_messages that passed
num_before > 0 would do its own manual management of fetch_status;
now, we just do it inside load_messages.
2018-12-13 08:43:56 -08:00
Tim Abbott cd118bbc7e message_fetch: Track history_limited property. 2018-12-13 08:43:56 -08:00
Tim Abbott b8a45d889e message_fetch: Fix home_msg_list older FetchStatus tracking.
Apparently, the older side of the FetchStatus object for home_msg_list
was incorrectly not being maintained.  We got away with this, because
the do_backfill code path (which runs after we're done with the
load_more cycle) will correct the error for found_oldest.  But we
didn't have proper handling for history_limited here.
2018-12-13 08:43:56 -08:00
Tim Abbott ba6ef745fe message_fetch: Fix home_msg_list newer FetchStatus tracking.
When we're doing the load_more frontfill, we were not correctly
declaring that we were in the process of doing a fetch.  Because the
next load_more call clears this state anyway, this was generally a
short race, off-screen, but it is still a data flow bug.

See the upcoming commits for a refactor that will eliminate the
possibility of this sort of bug.
2018-12-13 08:43:56 -08:00
Tim Abbott 982a70431f message_list_view: Rerender mentions when user names change.
When a user's name is edited, currently we still show the old name is
mentions (though clicking on the item does the right thing).

However, at present, it creates a new problem in search results, where
the highlighting is removed by this substitution.
2018-12-12 13:38:12 -08:00
Steve Howell dfddb0a636 left sidebar: Remove unneeded overlay code.
These handlers are not reachable if overlays are
open.
2018-12-10 16:55:25 -08:00
Aditya Jain 8f0ccdf1c9 user settings: Fix active background links when a modal is visible.
A bug caused background links to open even when a modal in the user
settings overlay was active in the foreground. This commit fixes this
by disabling mouse events for the background when the modal is active,
and restoring them as soon as the modal starts closing.

Fixes #10654.
2018-12-09 22:32:53 -08:00
Amadeo234 38aa44ef31 message_edit: Fix tab navigation to "Close" button.
This adds a line to static/js/hotkey.js for focusing the "Close"
button.  Tweaked by tabbott to make more clear that we don't expect
there to ever be both a close button and a save button, since in that
case this code would be busted.

Fixes: #3830.
2018-12-09 21:50:39 -08:00
Steve Howell d7c2577ffb subject -> topic: Rename compose fields.
The stream/topic edit areas now have these ids:

        #stream_message_recipient_stream
        #stream_message_recipient_topic

They are pretty verbose, but being able to grep
for these without noise does have some value.
2018-12-09 21:28:45 -08:00
Marco Burstein ba46dc83c6 notifications: Add a setting for changing the notification sound.
Also, add a new notification sound, "ding". It comes from
https://freesound.org, where the original Zulip notification sound comes
from as well. In the future, new sounds can be added by adding audio
files to the `static/audio/notification_sounds` directory.

Tweaked significantly by tabbott:
* Avoided removing static/audio/zulip.ogg, because that file is
  checked for by old versions of the desktop app.
* Added a views check for the sound being valid + tests.
* Added additional tests.
* Restructured the test_events test to be cleaner.
* Removed check_bool_or_string.
* Increased max length of notification_sound.
* Provide available_notification_sounds in events data set if global
  notifications settings are requested.

Fixes #8051.
2018-12-09 21:25:30 -08:00
Tim Abbott 838dd6d273 lint: Add eslint enforcement for comma-spacing.
We've been enforcing this manually for a long time, and hadn't
realized it was missing from our eslint configuration.
2018-12-07 12:22:24 -08:00
Steve Howell 78e20c82a8 settings: Handle back button within settings/orgs panels.
The Casper code that I eliminated here seems to be
bogus, in that I don't think it really waited for
all the clicks.

I **think** the intent of the test was to verify that
when you leave settings and go back into it, it remembers
the panel.  I was able to verify this manually.
2018-12-07 11:45:25 -08:00
Steve Howell 3544688b35 settings: Call replaceState() when entering settings/orgs.
We have an upcoming change that lets us use the
back button after going arrowing through multiple
settings pages.

Without first adding this commit, we would have an
infinite loop when you came back to '#settings' and
then '#settings' would rewrite the url with the current
hash.

Just replacing the browser state allows the browser
to do the right thing.

The history protocol is pretty well supported:

    https://caniuse.com/#search=history
2018-12-07 11:45:23 -08:00
Steve Howell 2a1a55af8a settings: Streamline how we launch settings.
We can eliminate the janky `setup_page` methods
and just pass in section from `hashchanged`.

This sets us up to handle browser history more
nicely when you load '#settings' and we could essentially
redirect you to '#settings/your-account' (or similar
things).  A future commit will address that.

We also use `launch` as the new entry point, which
is more consistent with other modules.
2018-12-07 11:40:56 -08:00
Steve Howell 5a4a357afc cosmetic: Use early-return instead of else/if. 2018-12-07 11:40:56 -08:00
Steve Howell 3acc6fe080 settings: Extract admin.build_page(). 2018-12-07 11:40:54 -08:00
Steve Howell b9aecabdb7 settings: Extract settings.build_page(). 2018-12-07 11:40:50 -08:00
Steve Howell fcf31cedbc settings: Extract gear_menu.update_org_settings_menu_item().
The prior name of this was a bit inaccurate, as we no
longer ever hide the menu item for non-admins.  Also,
it belongs more naturally in `gear_menu.js` at this point.

Also, we remove one call to this, which was in a place
where it was no longer necessary.
2018-12-07 11:40:40 -08:00
Steve Howell 1d07d0a532 settings: Extract admin_sections.maybe_disable_widgets().
We now run the code to disable widgets every time
we reload a section, which was the original intention
of the code, but the call to it only happened when
you first launched the page.

We also continue to run this logic for live updates
of is_admin, although it's worth noting that the
code still only handles the "demotion" case of going
from admin to non-admin. (If somebody makes you an
admin, you continue to need to reload to get
widgets enabled.)
2018-12-07 11:40:37 -08:00
Steve Howell b5645848d6 minor: Move line of code to set default language.
There was no reason for this code to be separated
from similar lines of code.
2018-12-07 08:04:09 -08:00
Steve Howell ead356971c hashchange: Pass in a "section" to subs.change_state.
We also eliminate get_hash_components() and clean up the
code a bit in change_state().
2018-12-07 08:03:55 -08:00
Steve Howell a2fd901bec hashchange: Add hash_util.get_hash_section().
We'll use this mostly for streams/settings URLs at first.
2018-12-07 08:03:41 -08:00
Steve Howell 7cbf031f18 hashchange: Add warning if pushState is not available. 2018-12-07 08:03:39 -08:00
Steve Howell 0914037bed hashchange: Extract get_full_url(). 2018-12-07 08:03:29 -08:00
Steve Howell a39c7096c0 hashchange: Use overlays.close_active() in a few places.
The `change_tab_to` calls are a relic of very
early versions of Zulip.
2018-12-07 08:03:20 -08:00
Steve Howell 6d22634e56 streams: Remove subs.show_and_focus_on_narrow().
We stopped calling this in this commit:

    3d77aa49db

We also remove its helper function and the obsolete
event that only it was looking for.
2018-12-07 08:03:14 -08:00
Steve Howell 75bdd2c62c hashchange: Remove unreachable code for drafts.
I missed this in an earlier commit where I swept
the overlays for unreachable code.
2018-12-07 07:39:51 -08:00
Joshua Pan bc74abae41 user_events: Create delivery_email update event procedure.
This ensures the "account settings" UI for managing a user's own email
address uses the delivery email, since that's what users care most about.

Eventually, we'll need to add support for at least viewing both email
addresses in "account settings", but this is the right long-term
behavior.
2018-12-06 20:09:57 -08:00
Joshua Pan 67f0b1bbca admin: Add UI for editing realm_email_address_visibility.
This new setting is still hidden in the UI when not in the development
environment, because the feature isn't ready for production, but
merging this will help simplify future work on the feature.
2018-12-06 16:01:09 -08:00
onkar shedge ba7e78bc65 message_edit: Allow editing topics indefinitely.
Previously, Topic editing was offered in the UI even to message
senders and organizations admins only if the message was no more than
one day old.  This was correct for the "community topic editing" case,
but not for message senders and organization admins.

While we're at it, this also centralizes some previously haphazard
logic to always call message_edit.is_topic_editable().

Tweaked significantly by tabbott to fix the logic.

Closes #10568.
2018-12-04 17:41:21 -08:00
Steve Howell 44ef8baff1 hashchange: Add hash_util.get_hash_category().
This replaces hashchange.get_main_hash(), which had
a slightly misleading name.  Also, moving this to
hash_util forces us to keep 100% coverage on it.
2018-12-04 17:16:40 -08:00
Steve Howell 67fba69b0c hashchange: Go to home page for bogus narrows.
This was the original intent of the code, and I think
it's the right behavior.
2018-12-04 17:16:38 -08:00
Steve Howell bcb142e68e hashchange: Move parse_narrow to hash_util.js.
The goal here was to enforce 100% coverage on
parse_narrow, but the code has an unreachable line
and is overly tolerant of bogus urls.  This will
be fixed in the next commit.
2018-12-04 17:16:32 -08:00
Steve Howell dac543891f hashchange: Move functions around in file.
This just puts similar functions near each other.
2018-12-04 17:16:29 -08:00
Steve Howell d9439e819e hashchange: Remove block comment.
This comment is less necessary now that we have docs
and have cleaned up the code a bit.
2018-12-04 16:13:18 -08:00
Anders Kaseorg 9ba860b4f2 Avoid double redirects to /login and then to /login/.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2018-12-04 16:12:58 -08:00
Tim Abbott d5f2eb3790 Revert "buddy list: Put "me" at the top of the list."
This reverts commit 1890c30ee1.
2018-12-04 16:08:18 -08:00
Rohitt Vashishtha ee3b4f3ee9 hotkeys: Map `CTRL + .` to narrow to compose box target.
Also adds relevant tests and documentation. We currently
do not narrow to a new topic, and instead just narrow to
the stream. Similarly, we do not narrow to a PM if any of
the recipients are invalid.
2018-12-04 13:58:00 -08:00
Tim Abbott 9ea4f50c1b Revert "search: Open typeahead on empty string only if lookup triggered by Tab."
This reverts commit b961093c14.
2018-12-04 13:58:00 -08:00
Steve Howell 4af1061974 Remove unused expected_hash variable.
We stopped setting this nearly five years ago, as part
of bd9cccffce

The big conditional that I removed here should have
always evaluated to false, as I understand the code.
Presumably either the browsers handle # -> '' redirects
better now, or we address this somewhere else in our
codebase.
2018-12-04 12:24:39 -08:00
Steve Howell a9391e0499 keydown_util: Ignore alt-arrow and similar things.
We ignore keystrokes like alt-left-arrow and alt-right-arrow,
so that the browser can do back/forward.

We may need to refine the handling of ctrl/alt/shift in the
future, but now we only support single-key operations.
2018-12-04 12:24:39 -08:00
Steve Howell 7a2527aed1 hashchange: Call stop_auto_scrolling() directly. 2018-12-04 12:24:39 -08:00
Steve Howell 6bfcebe6da Update hashchange docs and tweak function names.
This is mostly doc updates, and we also rename
a couple functions to have more consistent naming.
2018-12-04 12:24:39 -08:00
Steve Howell 1804d6c9ce Make back button work for some Settings/Org changes.
This change removes all the complexity around
get_hash_group(), and we now only go into the
"same overlay" logic within Settings or within
Manage Organization, but not between them.

This means if you're in Settings but hit the back
button to something under "#organization" we now
do "more stuff", since we want to err on the side
of reloading sections, etc.

There's not much flicker in my testing, and
this is not a super common transition, anyway.
2018-12-04 12:24:39 -08:00
Abhinav Singh 979fae0406 portico: Add autofocus to the first input field with errors.
This code brings the focus to the first input field with errors rather
than just the first input field present in the form after the sign up
form is rendered again after invalid data is submitted.

Note from tabbott: This still doesn't handle the ToS checkbox being
the source of the error, but that's an independent issue.

Fixes #10869.
2018-12-04 12:22:09 -08:00
Abhinav Singh 586ce70b8b portico: Auto-detect field to focus for registration page.
This replaces the manually-curated logic for which field to focus.
2018-12-04 12:22:09 -08:00
Aditya Bansal 7d0d4b5eec integrations: Start to use flex box for positioning in dropdown.
Positioning using flexbox makes life much easier for everyone. With
this change we make positioning of icon relative to the label in the
dropdown menu much easier to do and alter if required. We now no
longer need to fiddle with tedious pixel measurements for placing the
icon in the right place.

As a result of this commit we had to change a click event binding
back to be associated with .dropdown-toggle class rather than being
associated with the h3, i because of the re-arrangement of the
dropdown configs.
2018-12-03 17:29:47 -08:00
Aditya Bansal 9a9dd158c4 integrations: Fix behaviour of angle icon associated with the dropdown.
Here we just fix the behaviour of angle icon which is present
in the integration categories dropdown. It used to change direction
from down to right only if "All" options from the dropdown was
selected (which is also the initial and default option). This behaviour
was pretty inconsistent and looked odd. Rather than having a direction
changing icon here, it migth be just better to stick with just the
down facing angle arrow. Arrow direction in general represents in
which direction the dropdown is gonna open up (in addition to the
fact that a dropdown exits here).
2018-12-03 17:21:17 -08:00
Aditya Bansal b32f54e775 integrations: Add animation to integrations dropdown.
We make the integration categories dropdown gradually slide down/up
rather than appearing instantenously. I believe this gives a better
look to the dropdown and how it behaves.

We also fiddle a bit with the code relating to angle icon in the
dropdown. Basically though its behaviour was already buggy and
will be addressed in an upcoming commit, we try to maintain whatever
behaviour it had before introduction of the annimation effect.
2018-12-03 17:21:17 -08:00
Aditya Bansal 11f896809f integrations: Fix issue with area from where dropdown can be toggled.
The issue here was that if we opened up integrations page in
responsive mode (so the integrations category sidebar turns into a
dropdown) and click a few centimeters outside the actual dropdown
or perhaps the dropdown menu when its open, it is possible to toggle
or select a integration category.
What this essentially means is that clicking in blank area outside
visible boundaries of dropdown menu its possible to interact with it.

Fix: We change elements on which the click event is tied to and
adjust a bit of CSS for relevant elements so things look as they
used to but function in correct or better manner.
2018-12-03 17:21:17 -08:00
Aditya Bansal 98cab354bd integrations: Fix buggy behaviour around categories dropdown.
What is the buggy behaviour?
Before this commit if you were to open the integrations docs page
in a smaller window so that the integrations categories sidebar
changed into a dropdown (so that our page is responsive to
screen size), one would notice that selecting a category from the
dropdown menu didn't make dropdown to auto collapse. This feels very
uncomfortable from users prespective since an ugly dropdown with all
the categories sticking around uncollapsed kind of defeats the purpose
of having a dropdown.

Fix: We make the categories dropdown toggle/auto collapse upon
selection of a category.
2018-12-03 17:21:17 -08:00
Shubham Padia b961093c14 search: Open typeahead on empty string only if lookup triggered by Tab.
Fixes part of #10026.
Adds additional option to typeahead:
`tabOpensEmptyTypeahead`(default: false):
tabOpensEmptyTypeahead overrides helpOnEmptyStrings.
This commit sets helpOnEmptyStrings to false and
tabOpensEmptyTypeahead to true. Now typeahead will
open on an empty string only if Tab has been pressed.
2018-12-03 16:54:38 -08:00
Tim Abbott 333b8ef668 signup: Move registration JS to signup.js.
Also, fix a linter error encountered in the process.
2018-12-03 12:22:59 -08:00
Steve Howell 779ed37cfa hashchange: Fix update_browser_history() call for settings.
Even prior to my recent change in settings_panel_menu.js,
we were assigning window.location.hash a value that doesn't
have a '#' prefix.  This probably doesn't matter too much
for the browser, but it does confuse our own checks about
whether we're redundantly updating browser history.

Now we prefix the settings hash with '#' and we encorce
this convention with a blueslip error.
2018-12-03 10:09:35 -08:00
Steve Howell 05be16e051 hashchange: Remove is_exit_overlay code.
Just calling update_browser_history is sufficient
here, and we end up short-circuiting some code
in hashchanged():

    * we don't need to set state.old_hash, because
      that's what update_browser_history does
    * we bypass the is_overlay_check, which is always
      false in this context
2018-12-03 10:09:35 -08:00
Steve Howell c8cbf39a16 Avoid fake clicks when launching settings pages.
Fake clicks sometimes require more code, and they're
brittle to selectors changing, and it's harder to
debug.
2018-12-02 19:07:24 -08:00
Steve Howell c4d3578de3 Move more code into activate_section().
This code was added to the click handler, but it can
really go into activate_section().  This way the code
also runs when we first launch settings.
2018-12-02 19:07:24 -08:00
Steve Howell 473f2650fd refactor: Change settings_panel_menu.activate_section().
We now have activate_section take a section, rather than
an li, so it will be easier to call directly.
2018-12-02 19:07:24 -08:00
Steve Howell ec3f6434a6 subs: Remove complicated onlaunch triggers.
We can reliably just use hashchange.go_to_location()
when you click on "Stream Settings" in the left
sidebar popover.
2018-12-02 19:07:24 -08:00
Steve Howell 623e3f3c9f hashchange: Extract hash_util.stream_edit_uri. 2018-12-02 19:07:19 -08:00
Steve Howell bc18eb1d41 stream links: Use more standard API to go to location.
For stream links inside messages (like "#social") we
now use these functions:

    hashchange.go_to_location:

        We don't need to set href.  Relative paths
        are more standard, and the url is already
        encoded.

    hash_util.by_stream_uri:

        This saves a step in building the URL.
2018-12-02 19:07:19 -08:00
Steve Howell 846dfb2fe4 hashchange: Extract hashchange.go_to_location().
We use this API when we want the machinery
of the hashchanged system to come into play.
2018-12-02 19:07:15 -08:00
Steve Howell 636e54389b settings: Streamline code for navigating panels.
We call hashchanged.update_browser_history() when
we switch panels.  This API short circuits the
hashchanged callback and avoids code churn.

(We weren't actually double rendering, as the downstream
code does nothing at this point, so this is more
just preventig a pitfall and moving to a consistent
API.)
2018-12-02 19:07:15 -08:00
Steve Howell f930502312 stream settings: Streamline up/down arrow code.
We can eliminate export_hash() and just directly
call switch_to_stream_row().
2018-12-02 19:07:15 -08:00
Steve Howell b4d5c7e68a hashchange: Avoid double-rendering Subscribed/All tabs.
Before this commit, we would sometimes have
the toggler handle clicking or arrowing to
the All tab, but then also rewrite the hash
which caused us to re-process the event.

Now we only call update_browser_history()
in the callback handler from the toggle widget.

There's a bit of refactoring to make this happen,
but the call stacks end up being this:

    call toggler.goto(...)
        # callback is dispatched
            call subs.switch_stream_tab
                actually_filter_streams
                update_browser_history
2018-12-02 19:07:13 -08:00
Steve Howell 45227e84fc refactor: Flatten code in subs.change_state(). 2018-12-02 19:07:13 -08:00
Steve Howell 84d0b541e3 hashchange: Add hashchange.update_browser_history().
This helps us encapsulate the situation where we don't
want to trigger hashchanged(), without having to do it
within sub.js with prevent_once().
2018-12-02 19:07:10 -08:00
Steve Howell 212ee015d4 refactor: Extract subs.switch_to_stream_row. 2018-12-02 18:40:00 -08:00
Steve Howell bea328b8b6 refactor: Split out functions for opening edit panel.
While they can share some code, opening the edit panel
for a stream and clearing the panel are pretty different
actions, so we simplify the API for each thing.

You no longer have to pass in booleans, and for the clear
case, you don't have to pass in a bogus node that just
gets ignored.
2018-12-02 18:40:00 -08:00
Steve Howell 43f25eb4a5 Clean up code to open "Create stream" panel.
This fixes a bug where hitting the "n" hotkey was
causing double work related to the hashchange system.

The code is now organized like this:

    do_open_create_stream() does the GUI piece

    We call the above directly for hash changes.

    For in-app actions, whether clicks or hotkeys,
    we call open_create_stream(), which delegates
    most of the work to do_open_create_stream() but
    also updates the hash.
2018-12-02 18:40:00 -08:00
Steve Howell 13af91869d Deprecate unreachable code in hashchange.
The overlay URLs are never handled in this function,
and the prior code just created confusion.
2018-12-02 18:40:00 -08:00
Steve Howell 7859a441ac bug fix: Avoid spurious calls to subs.change_state.
This diff looks a bit more complicated than it really is.

We had a bug where we'd call subs.change_state for
non-streams-related changes.  The bug probably barely
impacted customers, since it's hard to get into that
situation unless you're in "Settings", and then the
code mostly did nothing.  There's still a deeper issue
of what we actually do want to for settings changes,
but this fix does not address that.

We invert the conditionals related to internal state
changes, so that we can handle internal state changes.

And we make sure to only call subs.change_state if our
"base" is "streams".
2018-12-02 18:40:00 -08:00
Steve Howell b80de69932 hashchange: Rename `ignore` to `state`. 2018-12-02 18:40:00 -08:00
Steve Howell 4b6ae10fb7 Rename group to old_overlay_group. 2018-12-02 18:40:00 -08:00
Steve Howell d11d1313d9 refactor: Flatten code for hashchanged().
Using early-exit make the 3 cases a bit more clear.

    opening overlay
    closing overlay
    "normal"
2018-12-02 18:40:00 -08:00
Steve Howell 1f41a65c88 Rename ignore.flag to is_exiting_overlay. 2018-12-02 18:40:00 -08:00
Steve Howell cee29483cf hashchange: Extract hashchanged_overlay().
This is mostly extracting the code within the `if`
block, as well as setting `base`, which wasn't used
elsewhere.

Also, the `else` no longer calls `is_overlay_hash`,
which was a redundant check.
2018-12-02 18:40:00 -08:00
Steve Howell 20bbc375a5 Rename ignore.prev to ignore.hash_before_overlay. 2018-12-02 18:40:00 -08:00
Steve Howell 53e99c0a55 hashchange: Remove unused ignore.last. 2018-12-02 18:40:00 -08:00
Steve Howell 682235af80 Rename hashchange.should_ignore to is_overlay_hash. 2018-12-02 18:40:00 -08:00
Rishi Gupta c59da02936 billing: Reflect discounts on /upgrade. 2018-11-30 11:19:07 -08:00
Rishi Gupta 1ba037201c billing: Move all price computations into billing.js. 2018-11-30 11:19:07 -08:00
Rishi Gupta 7523282e48 billing: Move cost calculation from upgrade.html to billing.js. 2018-11-30 11:19:07 -08:00
Rishi Gupta 60d3c17b6b billing: Enable tab navigation on /upgrade. 2018-11-30 11:19:07 -08:00
Steve Howell b827efb461 refactor: Extract maybe_reset_right_panel(). 2018-11-29 20:09:24 -08:00
Steve Howell c5b2cfd777 refactor: Extract get_search_params(). 2018-11-29 20:09:24 -08:00
Steve Howell 8f915da2ca refactor: Extract add_tooltips_to_left_panel(). 2018-11-29 20:09:24 -08:00
Steve Howell 3190c3ffeb refactor: Extract show_active_stream_in_left_panel(). 2018-11-29 20:09:24 -08:00
Tim Abbott d0f71881f4 docs: Add detailed documentation on the process for sending messages.
This has long been something missing from our suite of documentation.
2018-11-29 16:25:35 -08:00
Steve Howell d8c8fc1f03 streams: Optimize stream_data.create_sub_from_server_data.
This is definitely a micro-optimization, but avoiding
creating an extra object speeds up page loads by about
20ms per 1000 streams.

It's slightly sketchy to mutate the value in place, but
the original value never gets used again.
2018-11-29 13:29:17 -08:00
Tim Abbott 6781345b9b message_fetch: Fix a linter error introduced on rebase. 2018-11-29 13:29:12 -08:00
Steve Howell ba243416e3 stream_color: Make stream color assignment more efficient.
We now let color_data keep its own state for
unused_colors, so that we longer have to pass in
a large list of unused_colors every time we want
to assign a new stream color.

This mostly matters at startup, where we might
be cycling through 5000 streams.  We claim all
the unused colors up front.

Each operation now has an upper bound of expensiveness,
where the worst case scenario is basically popping
off the first element of a list of <= 24 colors.

The algorithm is now deterministic, too, to make
it easier to test.  It's unclear whether random color
assignment ever had much benefit, and it made unit
testing the algorithm difficult.  Now we have 100%
line coverage.

Fixes part of #10902.
2018-11-29 13:00:25 -08:00
Shubham Dhama 990d7fb37d narrow: Remove `narrow_activated.zulip` event trigger. 2018-11-29 12:36:00 -08:00
Shubham Dhama 654c3240e4 narrow: Remove `narrow_deactivated.zulip` event trigger. 2018-11-29 12:36:00 -08:00
Shubham Dhama 42f1d2a33b tab_bar: Make explicit call of narrow change handle function. 2018-11-29 12:36:00 -08:00
Shubham Dhama b726cd4b3e typing_events: Make explicit call of narrow change handle function. 2018-11-29 12:36:00 -08:00
Shubham Dhama e908da7831 narrow: Remove some `narrow_deactivated.zulip` event handling. 2018-11-29 12:36:00 -08:00
Shubham Dhama 209dd6dd37 narrow: Extract processes needed to be executed after narrow deactivate. 2018-11-29 12:36:00 -08:00
Tim Abbott 83b127cec1 server_events: Extract functions for managing connection errors.
This cuts a bit of code duplication.
2018-11-29 12:31:08 -08:00
Shubham Dhama 01927fb470 message view: Fix hiding of connection-error message on narrowing streams.
When there is some error in connecting to server(more specifically to the
tornado server) the "Unable to connect to Zulip" connection error message
gets cleared as Django server could send the response of "get" request of
old messages and hence get_old_messages_success hides the error message
even though the connection is not properly established.

Fixes: #5599.
2018-11-29 12:26:41 -08:00
Tim Abbott 02f09e2473 settings: Fix linter errors with user profiles. 2018-11-28 19:29:33 -08:00
Tim Abbott e39ebb7358 settings: Fix "Preview profile" button.
This was apparently broken in the refactoring in
a394778cde.
2018-11-28 16:46:15 -08:00
Yashashvi Dave fe3270d2b9 input pills: Fix modal gets closed when user click on remove-pill-btn.
This commit fixes bug: When user clicks on remove-user-pill-btn,
it closes the parent modal instead of removing user pill from input.
This happens because button has class `exit` and there is click
event listener on all `exit` class buttons, which closes modal.

Fix this by adding `e.stopPropogation` to remove-user-pill listener.
2018-11-28 16:33:08 -08:00
Yashashvi Dave 28c38a44c8 static/js/popover: Use predefine func to append user pills in field.
This commit remove repetitive code to append user pills in
custom field of user profile popover. And call already defined
function there.
2018-11-28 16:22:35 -08:00
Yashashvi Dave 20b6d08ef7 static/js/settings_account.js: Extract `append_custom_profile_fields`. 2018-11-28 16:22:35 -08:00
Yashashvi Dave b2aeffd947 static/js/settings_account.js: Extract `intialize_custom_user_type_fields`. 2018-11-28 16:22:35 -08:00
Yashashvi Dave cd8f4dfac0 statis/js/settings_account.js: Extract `initialize_custom_date_type_fields`. 2018-11-28 16:22:35 -08:00
Balaji2198 16967d6761 static/js/settings_streams.js: Refactor delete_default_stream method. 2018-11-28 16:17:21 -08:00
Nikhil Kumar Mishra 478674a6d6 analytics: Refactor to support more than one tooltip on same page.
While we don't actually need another tooltip on /stats right now, this
provides a clear approach for how to do that.  We've since added
tooltips in various other parts of the webapp, and that code is pretty
copy-pasteable, so I think it's reasonable to say this closes #4612.

Cleaned up by tabbott to remove a bunch of unnecessary changes.
2018-11-28 16:04:35 -08:00
Steve Howell 6035304619 Extract color_data.js.
This code is pretty distinct from all the color-picking UI,
and we want to get it to 100% coverage and optimize it
more.
2018-11-28 14:51:51 -08:00
Tim Abbott d8c5ad2a26 narrow: Add special text for conversation with yourself. 2018-11-28 11:59:16 -08:00
Abhinav Singh 0774bd7df0 portico: Fix password strength bar reset after form invalidation.
This code prevents the password bar from being incorrectly clear after
the sign up form is rendered again after invalid data is submitted
(generally due to forgetting to agree to ToS).

Fixes #10868.
2018-11-28 11:52:08 -08:00
Steve Howell b79d63e9c3 copy/paste: Try to fix Casper flake and add comments.
I think this will fix a Casper flake where there was a race
window with multiple temp DOM elements holding copied text.

I also add a comment to the code I think causes this race
for the tests.
2018-11-27 21:42:16 -08:00
Tim Abbott bddf23894d buddy list: Add marker for which user is yourself.
This helps make clear what's going on with the potentially confusing
"you" user.
2018-11-27 15:07:58 -08:00
Steve Howell 1890c30ee1 buddy list: Put "me" at the top of the list.
I think people will want this, particularly folks
with names toward the back of the alphabet.
2018-11-27 14:52:19 -08:00
Steve Howell 3aa490edbe Add current user back to the buddy list.
For many years we have been excluding the current user
from the buddy list, since their presence is kind
of implicit, and it saves a line of real estate.

This commit removes various user-is-me checks
and puts the user back for the following reasons:

    * explicit is better
    * newbies will be less confused when they
      can see they're actually online
    * even long-time users like myself will
      feel more comfortable if it's just there
    * having yourself in the buddy list facilitates
      things like checking your presence or sending
      yourself a message
    * showing "me" reinforces the meaning of the
      green circle (if my circle is green and I'm
      active, then others with green circles must
      be active too)
    * If you're literally the first user in the
      realm, you can now see what the buddy list
      looks like and try out the chevron menu.

The biggest tradeoff here is the opportunity cost.
For an org with more people than fit on the screen,
we put the Nth person below the fold to show "me".
I think that's fine--users can still scroll or
search.

This commit doesn't do anything special with the
current user in terms of sorting them higher in the
list or giving specific styling.

Fixes #10476
2018-11-27 14:52:19 -08:00
Steve Howell 731f76cea1 refactor: Have buddy_data.level() take user_id.
All the callers were having to call get_status().
We now do it for them.
2018-11-27 14:52:19 -08:00
Steve Howell 1e9d0718eb refactor: Flatten code in presence.set_info().
We reduce nesting of code by just early-exiting
for the `is_current_user` check.

This also forces us to be a bit more thorough
with our tests if we want to maintain line
coverage.
2018-11-27 14:52:19 -08:00
Rishi Gupta dd0126ff1b settings: Improve error message when deactivating the last user.
This PR was originally started by Rishi Gupta (see #10383).
2018-11-27 12:49:43 -08:00
Steve Howell 68d81cb25b subject -> topic: Fix respond_to_message(). 2018-11-16 11:11:40 -08:00
Steve Howell 82b9f2a3db subject -> topic: Fix create_message_object(). 2018-11-16 11:11:40 -08:00
Steve Howell 3e860fbc39 subject -> topic: Fix group.subject references. 2018-11-16 11:05:43 -08:00
Steve Howell 55362263dd Isolate/eliminate uses of "match_subject". 2018-11-16 11:05:43 -08:00
Steve Howell 89c278d1e5 Isolate/eliminate use of "subject_links".
For message groups, I just changed the internal name
to "topic_links".

For uses of "subject_links" that are tied to how the
server names fields, I introduced these wrappers:

    * util.set_topic_links(obj, topic_links)
    * util.get_topic_links(obj)

These can be used for either messages or events.
2018-11-16 11:05:43 -08:00
Yashashvi Dave 5759d5a762 statis/js/bot_data.js: Add `get_bot_owner_email` function. 2018-11-16 09:52:05 -08:00
Yashashvi Dave a394778cde statis/js/popover.js: Remove unused arg from `show_user_profile` func.
Remove unused argument `element` from function `show_user_profile`.
2018-11-16 09:52:05 -08:00
Tim Abbott 86801d350a compose: Store raw_content after fetching it for quoting.
This is a nice performance optimization for the rare case where the
user does quote-and-reply on a message, aborts the compose, and then
re-does the quote-and-reply.
2018-11-14 23:55:26 -08:00
Marco Burstein f37e4df471 compose: Check if `raw_content` is present when quoting.
If `raw_content` is already present for the selected message, there is
no need to make a request to the server.
2018-11-14 23:52:08 -08:00
Steve Howell 6546fb3f1d subject -> topic: Fix local subject vars. 2018-11-14 23:24:06 -08:00
Steve Howell 51f8ac91ec subject -> topic: Rename current_subject. 2018-11-14 23:24:06 -08:00
Steve Howell a172ac264d subject -> topic: Rename by_stream_subject_uri. 2018-11-14 23:24:06 -08:00
Steve Howell b615f0df4d subject -> topic: Fix stream/subject in comments. 2018-11-14 23:24:06 -08:00
Steve Howell c6ad12d058 subject -> topic: Fix local vars in stream_list. 2018-11-14 23:24:06 -08:00
Steve Howell 3a9c81ed8c subject -> topic: Rename add_subject_links. 2018-11-14 23:24:06 -08:00
Steve Howell 91e4784b92 subject -> topic: Rename narrow.by_subject. 2018-11-14 23:24:06 -08:00
Steve Howell 6c1a96174e subject -> topic: Rename narrow_by_subject. 2018-11-14 23:24:06 -08:00
Steve Howell 7ae8907b3f subject -> topic: Rename narrows_by_subject. 2018-11-14 23:24:06 -08:00
Rohitt Vashishtha d7a0bd4a6c subject-to-topic: Add topics to compose_state.js. 2018-11-14 23:24:06 -08:00
Steve Howell 47e464528c refactor: Split up add_display_time().
We split out two new functions and call them
everywhere that we used to call add_display_time():

    - `update_group_time_display`
    - `update_timestr`

We also make some of the local vars more consistent,
as well as doing more explicit clearing of vars than
`delete`.

Splitting these functions will allow us to muck with date
dividers without affecting the `update_str` functionality.
2018-11-14 22:47:29 -08:00
Yashashvi Dave 89eebad14f user profile: Add user type/role in user profile popover.
Add user type/role in user's detail profile popover.

Fixes part of #10754
2018-11-12 15:13:44 -08:00
Yashashvi Dave 54dd7f0a43 user info popover: Add user type/role in user information popover.
Add user role-- "Administrator", "Member", "Bot" or "Guest"
under 'Local time' in user information popover.

Fixes part of #10754
2018-11-12 15:13:44 -08:00
Yashashvi Dave 614624d232 static/js/popover.js: Extract `render_user_info_popover`. 2018-11-12 15:13:43 -08:00
Tim Abbott 67fa755158 popovers: Remove now-unused narrowed argument to user info popover.
This stopped being used in bbfd33185c.
2018-11-12 15:10:19 -08:00
Tim Abbott 5a9f00dae4 popovers: Sort arguments for user info popover.
This makes it easier to see how the two duplicate implementations differ.
2018-11-12 15:09:09 -08:00
Tim Abbott 4c8f439ece popovers: Standardize calculation of show_user_profile. 2018-11-12 14:59:39 -08:00
Tim Abbott 96284bd336 popovers: Use attributes of user object more consistently.
This is a preparatory refactoring to make it easy to see what's
different as we deduplicate this logic.
2018-11-12 14:59:38 -08:00
Tim Abbott 08529507c8 popovers: Sort arguments to user info popover rendering.
This is a first step towards deduplicating this logic.
2018-11-12 14:59:23 -08:00
Yashashvi Dave 53201c5411 statis/js/people.js: Add function `get_user_type`.
Add function `get_user_type`, which returns user
type-"Administrator", "Guest", "Bot" or "Member"
depending on what they are.
2018-11-12 14:57:32 -08:00
Tim Abbott 2c06615909 streams: Fix stream color synchronization.
Previously, when a new stream was created on a client other than the
current one, the browser would first receive the "stream_created"
event, and make up a client-side display color at that time to use in
the "stream settings" view (it doesn't yet know the color that was
selected when the user was actually subscribed, because it doesn't
even know yet that the user is being subscribed to this stream), and
then moments after it'll receive a "susbcribe" event letting the
client know that the user is subscribed (and specifying the color to
use).

However, due to an argument not being passed through properly and a
missing rerender, we were not properly updating either the data
structures or doing a stream colors rerender in order to show the new
color.

This fixes the issue reported in
https://chat.zulip.org/#narrow/stream/48-mobile/subject/stream.20colors/near/660170
2018-11-09 17:04:47 -08:00
Marco Burstein 207d7a8ee6 compose: Use a placeholder when quoting and replying.
Use the placeholder `[Quoting…]` when quoting and replying before the
quote has been added to the message. Also, add tests to the
`compose_actions` Node tests for the new behavior.

Fix #10705.
2018-11-07 09:56:38 -08:00
Yashashvi Dave 8c72adc106 subscribers: Hide subscribers of non-subscribed stream for guest user in UI.
Guest users can't access subscribers of any(public or private)
non-subscribed streams. Therefore, hide subscribers list
of all non-subscribed streams from guest users in UI.

Fixes #10749 (the previous parts were fixed already).
2018-11-06 12:57:19 -08:00
Yashashvi Dave f6b4e65b92 compose: Hide sub-btn in compose-to-unsub warning if user can't subscribe.
Hide subscription button in compose-message-to-unsubscribe-stream
warning, if user can't subscribe back to stream.
2018-11-02 11:57:04 +05:30
Vishnu Ks 4533f8f962 billing: Make URL hash work in billing page.
This will change the hash of the URL when a new tab
gets selected. Vice versa when the billing page is opened
the appropriate tab is selected according to hash of
the URL. This means when the card gets updated the
page would be reloaded correctly to show #payment-method
tab.
2018-11-01 12:50:24 -07:00
Marco Burstein 502e9fe8a6 compose: Open the mobile compose popover when the `+` button is pressed.
The `+` button will only be displayed on mobile devices.
2018-10-31 16:47:48 -07:00
Marco Burstein 05b486182d compose: Create the mobile compose popover.
When a user clicks the compose `+` button, create a popover at the
bottom right of the screen including buttons for opening a new stream
message or a new private message.
2018-10-31 16:47:48 -07: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
Yashashvi Dave e489923d52 stream settings: Hide subscription button in case of guest user.
Guest users can't subscribe themselves to any stream, so we hide the
"Subscribe" button. Previously, it was showing Subscribe button after
a guest user unsubscribed from a stream.

Fixes part of #10749.
2018-10-31 15:46:34 -07:00
Shikhar Vaish 5ffca5e388 settings: Warn if server is unable to deliver mobile push notifications.
The "notification settings" page previously advertised support for
mobile push notifications via checkboxes, even if the server hadn't
yet been registered for push notifications.  This was a frequent
source of onboarding pain for new Zulip organizations.

We fix this by providing a clear warning and disabling the relevant
inputs on the settings pages.

Modified significantly by tabbott to correct some tricky logic errors
as well as some copy-paste bugs.

Fixes #10331.
2018-10-31 13:18:17 -07:00
Tim Abbott deb29749c2 people: Add a CSS class to label guest users.
This doesn't do anything yet, since we still need to add the actual
CSS, but it should make it easy for someone to just do the design
work.
2018-10-31 10:15:49 -07:00
Rishi Gupta ef8113556a settings: Update dropdown in user roles modal. 2018-10-30 10:48:06 -07:00
Rishi Gupta 37e00dce78 settings: Update organization permission strings to reflect guests. 2018-10-30 10:48:06 -07:00
Steve Howell 706821e259 minor: Change error to warning for missing user ids.
We want to avoid `blueslip.error` in cases where
the root cause could just be bad data that is
human-entered.

There are a few callers here who **should** be
sending good data all the time, but hopefully
they either have good test coverage, other
obvious failure symptoms, or, ideally, just
do what the user would mostly expect in the
face of bad data.
2018-10-29 12:57:15 -07:00
Pragati Agrawal d5df0377cc settings_users: Support guest user in admin-user-table.
This supports guest user in the user-info-form-modal as well as in the
role section of the admin-user-table.

With some fixes by Tim Abbott and Shubham Dhama.
2018-10-29 12:33:35 -07:00
Steve Howell 3a267b5cc6 Have ESC zoom out topics if you're zoomed in.
This is the natural behavior that most users will
probably expect.  If you need to go to All Messages when
topics are zoomed in, you can just hit ESC twice.
2018-10-24 16:54:35 -07:00
Steve Howell 06b1aece31 Simplify narrow/search interactions.
Before this change, if you hit ESC, then hotkey
code would call search.clear_search, which would
call narrow.deactivate(), which would then use
`$('#search_query')` to clear a value, but then
let search.clear_search blur the input and
disable the exit button.  It was all confusing.

Things are a bit more organized now.

Now the code works like this:

    hotkey.process_escape_key
        Just call narrow.deactivate.

    $('#search_exit').on('click', ...):
        Just call narrow.deactivate.

    narrow.deactivate:
        Just call search.clear_search_form

    search.clear_search_form:
        Just do simple jquery stuff.  Don't
        change the entire user's narrow, not
        even indirectly!

There's still a two-way interaction between
the narrow.js module and the search.js module,
but in each direction it's a one-liner.

The guiding principle here is that we only
want one top-level API, which is narrow.deactivate,
and that does the whole "kitchen sink" of
clearing searches, closing popovers, switching
in views, etc.  And then all the functions it
calls out to tend to have much smaller jobs to
do.

This commit can mostly be considered a refactoring, but the
order of operations changes slightly.  Basically, as
soon as you hit ESC or click on the search "X", we
clear the search widget.  Most users won't notice
any difference, because we don't have to hit the
server to populate the home view.  And it's arguably
an improvement to give more immediate feedback.
2018-10-24 16:54:35 -07:00
Steve Howell 08f0690333 left sidebar: Fix scrolling bugs with zoomed topics.
If you zoom into "more topics" for a stream that has
a LOT of topics, and then scroll down to the bottom,
and then zoom out by selecting "All messages" or
similar upper-left-sidebar options, we now try to scroll
the more recently active stream back into place after we scroll
out.

Before this change, it was possible for your lower left
sidebar to appear empty, as it would keep the
scroll offset from "more topics".
2018-10-24 16:54:35 -07:00
Steve Howell 4bfb49c3a4 Streamline closing topic lists.
If our topic list isn't zoomed in, avoid calling
stream_list.zoom_out_topics().

This commit also introduces `zoomed_in` to track
our topic zooming state.
2018-10-24 16:54:35 -07:00
Steve Howell 047a81dd2c refactor: Move clear_topics into topic_zoom.js.
This sets up some subsequent changes.
2018-10-24 16:54:35 -07:00
Steve Howell acb7149386 Extract topic_zoom.js.
This small modules nicely breaks down the
responsibilities of topic_list and stream_list
when it comes to zooming in and out of topics
(also known as hitting "more topics" or "All
Streams).

Before this, neither module was clearly in
charge, and there were kind of complicated
callback mechanisms.  The stream_list code
was asking topic_list to create click handlers
that called back into stream_list.

Now we just topic_zoom set up its own click
handlers and delegate out to the other two
modules.
2018-10-24 16:54:35 -07:00
Steve Howell c58a99b156 PM sidebar: Expand PM sidebar for huddles.
This fixes a regression from here:

    88b4a9f2d7

The fix didn't account for how huddles are
represented as comma-delimited strings.

We also simplify the logic by extracting a
function and doing early-exit for simple
cases.
2018-10-22 12:22:26 -07:00
Steve Howell 328e2ff316 Fix "Copy link to conversation" links.
This cleans up the code for stream links
and creates nicer, more correct links for
PMs.

Fixes #10605
2018-10-22 12:22:26 -07:00
Steve Howell adf616d3f1 Add pm_perma_link helper. 2018-10-22 12:22:26 -07:00
Steve Howell 8c49985058 url decoding: Handle your own id being in PM slugs.
Internally we generally omit our own id and email
in data structures related to PMs, except when we
are the sender, but if we receive "perma links"
we will need to filter out our id.
2018-10-22 12:22:26 -07:00
Pragati Agrawal cc0ac4d340 settings_users: Change "role" column text on updation.
This reflects the newly selected value of role in "role" column under
active-users section and deletes the redundant admin-icon updation code(
As we already removed bolt admin-icon)
2018-10-19 15:51:12 -07:00
Yashashvi Dave cc810f8951 settings: Fix width not maximum while uploading user avatar.
New user avatar width is not maximum when user upload
new image. Because wrong html element is accessed for
setting value of image src attribute.
This commit removes these code from success of ajax call,
cause we already handle this in event `user_events - avatar_url`.
2018-10-19 12:36:18 -07:00
Steve Howell fd22687cd2 refactor: Split out buddy_list_conf().
This moves us closer to having a generic widget that
we can use for other things like stream settings.
2018-10-16 16:53:47 -07:00
Steve Howell 653aa40384 Extract buddy_list_create().
This makes buddy_list look more similar to other modules
where we don't indent within the boilerplate IIFE.
2018-10-16 16:53:47 -07:00
Shubham Dhama d1c62369b7 templates: Add `is_false` handlebars helper.
There is need for such a helper because `unless` executes to be true even
when we haven't passed the context variable on which we are checking the
conditional statement.
2018-10-16 13:07:53 -07:00
Aditya Bansal 75ae94e459 font-awesome: Drop support for legacy font awesome icons.
We drop support for usage of `icon-vector` as base class when
including icons from font awesome icons package.
Now on, only icons as specified in font awesome v4.7.0 can be used
in the code base.
2018-10-15 20:14:55 +05:30
Aditya Bansal 7eeed1413c icons: Remove base class from comments and test templates. 2018-10-15 19:55:18 +05:30
Aditya Bansal a4b51a33f8 timerender.js: Remove use of legacy font awesome base class 'icon-vector'. 2018-10-15 19:22:57 +05:30
Steve Howell 72295e94b4 typing indicators: Use user ids internally.
We now ask compose_pm_pill to give us a list of user
ids that we are PM'ing to, and we only convert user
ids to emails right before we put requests on the wire.

We also let the "pill system" tell us whether we
have unconverted data.

It also sets up for an upcoming server change where we
can just send user ids to the server.

This change should be transparent to the majority of users.
For Zephyr users we are slightly less aggressive about
sending typing indicators, since we now require valid
user ids.
2018-10-14 09:38:32 -07:00
Cynthia Lin c0edcf6fe4 user profiles: Remove empty space under profiles with no set fields.
Fixes #10652.
2018-10-14 09:37:18 -07:00
Rohitt Vashishtha 0d8ce4201c composebox_typeahead.js: Use people.get_mention_syntax. 2018-10-13 16:42:50 -07:00
Rohitt Vashishtha f857111920 popovers.js: Use people.get_mention_syntax. 2018-10-13 16:42:50 -07:00
Rohitt Vashishtha 11e4011d5f transmit.js: Use people.get_mention_syntax. 2018-10-13 16:42:50 -07:00
Rohitt Vashishtha 38cddf7d54 compose_actions: Use people.get_mention_syntax in reply_with_mention. 2018-10-13 16:42:50 -07:00
Rohitt Vashishtha b18f9def06 people.js: Add get_mention_syntax to conditionally get @user|id syntax.
This is intended to replace all function calls for generating mention
syntax for a target user.
2018-10-13 16:42:34 -07:00
Tim Abbott 3c2f49edaa message_flags: Fix JS exception when handling starred messages.
Previously, if one starred a message that wasn't in the browser's
locally cached history, it'd throw a JavaScript exception.
2018-10-12 13:52:30 -07:00
Steve Howell 27ef6a9991 compose pill: Add has_unconverted_data() helper. 2018-10-12 11:20:30 -07:00