Commit Graph

163 Commits

Author SHA1 Message Date
N-Shar-ma c64726ea9a compose: Retain compose state across narrows if recipient was edited.
Uptil now, the compose box's state was retained across narrows only if
the compose box had any content in it. Else it was reset to match the
current narrow.

To not lose any changes made to the recipient fields only, the compose
box will now retain its state also if the recipient (stream, topic or
PMs) has been manually edited.

This is achieved by having a variable in `compose_state` track if the
recipient fields were changed, and checking it before resetting the
compose box on narrowing. This variable is reset when the compose box's
context is changed by clicking on a message, or when a message is sent.

Fixes: #23064.
2023-01-20 12:56:37 -08:00
evykassirer 53d8abe79b compose_state: Use stream_name() and topic() universally.
This change ensures that every call to find the stream name or topic
in the composebox is calling compose_state functions instead of directly
taking a value from an HTML element specified by a classname.

This has better code readability and abstracts away the classname,
and also makes it easier to change which classname we use (which
will be happening in an upcoming change as part of switching the
stream name field to a dropdown).

Note that this change means that the stream name will always be
trimmed, whereas before it was whatever the user had written even
if it had trailing whitespace. This shouldn't be an issue as far
as we (me + Tim) can tell, and also it will become irrelevant as
soon as the dropdown changes land.
2022-12-15 17:26:04 -08:00
evykassirer 7f9989003a compose_state: Break out stream_name() into separate getter and setter.
This code is equivalent, because the keep_leading_whitespace parameter
of get_or_set was never used for the stream name.

This addresses an open TODO and makes the code more readable.
2022-12-15 17:25:36 -08:00
evykassirer 1b0a14bf40 compose banner: Add specific functions to clear warnings and errors.
Instead of removing all compose banners, we now remove only warnings
and errors -- this makes no difference right now, but this change
will allow us to add other compose banners that are cleared at
different times.
2022-12-14 20:36:07 -08:00
N-Shar-ma 38587b79b9 compose: Always preserve cursor position post replacement in a textarea.
Refactored (moved) the code for preserving the cursor's initial logical
position from `quote_and_reply()` in `compose_actions.js` which calls
`replace_syntax()` directly into `replace_syntax()` in `compose_ui.js`.
This ensures that anytime text in a textarea is replaced, the original
cursor position is always restored.

Earlier, this was needed to be done separately, and missing that would
lead to bugs with the cursor unexpectedly jumping on replacement.

Fixes: #23863.
2022-12-14 12:40:51 -08:00
evykassirer 8ced075643 compose: Migrate compose-all-everyone to use compose_banner.
This is part several updates for #22524.

Testing note: I removed the test test_compose_all_everyone_confirm_clicked
since it heavily relies on the old way of rendering banners and is too
UI-focused (instead of logic focused) for me to feel like it's worth
testing that the banner is removed when clicking the button.
2022-12-06 15:43:34 -08:00
evykassirer 85cbd324eb compose: Create shared compose banner and use for resolved topic warning.
This is the beginning of a fix for #22524 which converts several
banners to a new style. As a part of that set of changes, this
commit creates the shared template and warning styling. The
resolved topic warning was picked (for no particular reason)
to migrate first. Further commits updating other banners
to follow.
2022-12-06 15:42:07 -08:00
Lauryn Menard 54ad2f5266 compose-actions: Stop compose box load for invalid users with any trigger.
A user could trigger a "pm-with" narrow with an invalid user by moving
back/forward in the session, which would trigger the compose box to
open via a hash change. Updates the check to pass in any "pm-with"
narrow with an invalid user.

Also, if the compose box was active/started in the previous view, but
without any content, then we want to actively cancel/close it in the
invalid user "pm-with" narrow.
2022-11-04 14:08:25 -07:00
Lauryn Menard 09c4e2f662 compose-actions: Load compose box for PMs based on org policy.
If an organization has disabled sending private messages, we do not
want to load the compose box automatically for "pm-with" narrows.

We still open the compose box for private messages narrows with a
single bot user as this is not limited by this organization setting.

Also, if the compose box was active/started in a narrow with a bot
user, but had no content, then we want to close/cancel that in a
new narrow with a person or group.
2022-11-04 14:08:25 -07:00
Joseph Ho 551c6899be
compose: Stop selecting compose box content after topic change.
Previously, the on_topic_change handler for the compose system would
focus the compose box after a topic change, and also select all content in 
the compose box. Selecting that content makes sense if we think the user's
intent is likely to be deleting that content; but there's no clear reason we
should expect that intent, and it's not particularly consistent with our drafts
model to risk accidentally losing partially composed message content this way.

