discourse/spec/requests/api/schemas/json
Martin Brennan d3f02a1270
FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937)
This commit fleshes out and adds functionality for the new `#hashtag` search and
lookup system, still hidden behind the `enable_experimental_hashtag_autocomplete`
feature flag.

**Serverside**

We have two plugin API registration methods that are used to define data sources
(`register_hashtag_data_source`) and hashtag result type priorities depending on
the context (`register_hashtag_type_in_context`). Reading the comments in plugin.rb
should make it clear what these are doing. Reading the `HashtagAutocompleteService`
in full will likely help a lot as well.

Each data source is responsible for providing its own **lookup** and **search**
method that returns hashtag results based on the arguments provided. For example,
the category hashtag data source has to take into account parent categories and
how they relate, and each data source has to define their own icon to use for the
hashtag, and so on.

The `Site` serializer has two new attributes that source data from `HashtagAutocompleteService`.
There is `hashtag_icons` that is just a simple array of all the different icons that
can be used for allowlisting in our markdown pipeline, and there is `hashtag_context_configurations`
that is used to store the type priority orders for each registered context.

When sending emails, we cannot render the SVG icons for hashtags, so
we need to change the HTML hashtags to the normal `#hashtag` text.

**Markdown**

The `hashtag-autocomplete.js` file is where I have added the new `hashtag-autocomplete`
markdown rule, and like all of our rules this is used to cook the raw text on both the clientside
and on the serverside using MiniRacer. Only on the server side do we actually reach out to
the database with the `hashtagLookup` function, on the clientside we just render a plainer
version of the hashtag HTML. Only in the composer preview do we do further lookups based
on this.

This rule is the first one (that I can find) that uses the `currentUser` based on a passed
in `user_id` for guardian checks in markdown rendering code. This is the `last_editor_id`
for both the post and chat message. In some cases we need to cook without a user present,
so the `Discourse.system_user` is used in this case.

**Chat Channels**

This also contains the changes required for chat so that chat channels can be used
as a data source for hashtag searches and lookups. This data source will only be
used when `enable_experimental_hashtag_autocomplete` is `true`, so we don't have
to worry about channel results suddenly turning up.

------

**Known Rough Edges**

- Onebox excerpts will not render the icon svg/use tags, I plan to address that in a follow up PR
- Selecting a hashtag + pressing the Quote button will result in weird behaviour, I plan to address that in a follow up PR
- Mixed hashtag contexts for hashtags without a type suffix will not work correctly, e.g. #ux which is both a category and a channel slug will resolve to a category when used inside a post or within a [chat] transcript in that post. Users can get around this manually by adding the correct suffix, for example ::channel. We may get to this at some point in future
- Icons will not show for the hashtags in emails since SVG support is so terrible in email (this is not likely to be resolved, but still noting for posterity)
- Additional refinements and review fixes wil
2022-11-21 08:37:06 +10:00
..
admin_user_list_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
admin_user_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
backups_create_request.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
backups_list_response.json api docs example (#11997) 2021-02-08 10:09:44 -07:00
badge_create_request.json DEV: Document some of the badge api endpoints (#13919) 2021-08-03 06:25:12 -06:00
badge_create_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
badge_list_response.json DEV: Fix flaky admin badges.json api docs spec (#17210) 2022-06-23 14:32:17 -06:00
badge_update_request.json DEV: Document some of the badge api endpoints (#13919) 2021-08-03 06:25:12 -06:00
badge_update_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
category_create_request.json DEV: Document some more parms for the cat create api docs (#19024) 2022-11-14 16:15:42 -07:00
category_create_response.json FEATURE: Add dark mode option for category logos (#18460) 2022-10-07 11:00:44 -04:00
category_list_response.json FEATURE: Add dark mode option for category logos (#18460) 2022-10-07 11:00:44 -04:00
category_topics_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
category_update_response.json FEATURE: Add dark mode option for category logos (#18460) 2022-10-07 11:00:44 -04:00
group_add_members_request.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
group_add_members_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
group_create_request.json DEV: Document create group api params (#18736) 2022-10-24 18:55:51 -06:00
group_create_response.json DEV: Tidy up create group api endpoint docs (#17586) 2022-07-20 19:18:48 -06:00
group_members_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
group_remove_members_request.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
group_remove_members_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
group_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
groups_list_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
post_delete_request.json DEV: Document delete post API endpoint (#15495) 2022-01-07 16:09:32 -07:00
post_replies_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
search_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
site_response.json FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937) 2022-11-21 08:37:06 +10:00
success_ok_response.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
tag_group_create_request.json
tag_group_create_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
topic_create_request.json DEV: Document external topic id endpoints (#15897) 2022-02-10 19:01:19 -07:00
topic_create_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
topic_show_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
upload_abort_multipart_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_batch_presign_multipart_parts_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_batch_presign_multipart_parts_response.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_complete_external_upload_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_complete_multipart_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_create_multipart_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_create_multipart_response.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_create_request.json DEV: More API Doc improvements (#11849) 2021-01-26 07:38:46 -07:00
upload_create_response.json UX: Use dominant color as image loading placeholder (#18248) 2022-09-20 10:28:17 +01:00
upload_generate_presigned_put_request.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
upload_generate_presigned_put_response.json DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
user_actions_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
user_anonymize_response.json DEV: Document anonymize user api endpoint (#13893) 2021-07-29 17:40:41 -06:00
user_badges_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
user_create_request.json DEV: Add description for active param on create user api docs (#18753) 2022-10-25 18:24:54 -06:00
user_create_response.json DEV: Refactor the api docs for the user endpoint (#14377) 2021-09-20 10:04:57 -06:00
user_delete_request.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
user_delete_response.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
user_emails_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00
user_get_response.json FEATURE: Add button to reset seen popups (#18586) 2022-10-20 09:06:39 +08:00
user_password_change_request.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
user_password_reset_request.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
user_password_reset_response.json document api endpoints (#11958) 2021-02-03 17:12:35 -07:00
user_refresh_gravatar_response.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
user_silence_request.json FIX: Show suspended by user (#16927) 2022-06-01 14:54:23 +02:00
user_silence_response.json FIX: Show suspended by user (#16927) 2022-06-01 14:54:23 +02:00
user_suspend_request.json DEV: Document the user suspend api endpoint (#12179) 2021-02-23 05:58:22 -07:00
user_suspend_response.json FIX: Show suspended by user (#16927) 2022-06-01 14:54:23 +02:00
user_update_avatar_request.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
user_update_email_request.json document user endpoints (#11894) 2021-01-29 11:27:11 -07:00
user_update_request.json FEATURE: API to create user's associated account (#15737) 2022-03-03 18:17:02 +02:00
user_update_response.json FEATURE: API to create user's associated account (#15737) 2022-03-03 18:17:02 +02:00
user_update_username_request.json DEV: Update api docs to update username and to get post replies (#15881) 2022-02-09 15:04:36 -07:00
users_public_list_response.json repair structural problems with the openapi spec (#16710) 2022-06-20 10:56:56 -06:00