Commit Graph

69 Commits

Author SHA1 Message Date
Riken Shah 6c003a7802 refactor: Move emoji details related code to `emoji.js`.
As `reaction.js` and `user_status.js` has similar code to
get emoji details, it makes more sense to extract this as a
single function.
2021-07-28 09:35:00 -07:00
Wesley Aptekar-Cassels f08555bb31 shared: Bump version to 0.0.6. 2021-06-15 14:40:58 -07:00
Steve Howell 50362a8c39 poll widget: Check types for inbound events. 2021-06-14 17:46:16 -07:00
Steve Howell 99cdfbcbe5 widgets: Clean up index handling.
We only need to bump up indexes if inbound
events suggest that we have incremented our
personal index from another device.

We don't want somebody else's runaway index
to affect our index.

(For both widgets the sender_id is part of
the key, so uniqueness across all senders is
not required for the integer part.)
2021-06-14 17:46:16 -07:00
Steve Howell 91b8049ecf minor: Add permission-related comments to widgets. 2021-06-14 17:46:16 -07:00
Steve Howell 5f73164210 poll widget: Prevent question updates from non-authors.
We now ignore question edits if the sender of the submessage
is not the message author.

The webapp UI prevents folks from editing the question for
somebody else's poll, but a determined person could use our
low level API to do it.  We will add safeguards on the server
side for this, but this change is sufficient to protect the
webapp (and mobile when they upgrade the library).
2021-06-14 17:46:16 -07:00
Anders Kaseorg e015f3ed7d docs: Correct “webapp” to “web app”.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-14 13:15:38 -07:00
Anders Kaseorg 544bbd5398 docs: Fix capitalization mistakes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-10 09:57:26 -07:00
Wesley Aptekar-Cassels 6639342892 shared: Add link to mobile @zulip/shared docs in README. 2021-05-09 19:12:09 -07:00
Anders Kaseorg fc9481a24e js: Remove some pointless IIFEs.
Some of these were there because they predate block-scoped const/let.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-06 14:38:57 -07:00
Anders Kaseorg 802c8de0e8 fenced_code: Wrap math blocks in the frontend like the backend.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-05-01 15:36:15 -07:00
Wesley Aptekar-Cassels 367cf897fa shared: Bump version to 0.0.5. 2021-04-20 17:19:12 +08:00
Wesley Aptekar-Cassels da0c616b69 shared: Move PollData into shared. 2021-04-19 06:34:08 -04:00
aryanshridhar f19c7a2f69 emoticon_translation: Update comment for precise object length. 2021-04-01 16:52:32 -07:00
Anders Kaseorg 7656d44abc js: Simplify code using default parameters and destructuring.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 09:21:46 -07:00
Ganesh Pawar 947ce2b79d minor: Check if typeahead query exists.
When a user entered an invalid character (whitespace or characters not
present in a name), the cleaned-up array, and hence the query,
would be empty which resulted in an error.

Fixes #17542
2021-03-25 02:08:51 -07:00
Wesley Aptekar-Cassels 673af19a4d typeahead: Always rank exact string match first.
Previously, exact matches could be pushed off the typeahead list in the
case where there were more prefix matches that happened to rank first,
which is confusing to the user: if an emoji, for instance, falls into
this category, it will never show up in typeahead, which is easy to
confuse with the emoji not existing.

This isn't a perfect fix — there are still cases where it's hard to find
emojis because the prefix-space is very crowded, but it does fix a
category of surprising and frustrating behaviour.

This doesn't come completely without downside - it means that the exact
match emoji will jump to the front of the list, which changes what is
currently conceptually a "filtering" operation to a "filtering and
sorting" operation, but it seems on the whole to be a more ideal
experience. This is particularly notable in the non-typeahead emoji
picker, which uses the same codepath, but this change seems somewhat
desirable even there, since it allows the user to type the name of an
emoji and press enter and have that emoji show up, without having to
visually confirm that they aren't inadvertently selecting a
prefix-matching emoji.