After some discussion, we've concluded that in both cases reaching this code path
(either the previous topic being "" or the compose box content being entry), it'd
be better to skip the `.select()`.

Fixes #23146.
2022-10-18 17:20:52 -07:00
evykassirer 553723e5d4 compose: Offer narrow to compose target button for private messages.
We already offer this for stream messages, but had been blocked on
adding it for private messages for visual design reasons. The dark
theme had a natural place to put this, since it had a box around the
private message recipient box; but the light theme didn't.

We add a border to the light theme private message recipient box to
allow us to add the same button to private messages, and implement
that button.

Fixes #21962.
2022-10-05 11:11:28 -07:00
Sean Heckathorne 6728ee1f0e compose: Clear preview UI when recipient change clears compose box.
Previously, we cleared the preview element only when cancelling
compose, which meant the compose box would be left in an invalid
state, showing a preview from a no longer active draft, if switching
recipients with it open.

Fix this by moving the call to clear the preview state to clear_box,
which is called in both the hide_box (close compose) and change
recipient code paths for clearing compose after not having sent a
message.

Fixes #22703.
2022-08-25 16:07:44 -07:00
Anders Kaseorg fde9b1d366 channel: Remove idempotent retry loop.
This was added by commit 7f174213ed, and
appears to have been designed for responses that are *successful* but
falsy. Logically, these should not implicitly represent a failure to
be retried if it were.

Note from tabbott: The background is that this idempotent retry loop
was a hacky workaround for a bug we never understood but saw daily in
production. Especially during server restarts / client reloads,
something would result in 200 responses with no data being seen by the
frontend, despite the Django server not having received/processed the
request. Fortunately, this strange failure mode appears to have
stopped happening in late 2019, so we can delete this hack.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-08-19 12:14:41 -07:00
Anders Kaseorg b0dba411d9 js: Skip redundant jQuery object reconstruction.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-08-18 16:11:13 -07:00
evykassirer 0524e1b40d compose: Rename show_box to show_compose_box.
This lets us remove a comment to clarify this.
2022-08-03 17:05:15 -07:00
Sahil Batra 74476317fd compose: Remove validation for stream named "announce".
Originally, DEFAULT_NOTIFICATION_STREAM_NAME was set to
"announce" and we also showed warning in frontend when
user was composing message to "announce" stream and if
the stream had more than 60 subscribers.

But we changed DEFAULT_NOTIFICATION_STREAM_NAME to "general"
in d46b125bf2. That commit did not remove the frontend code
for showing warning and this commit removes it since there
is no "announce" stream by default now, and we would not
want to show warning when sending to "general" since that
stream could be used for many discussions and it would not
be nice experience to show warning everytime.
2022-07-22 17:19:40 -07:00
Dinesh 43107e1424 compose_box: Add button to go the narrow message is being composed to.
This'll be shown only when in a different narrow from what
you're composing to.

Takes care of updating display of the button on moving from
one narrow to another and also on changing inputs. This is
what contributes to majority of js code in this commit.

We are not displaying this for private messages since we do not
have a consistent design for both stream and private compose areas.
See https://chat.zulip.org/#narrow/stream/101-design/topic/narrow.20to.20topic.2Fpms.20when.20composing/near/1318548

Thanks to Vlad Korobov for the icon and for proposing various
designs.
2022-04-28 12:57:42 -07:00
Anders Kaseorg f84a2c08d5 js: Prefix jQuery object variable names with $.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-16 12:52:07 -07:00
Tim Abbott 562f37b9af compose: Show topic resolve warning only when compose is nonempty.
The resolve topic warning can feel like clutter in the event that the
compose box is empty (which often occurs when the user has no intent
to send a message), so we configure the validation logic to only
display the notice when the compose box is non-empty.

We take some care to minimize work the function is doing, beacuse it
is called on every keystroke in the compose box.

Fixes: #21155.
2022-03-15 17:59:15 -07:00
Tim Abbott ed4ff268a8 compose: Save drafts when starting compose might destroy content.
Starting composing a message to a new recipient will clear the compose
box. Previously, we were saving drafts before doing so only in the
compose_actions.respond_to_message code path (i.e. when starting a
reply). Logically, this behavior should apply regardless of why we're
initiating a new message, so it belongs in compose_actions.start.

