Added tests and documentation
This commit is contained in:
parent
94af11d7e3
commit
f88960c561
@ -907,6 +907,13 @@ and an idle presence according to XEP-0319 is sent.
|
||||
|
||||
If the given value is negative or ``0``, this feature is disabled.
|
||||
|
||||
image_urls_regex
|
||||
----------------
|
||||
|
||||
Any URLs in a message that matches the regex in this setting will be considered an image and displayed inline.
|
||||
|
||||
E.g. ``/^https?:\/\/(?:www.)?(?:imgur\.com\/\w{7})\/?$/i``
|
||||
|
||||
jid
|
||||
---
|
||||
|
||||
|
@ -979,6 +979,13 @@ describe("A Chat Message", function () {
|
||||
expect(view.content.querySelectorAll('img').length).toBe(4);
|
||||
mock.sendMessage(view, message);
|
||||
expect(view.content.querySelectorAll('img').length).toBe(4);
|
||||
|
||||
// Configured image URLs are rendered
|
||||
_converse.api.settings.set('image_urls_regex', /^https?:\/\/(?:www.)?(?:imgur\.com\/\w{7})\/?$/i);
|
||||
message = 'http://imgur.com/xxxxxxx';
|
||||
mock.sendMessage(view, message);
|
||||
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-image').length === 5, 1000);
|
||||
expect(view.content.querySelectorAll('img').length).toBe(5);
|
||||
done();
|
||||
}));
|
||||
|
||||
|
@ -52,6 +52,7 @@ converse.plugins.add('converse-chatview', {
|
||||
api.settings.extend({
|
||||
'auto_focus': true,
|
||||
'debounced_content_rendering': true,
|
||||
'image_urls_regex': null,
|
||||
'message_limit': 0,
|
||||
'muc_hats_from_vcard': false,
|
||||
'show_images_inline': true,
|
||||
@ -67,7 +68,6 @@ converse.plugins.add('converse-chatview', {
|
||||
'emoji': true,
|
||||
'spoiler': true
|
||||
},
|
||||
'image_urls_regex': null
|
||||
});
|
||||
|
||||
|
||||
|
@ -120,7 +120,7 @@ function addHyperlinks (text, onImgLoad, onImgClick) {
|
||||
text.addTemplateResult(
|
||||
url_obj.start,
|
||||
url_obj.end,
|
||||
show_images && (u.isImageURL(url_text) || u.isWhitelistedImageURL(url_text)) ?
|
||||
show_images && u.isImageURL(url_text) ?
|
||||
u.convertToImageTag(url_text, onImgLoad, onImgClick) :
|
||||
u.convertUrlToHyperlink(url_text),
|
||||
);
|
||||
|
@ -76,10 +76,11 @@ function checkFileTypes (types, url) {
|
||||
|
||||
u.isAudioURL = url => checkFileTypes(['.ogg', '.mp3', '.m4a'], url);
|
||||
u.isVideoURL = url => checkFileTypes(['.mp4', '.webm'], url);
|
||||
u.isImageURL = url => checkFileTypes(['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.svg'], url);
|
||||
u.isWhitelistedImageURL = url => {
|
||||
const regex = _converse.api.settings.get('image_urls_regex');
|
||||
return regex ? regex.test(url) : false;
|
||||
u.isImageURL = url => {
|
||||
const regex = api.settings.get('image_urls_regex');
|
||||
return regex
|
||||
? regex.test(url)
|
||||
: checkFileTypes(['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.svg'], url);
|
||||
}
|
||||
|
||||
function getFileName (uri) {
|
||||
|
Loading…
Reference in New Issue
Block a user