linkifiers: Update API to send data using dictionaries.

* This introduces a new event type `realm_linkifiers` and
a new key for the initial data fetch of the same name.
Newer clients will be expected to use these.

* Backwards compatibility is ensured by changing neither
the current event nor the /register key. The data which
these hold is the same as before, but internally, it is
generated by processing the `realm_linkifiers` data.
We send both the old and the new event types to clients
whenever the linkifiers are changed.
Older clients will simply ignore the new event type, and
vice versa.

* The `realm/filters:GET` endpoint (which returns tuples)
is currently used by none of the official Zulip clients.
This commit replaces it with `realm/linkifiers:GET` which
returns data in the new dictionary format.
TODO: Update the `get_realm_filters` method in the API
bindings, to hit this new URL instead of the old one.

* This also updates the webapp frontend to use the newer
events and keys.
This commit is contained in:
Abhijeet Prasad Bodas
2021-03-30 16:21:54 +05:30
committed by Tim Abbott
parent 5eff43f5d9
commit 3947b0c80a
21 changed files with 297 additions and 90 deletions

View File

@@ -89,7 +89,7 @@ export function contains_backend_only_syntax(content) {
// then don't render it locally. It is workaround for the fact that
// javascript regex doesn't support lookbehind.
const false_linkifier_match = linkifier_list.find((re) => {
const pattern = /[^\s"'(,:<]/.source + re[0].source + /(?!\w)/.source;
const pattern = /[^\s"'(,:<]/.source + re.pattern.source + /(?!\w)/.source;
const regex = new RegExp(pattern);
return regex.test(content);
});
@@ -225,8 +225,8 @@ export function add_topic_links(message) {
const links = [];
for (const linkifier of linkifier_list) {
const pattern = linkifier[0];
const url = linkifier[1];
const pattern = linkifier.pattern;
const url = linkifier.url_format;
let match;
while ((match = pattern.exec(topic)) !== null) {
let link_url = url;
@@ -451,15 +451,18 @@ export function update_linkifier_rules(linkifiers) {
const marked_rules = [];
for (const [pattern, url] of linkifiers) {
const [regex, final_url] = python_to_js_linkifier(pattern, url);
for (const linkifier of linkifiers) {
const [regex, final_url] = python_to_js_linkifier(linkifier.pattern, linkifier.url_format);
if (!regex) {
// Skip any linkifiers that could not be converted
continue;
}
linkifier_map.set(regex, final_url);
linkifier_list.push([regex, final_url]);
linkifier_list.push({
pattern: regex,
url_format: final_url,
});
marked_rules.push(regex);
}