Fixes #21128.
Fixes #21171.
2022-03-10 16:17:51 -08:00
Austin Riba b22578f975 hash_util: Rename _uri functions to _url.
It's 2022 and the WHATWG no longer recognizes the term URI. Everything
is now a URL or a type of URL. Which is great because it's way less
confusing. Details here:
https://url.spec.whatwg.org/
2022-03-01 18:14:31 -08:00
Aman Agrawal a38b11d188 resize: Rename reset_compose_textarea_max_height.
This no logner just resets the max-height of compose-textarea
but also preview_message_area.
2022-02-02 10:01:27 -08:00
Priyam Seth 17f74a3f57 compose: Show warning while composing to a resolved topic.
This commit creates the function warn_if_topic_resolved that checks if
the topic to which the user is composing is resolved or not. First it
checks if the stream exists and then if the topic name starts with the
RESOLVED_TOPIC_PREFIX. If the conditions are true, a warning banner is
shown to the user.

It also shows to the user a button to unresolve the topic, if he has
the permission to do so.

Fixes #20584.
2022-02-01 17:50:17 -08:00
YashRE42 be76d7592a reload: Manually save draft and preserve id when triggering reload.
We received a complaint about the generation of multiple duplicate
drafts for a single message. It was discovered that the likely cause
of this was how we were handling clients that were frequently
suspending/unsuspending, we would initiate a reload when we discovered
this, and expect the `beforeunload` handler to save the draft. This
behaved correctly, however, we would also save the compose state and
fill it in via `preserve_state` in reload.js. The important detail
here is that `preserve_state` would not encode and preserve the
`draft_id` for the current message, partly because it had no way of
knowing the `draft_id` of the draft... since we have not saved it yet,
the `beforeunload` event happens after `preserve_state`. As such,
performing any action that would trigger a draft to be saved, eg
pressing Esc to close the compose box, would save a duplicate draft of
the same message.

To resolve the above bug, we (1) ensure that we call
`drafts.update_draft()` in `preserve_state`, this returns a draft_id
to us, which we (2) ensure that we encode as part of the url and (3)
set on the `#composebox-textarea` as a `draft-id` data attribute,
which we check the next time we try to save the draft, post reload.

Note that this causes us to save the draft twice, once from
preserve_state and then again from the `beforeunload` handler, but we
do not add two drafts since the second update_draft call just edits
the timestamp because it finds the `draft-id` data attribute on the
`#composebox-textarea` set by the first call.
2021-12-01 12:03:20 -08:00
YashRE42 555f80c34b compose_actions: Add comment about spread syntax overwrite behavior. 2021-12-01 11:29:37 -08:00
Tim Abbott 23558ebd39 compose: Add missing translation tag to quoting placeholder. 2021-11-28 07:00:46 -08:00
Tim Abbott 8d1013acdb compose: Rewrite quote-and-reply cursor positioning logic.
This fixes unexpected cursor repositioning behavior when the cursor was
positioned before or inside the "Quoting..." element.

The comments document the new logic, but roughly we aim to just
preserve the logical position of your cursor after replacing the
placeholder.

We also factor out a shared variable for the "Quoting..." string which
will allow us to tag it for translation in a future commit.
2021-11-28 07:00:46 -08:00
Tim Abbott 25c9b05bd0 compose: Fix cursor position loss in quote-and-reply.
If you used "Quote and reply" to start composing a message, and
started typing before receiving the original message body from the
server, we ended up resetting your cursor to the start of the line
after the quote for two reasons:

* We were incorrectly fetching the pre_cursor for our replacement
  operation before doing the server fetch, which meant we ignored any
  editing done while waiting for the server to respond.

* Worse, we actually fetched the original cursor position before
  inserting the "[Quoting...]" placeholder text. So we were guaranteed
  to have at least some amount of error in the cursor position.

Fixes #20379.
2021-11-28 07:00:46 -08:00
Anders Kaseorg f194ffbee8 compose_actions: Remove self-import.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-11-23 15:21:48 -08:00
Tim Abbott 53d9797044 stream_data: Rename is_subscribed to is_subscribed_by_name.
Generally the stream_data module aims to do lookup by ID, not name,
wherever possible, so we should represent that in the function names.
2021-11-22 15:44:30 -08:00
Tim Abbott 4e1525d7c4 compose: Fix buggy refocusing of compose box on close.
The `make_compose_box_original_size` function is designed in such a
way that it should only be called when it actually needs to resize the
compose box. In 3 of the 4 places that called it, we checked whether
the compose was already the original size; this fixes the 4th to do
the same.
2021-10-26 17:54:56 -07:00
Aman Agrawal 31de905955 login_to_access: Rename module to `spectators`.
This allows us to call spectators.login_to_access which
is more clear for what it does.
2021-09-07 09:47:28 -07:00
Aman Agrawal fcfc81cdf3 compose: Prompt user to login when trying to compose. 2021-09-06 09:00:16 -07:00
Riken Shah 0dbc7e0d21 compose: Improve how we handle over character limit message error.
We improved it in the following ways:
* Show the error message with the maximum character
limit.