A better solution to this in the long term might be ordering emoji
results by shortest-first as a tiebreaker for alphabetical ordering,
since that should provide the same behaviour while keeping the mental
model as "filtering" (since the sort order won't change as the user
types), but this seems like a reasonable first pass, and changing to
shortest-first ordering after making this change won't break any muscle
memory for existing users.
2021-02-25 17:55:54 -08:00
Anders Kaseorg 57f2b8760a shared: Format our one Flow file with Prettier.
Why not.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-14 07:03:32 -05:00
Anders Kaseorg 1e7347349c eslint: Fix unicorn/no-array-push-push.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Anders Kaseorg 6cd694b8e3 eslint: Fix unicorn/no-array-callback-reference.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Greg Price c7d329544b shared: Bump version to 0.0.4. 2020-12-30 15:02:13 -08:00
Greg Price 0de1d03dd4 typing_status: Mark recipient array as allowing number subtypes.
Concretely, we'll use this with a `UserId` type which is an
"opaque type alias" of `number` -- it's secretly implemented as
simply `number`, and it can be consumed by anything that wants a
`number` (in other words, it's a subtype of `number`), but the
fact that it secretly just is `number` is private to the module
that defines the type.

As far as the typing_status code is concerned, allowing this to
be a subtype of `number` just means that the code doesn't ever
try to inject new numbers of its own into the recipients arrays
that it passes around.
2020-12-30 14:55:24 -08:00
Greg Price 9a15301f4a typing_status: Mark recipient array as read-only for Flow.
This type means that code consuming this value promises not to
mutate it.  It's useful partly for the sake of simply controlling
mutation, so that arrays can be passed around without making
defensive copies; and partly because it makes the type covariant
in the elements, rather than invariant.

That is, if a function takes a plain Array<number | null>, then you
can't pass it an Array<number>, because it might add a `null` to it.
But if it takes $ReadOnlyArray<number | null>, then you can.
In general, Array<S> <: $ReadOnlyArray<S> <: $ReadOnlyArray<T>
for any S <: T, where `<:` means "is a subtype of".

Marking this type as read-only means we can pass in a read-only
array without adding a fixme (equivalent to a mypy type-ignore) to
locally disable the type-checker, nor a redundant defensive copy.
2020-12-30 14:55:24 -08:00
Anders Kaseorg 26f630dfa1 fenced_code: Escape code_language on output in wrapped_code.
Strings should be escaped at the point of interpolation into a
template, not before.  In this case, the early escape was hiding the
bug that code_language was only escaped if it was not found in
pygments_data.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-11-02 16:23:48 -08:00
akshatdalton 620e9cbf72 markdown: Fix merging of separate quotations.
Initally, when writing two or more quotes, having
a blank line in between them, merges those quotes.
This created confusion especially in "quote and reply".

This commit fixes such issues. Now two or more quotes
having a blank line in between them, will not get merged.

This change is correct both for usability and for improving our
compatibility with CommonMark.

Fixes #14379.
2020-10-30 15:21:15 -07:00
Anders Kaseorg 72d6ff3c3b docs: Fix more capitalization issues.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-23 11:46:55 -07:00
Anders Kaseorg d81a93cdf3 requirements: Upgrade markdown to 3.3.1.
Upstream has slightly changed the whitespace around stashes.  Take
this opportunity to clean up the extra blank lines we were outputting.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-19 11:54:14 -07:00
Anders Kaseorg 8098acb63c eslint: Fix unicorn/prefer-trim-start-end.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-trim-start-end.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Anders Kaseorg d654992164 eslint: Fix unicorn/prefer-optional-catch-binding.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-optional-catch-binding.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Sumanth V Rao ca7f84ac58 markdown: bugfix: Fix importing pygments data for codeblock header creation.
In c563cdba61 we imported the generated
pygments data from outside `/shared` folder. This had a couple of
problems:
    * Using `require` was the wrong way to do the import in ES6 modules.
    * Since we get the data from outside `/shared`, clients like
      zulip-mobile would not receive it - this case had to be handeled.

Here, we fix the above problems by receiving the data when initializing
through fenced_code.initialize, and when the pygments data structure is
empty (for zulip-mobile) we fallback to the old header structure without
the data-code-language tag.

Also, this commit does a small refactor to improve the way we fetch
canonicalized_alias from pygments_data.

Tests amended.
2020-09-28 15:39:31 -07:00
Anders Kaseorg d72423ef21 eslint: Replace empty-returns with consistent-return.
Instead of prohibiting ‘return undefined’ (#8669), we require that a
function must return an explicit value always or never.  This prevents
you from forgetting to return a value in some cases.  It will also be
important for TypeScript, which distinguishes between undefined and
void.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-09-25 15:17:59 -07:00
Sumanth V Rao c563cdba61 markdown: Add data-code-lang attribute for locally echoed messages.
This mimics the backend logic for adding the data-attribute -
to know what Pygments language was used to highlight the code
block - in locally echoed messages.

New test added checks our logic for canonicalizing pygments alias
(for both frontend and backend).

Other fixtures and tests amended.
2020-09-18 17:12:26 -07:00
Greg Price 6a1fcea5ad shared: Bump version to 0.0.3. 2020-08-26 22:34:06 -07:00
Anders Kaseorg 768f9f93cd docs: Capitalize Markdown consistently.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-08-11 10:23:06 -07:00
Anders Kaseorg f63d132276 js: Use unminified KaTeX (and minifiy it with everything else).
Since our Webpack config passes pre-minified JS files to
script-loader, they can’t be used as modules.  Use the normal
unminified version, letting Webpack minify it and give us source maps.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-08-07 11:27:44 -07:00
Anders Kaseorg 8e79e0e63b emoji: Replace escape_regexp with _.escapeRegExp.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-29 16:51:24 -07:00
Anders Kaseorg d2520cd7e0 js: Replace underscore with lodash and remove it from globals.
Tweaked by tabbott to bump PROVISION_VERSION.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 16:12:06 -07:00
Steve Howell 0eb206f97e mobile sharing: Make emoji.js a shared ES6 module.
This is a pretty straightforward conversion.

The bulk of the diff is just changing emoji.js
to ES6 syntax.

There is one little todo that can be deferred
to the next commit--we are now set up to have
markdown.js require emoji.js directly, since
it is no longer on `window`.
2020-07-26 16:07:17 -07:00
Anders Kaseorg 7727dae441 shared: Add missing katex dependency to shared package.json.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-25 12:22:25 -07:00
Anders Kaseorg f0c4cc9e46 js: Fix new import/order errors.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-24 13:04:07 -07:00
Steve Howell cc31403112 mobile sharing: Move fenced_code.js to shared/js.
We also take fenced_code out of the global namespace,
since it only requires katex and underscore.

And we fix the exports to be ES6 style.
2020-07-24 12:57:52 -07:00
Gittenburg 45e19dd6b9 emoji: Rename :slight_smile: to 😄.
Zulip converts :) to the 1F642 Unicode emoji and promotes the same emoji
in the popular section of the emoji picker.

Previously Zulip has labeled 1F642 as "slight smile". While that name
conforms to the Unicode standard (which describes the code point as
SLIGHTLY SMILING FACE), it didn't match our use case of the emoji.

If a user types :) or selects the first smile in the emoji picker they
probably mean to express a regular "smile" and not a "slight smile",
which raises the question why they are only smiling slightly.

This commit relabels 1F642 as 😄 and our previous 😄 263A as
:smiling_face:. Note that 263A looks different in our three supported
emoji sets, so it is not suited to be our "default smile".

This change does not require a migration since our emoji system stores
both unicode points and names and handles name changes transparently.
2020-07-21 16:49:54 -07:00
Anders Kaseorg b65d2e063d js: Reformat with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg f3726db89a js: Normalize strings to double quotes.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg e014ea966a eslint: Enable comma-dangle for functions.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg b0253c5a2e eslint: Enable arrow-parens.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:53:39 -07:00
Anders Kaseorg b019d7ffe8 typeahead: Convert to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-19 14:36:42 -08:00
Anders Kaseorg 59d55d1e06 js: Use modern spread arguments syntax.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-11 17:43:35 -08:00
Anders Kaseorg 70ff164f89 js: Convert _.any(a, …), _.some(a, …) to a.some(…).
And convert the corresponding function expressions to arrow style
while we’re here.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg ef50346a29 js: Convert _.reject(a, … => …) to a.filter(… => !…).
And convert the corresponding function expressions to arrow style
while we’re here.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00