Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] improve autolinker flow #15340

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/autolinker/client/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import s from 'underscore.string';
import Autolinker from 'autolinker';

Expand Down Expand Up @@ -41,11 +42,13 @@ const createAutolinker = () => {
});
};

const renderMessage = (message) => {
if (settings.get('AutoLinker') !== true) {
return message;
}
let autolinker;

Tracker.autorun(() => {
autolinker = createAutolinker();
});

const renderMessage = (message) => {
if (!s.trim(message.html)) {
return message;
}
Expand All @@ -58,7 +61,7 @@ const renderMessage = (message) => {
} else {
msgParts = [message.html];
}
const autolinker = createAutolinker();

message.html = msgParts
.map((msgPart) => {
if (regexTokens && regexTokens.test(msgPart)) {
Expand All @@ -72,4 +75,9 @@ const renderMessage = (message) => {
return message;
};

callbacks.add('renderMessage', renderMessage, callbacks.priority.LOW, 'autolinker');
Tracker.autorun(function() {
if (settings.get('AutoLinker') !== true) {
return callbacks.remove('renderMessage', 'autolinker');
}
callbacks.add('renderMessage', renderMessage, callbacks.priority.LOW, 'autolinker');
});