* Disable the send button.

* When the user tries to send the message via hotkeys
i.e, When "Press enter to send" is enabled or the user
uses "Shift" + "Enter" shortcut, Flash the red border
around the compose box.

Also renamed `check_and_set_overflow_text` to
`check_overflow_text` for better clarity.
2021-07-13 08:29:55 -07:00
Signior-X 6cf33c4275 compose: Add support for full size compose box.
This commit makes a working toggler in compose_actions that adds the
compose-fullscreen class to the compose that removes the max-height
from the compose textarea and adds flex elements above so that the
height automatically adjust with the device height. This results in
making the compose box full screen sized.

The compose_height.js maintains the state of the height of the compose
box. Also, when the compose box is closed, the compose box is reset to
it's default behaviour and original height. So, everytime user need
not toggle off the compose full size and only for specific message
it is used.

It also adds destroy autosize on compose_height state change.
It destroys the autosize of textarea when the full
screen sized compose box is toggled on. And everytime when it is
turned off, it reinitialises the autosize. This also adds a
condition in autosize_textarea to only autosize when composebox
is not in full height state.

Fixes #17660
2021-07-07 16:47:30 -07:00
Priyam Seth 62d9f28211 compose_area: Fix compose_area pasted message bigger than max_length.
Fix a bug where the compose box cut the message without warning the user
the message pasted was longer than the allowed. It was fixed by stopping
cutting the message off and showing an indicator whenever the limit exceeds
and removing the indicator as soon as message gets less than that.

The cut off for showing the indicator is set as 90% of the limit.

Fixes #15909
Co-authored-by: João Maurício <carvalho.joaomauricio@gmail.com>
2021-07-07 12:18:18 -07:00
Priyansh Garg 3294e8dbe0 compose-box: Insert quoted content at the cursor position.
Right now, on clicking `quote and reply` on any message, the quoted
message is always inserted at the top of compose-box irrespective of
the current cursor position. Also, after insertion of the quoted
message, the cursor is shifted at the end of the compose box.

This commit changes this behaviour to insertion of quoted message
at the current cursor position with a newline at the end of quote
and moving the cursor position to that newline after insertion.
A newline is added at the beginning of quoted message only if there
was some content already present in compose box before the previous
cursor position.

Tested on Google Chrome and Firefox browsers on Ubuntu dev environment.

Fixes: #16836
2021-07-06 16:38:17 -07:00
Priyam Seth 57340a888c compose: Extract "compose_validate.js".
This commit first moves the compose.validate() function out
with the functions that are needed by it. Then one by one
checked for which function is now not needed in compose.js.

This moves all validation related functions out of "compose.js"
to "compose_validate.js".

Splitting compose announce variables out of compose.js.

This commit moves the "user_acknowledged_all_everyone" and
"user_acknowledged_announce" out of compose.js to reduce
cyclic dependency of compose_validate on compose.js.

Moving wildcard mentions to compose_validate.

The wildcard mention settings are mostly used while validating.
Also to reduce the cyclic dependence of compose in
compose_validate, the related wildcard mentions are moved out to
compose_vaidate.js.

This also converts reset_acknowledged functions to set values
by passing values.
2021-07-05 19:21:56 -07:00
Priyam Seth 985e95041d compose: Add trigger for new private message.
This commit adds a new trigger for compose.start that is
"new private message". It will clear the message recipients
whenever compose.start is called with this trigger.

This solves the bug, when a person is in a PM narrow and
clicks the new private message button, it opens the
composebox with the recipients filled out with whoever
you're narrowed to, rather than opening a new, blank PM.

CZO link for the issue
https://chat.zulip.org/#narrow/stream/9-issues/topic/.22New.20private.20message.22.20isn't/near/1222712
2021-07-05 11:56:46 -07:00
Priyansh Garg 6cfe10fef2 compose-box: Fix compose-box from covering last messages of stream.
While writing a long message in compose-box, the last few messages of
the current stream gets covered by the compose-box and it gets pretty
annoying sometimes trying to figure out a way to read the last message
of the stream while writing. Right now, the only way to get past this
is to resize `compose-textarea` by using the resize tool at the
bottom-right corner of the `compose-textarea`. But, that small resize
tool is not always readily visible to the user.

