Closes https://github.com/flarum/core/issues/3070
If the user doesn't have permission to search users, there will currently be browser errors, as the current implementation will still attempt to search and autocomplete. In this PR, we check for permission before searching. The dropdown will still support autocomplete of users currently participating in the discussion.
* Add Prettier
* Update dependencies; add typescript setup
* Add tsconfig
* Rewrite some mentions frontend into TS
* Fix use of username instead of display name
* Change back to JS
* Remove commented code
* Update function name to match filename
* Update getMentionText.js
* Simplify condition
* Bump packages to stable versions; use prettier package
* Make functions use camel case
* Update js/package.json
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
* Don't access data directly
* Update js/src/forum/addComposerAutocomplete.js
Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
* Update tsconfig.json
Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
* Convert user mentions to new `@"Display Name"#ID` format
* Handle deleted user's mentions
* Convert post mentions to `@"Display Name"#pID` format
* Handle deleted user's post mentions and deleted posts mentions
* Clean display name of `"#{letters}{numbers}` (replace with underscore _)
* Adapt integration tests to new mention formats
* Use a deleted attribute for user mentions
* Introduce cleanDisplayName util
* Detect new format with autocomplete
* Slug needed on rendering only
* Invalidate user mention tag when ID is invalid
This used to be implicitly done, when there was a username attribute configured, formatter would check that all attributes are available and if not invalidate.
since we now only have `displayname` and `id` attributes which are both available from the regex matching, formatter doesn't implicitly invalidate anymore and therefore validates ANY matches. So we explicitly invalidate the tag when the ID does not match a user.
* Allow username mention format with a setting
* Add tests for turning setting on/off
* Move setting check to tag filter
Because the configurator caches, changing the setting only takes effect after the cache is cleared.
* fix: showing autocomplete at the right moment
* Add dockblocks to explain unparsing process
The previous solution didn't properly account for document scroll, so when replying to posts, the parent offset would be extremely large, and it'd fall back to the top coordinate, which is out of bounds on small screens.
Update for Mithril 2
- Please note that PostQuoteButton and AutocompleteDropdown are not Fragments, not Components. Accordingly, they have been moved to the components folder.
Co-authored-by: Matthew Kilgore <tankerkiller125@gmail.com>
Co-authored-by: Franz Liedke <franz@develophp.org>
Cache the order in which users are returned by the API to stop the mentions list from jumping around
Only ping the api when 2 or more characters are entered
Since we don't return an "unread count" in the API, this pluralization
logic is useless at the moment. Related to #643 and #716 but really
needs further thought in #868.
Previously, the positioning logic did not account for the case
when the textarea was already scrolled down a bit, thus often
rendering the dropdown off-screen.
Fixesflarum/core#1021.
See https://github.com/flarum/core/pull/1367
* Replace gulp with webpack and npm scripts for JS compilation
* Set up Travis CI to commit compiled JS
* Restructure `js` directory; only one instance of npm, forum/admin are "submodules"
* Restructure `less` directory
This also improves the behaviour of mentions in the JS preview (no more
broken links, mention is only picked up if corresponding user/post is
found).
See flarum/core#1246Closesflarum/core#315