fix: Fix agent name in Twitter channel private note acting as a link (#4326)
This commit is contained in:
parent
eff3a50316
commit
3cd1616df6
4 changed files with 42 additions and 7 deletions
|
@ -207,7 +207,11 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
this.formatMessage(this.data.content, this.isATweet) + botMessageContent
|
this.formatMessage(
|
||||||
|
this.data.content,
|
||||||
|
this.isATweet,
|
||||||
|
this.data.private
|
||||||
|
) + botMessageContent
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
contentAttributes() {
|
contentAttributes() {
|
||||||
|
|
|
@ -13,8 +13,9 @@ const TWITTER_HASH_REPLACEMENT =
|
||||||
const USER_MENTIONS_REGEX = /mention:\/\/(user|team)\/(\d+)\/(.+)/gm;
|
const USER_MENTIONS_REGEX = /mention:\/\/(user|team)\/(\d+)\/(.+)/gm;
|
||||||
|
|
||||||
class MessageFormatter {
|
class MessageFormatter {
|
||||||
constructor(message, isATweet = false) {
|
constructor(message, isATweet = false, isAPrivateNote = false) {
|
||||||
this.message = DOMPurify.sanitize(escapeHtml(message || ''));
|
this.message = DOMPurify.sanitize(escapeHtml(message || ''));
|
||||||
|
this.isAPrivateNote = isAPrivateNote;
|
||||||
this.isATweet = isATweet;
|
this.isATweet = isATweet;
|
||||||
this.marked = marked;
|
this.marked = marked;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class MessageFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
formatMessage() {
|
formatMessage() {
|
||||||
if (this.isATweet) {
|
if (this.isATweet && !this.isAPrivateNote) {
|
||||||
const withUserName = this.message.replace(
|
const withUserName = this.message.replace(
|
||||||
TWITTER_USERNAME_REGEX,
|
TWITTER_USERNAME_REGEX,
|
||||||
TWITTER_USERNAME_REPLACEMENT
|
TWITTER_USERNAME_REPLACEMENT
|
||||||
|
|
|
@ -36,19 +36,45 @@ describe('#MessageFormatter', () => {
|
||||||
it('should add links to @mentions', () => {
|
it('should add links to @mentions', () => {
|
||||||
const message =
|
const message =
|
||||||
'@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername';
|
'@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername';
|
||||||
expect(new MessageFormatter(message, true).formattedMessage).toMatch(
|
expect(
|
||||||
|
new MessageFormatter(message, true, false).formattedMessage
|
||||||
|
).toMatch(
|
||||||
'<p><a href="http://twitter.com/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">@chatwootapp</a> is an opensource tool thanks @longnonexistenttwitterusername</p>'
|
'<p><a href="http://twitter.com/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">@chatwootapp</a> is an opensource tool thanks @longnonexistenttwitterusername</p>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add links to #tags', () => {
|
it('should add links to #tags', () => {
|
||||||
const message = '#chatwootapp is an opensource tool';
|
const message = '#chatwootapp is an opensource tool';
|
||||||
expect(new MessageFormatter(message, true).formattedMessage).toMatch(
|
expect(
|
||||||
|
new MessageFormatter(message, true, false).formattedMessage
|
||||||
|
).toMatch(
|
||||||
'<p><a href="https://twitter.com/hashtag/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">#chatwootapp</a> is an opensource tool</p>'
|
'<p><a href="https://twitter.com/hashtag/chatwootapp" target="_blank" rel="noreferrer nofollow noopener">#chatwootapp</a> is an opensource tool</p>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('private notes', () => {
|
||||||
|
it('should return the same string if not tags or @mentions', () => {
|
||||||
|
const message = 'Chatwoot is an opensource tool';
|
||||||
|
expect(new MessageFormatter(message).formattedMessage).toMatch(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add links to @mentions', () => {
|
||||||
|
const message =
|
||||||
|
'@chatwootapp is an opensource tool thanks @longnonexistenttwitterusername';
|
||||||
|
expect(
|
||||||
|
new MessageFormatter(message, false, true).formattedMessage
|
||||||
|
).toMatch(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add links to #tags', () => {
|
||||||
|
const message = '#chatwootapp is an opensource tool';
|
||||||
|
expect(
|
||||||
|
new MessageFormatter(message, false, true).formattedMessage
|
||||||
|
).toMatch(message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('plain text content', () => {
|
describe('plain text content', () => {
|
||||||
it('returns the plain text without HTML', () => {
|
it('returns the plain text without HTML', () => {
|
||||||
const message =
|
const message =
|
||||||
|
|
|
@ -3,8 +3,12 @@ import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
formatMessage(message, isATweet) {
|
formatMessage(message, isATweet, isAPrivateNote) {
|
||||||
const messageFormatter = new MessageFormatter(message, isATweet);
|
const messageFormatter = new MessageFormatter(
|
||||||
|
message,
|
||||||
|
isATweet,
|
||||||
|
isAPrivateNote
|
||||||
|
);
|
||||||
return messageFormatter.formattedMessage;
|
return messageFormatter.formattedMessage;
|
||||||
},
|
},
|
||||||
getPlainText(message, isATweet) {
|
getPlainText(message, isATweet) {
|
||||||
|
|
Loading…
Reference in a new issue