The proposed solution in this commit is to reset the `max-height`
property of `#compose-textarea` everytime `bottom_whitespace_height`
is resized such that the total height of `#compose` is always less
than or equal to the height of `bottom_whitespace_height`.  Doing
this, the compose-box never covers the last message of the current
stream.

The only problem with this is that if the compose-box is closed at the
time of bottom-whitespace resize, we cannot find the
`compose_non_textarea_height` and so, we cannot reset the max-height
of `#compose-textarea`. To solve this, max-height of
`compose-textarea` is also reset everytime a new compose-box is opened
according to the value of `bottom_whitespace_height` at that time.

Thus, if the compose-box is already open at the time of
bottom-whitespace resize, the max-height of `#compose-textarea` will
also get reset at the same time, whereas, if the compose-box is closed
at the time of bottom-whitespace resize, the max-height of
`#compose-textarea` won't get reset at that time, but it will surely
get reset whenever the user will open the compose-box.

Tested on my Ubuntu Development Environment on Chrome and Firefox browsers.

Fixes: #16038.
2021-06-29 11:24:01 -07:00
Aman Agrawal 88454307cd recent_topics: Split into three modules.
We split recent_topics module into recent_topics_(ui + data + util).

This allows us to reduce cyclical dependencies which were
created due to large list of imports in recent topics. Also, this
refactor on its own makes sense.
2021-06-10 15:53:05 -07:00
Tim Abbott b67b9912c4 drafts: Fix hook for saving drafts.
Previously, the hook to save drafts when closing the compose box was a
focusout on #compose-textarea. This mostly worked, and was essentially
invisible to users (because the animation to notify you about saved
drafts was in the close_compose_ui widget that is hidden), but you'd
end up seeing the tooltip appear (in the wrong place) if you closed
the compose box immediately after sending a message with Tab+Enter.

The correct fix is for the drafts hook to be just before we start
clearing compose box state, inside hide_box.

This was difficult to catch in a development environment, since one
doesn't use that flow with "Enter sends" enabled.
2021-05-12 12:53:58 -07:00
Aman Agrawal 0d8a7efa09 compose_closed_ui: Show default label for empty narrows.
The default label for empty narrows depends on whether it's a
stream/topic narrow or a PMs narrow.

We leave some default text in compose.hbs for reply label
because it take some time for the js to display the
correct label.
2021-05-11 23:57:57 -07:00
Aman Agrawal d8f554eb52 recent_topics: Set default text for reply btn when not focused in table.
When user is focused in search or filters, show "Compose Message"
as label which is more appropriate.
2021-05-11 23:51:00 -07:00
Aman Agrawal 51acbefc8a recent_topics: Display compose box & enable compose hotkeys.
We move compose from being a part of message feed to
being a part of  middle column which is a common parent of recent
topics and message feed. This allows us to use a common compose
box for both the views. Fortunately, compose actions were
independent of this change so there weren't any evident
side effects.

Fixes #17543
2021-05-07 16:07:51 -07:00
Tim Abbott 9dd88e845a compose_actions: Remove useless conditional.
get_focus_area can never return undefined.

Fixes an issue reported in #18273.
2021-04-27 23:13:40 -07:00
Anders Kaseorg 2004a85fb1 i18n: Automatically convert remaining JavaScript messages to FormatJS.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Wesley Aptekar-Cassels e0b1818780
compose: Don't escape usernames in quote-and-reply.
This fixes a bug that breaks quote-and-replying to users with characters
like apostrophes in their usernames.

The bug was introduced in def1e01512.
2021-04-08 13:51:17 -07:00
Signior-X 66d7e711b2 refractor: Replace manual autosize of textarea with compose_ui autosize.
This commit make compose_ui.autosize_textarea handle most of the autosize
logic of the textarea. It audits for any logic that is trying to do
autosize manually and replace it with compose_ui.autosize_textarea.
This allows to have better check for when the textarea is autosized.

Mainly done this so that we can have a check on #compose-textarea when
to autosize and when not to, thus helping to have all the logic in only
one function.
2021-03-31 07:49:47 -07:00
Anders Kaseorg d43ac7357a js: Move current_msg_list, home_msg_list to ES6 module message_lists.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-29 18:23:47 -07:00