Преглед на файлове

Restrict unfurl description to `message_limit` setting

JC Brand преди 4 години
родител
ревизия
1bd4572957
променени са 2 файла, в които са добавени 7 реда и са изтрити 1 реда
  1. 6 1
      src/headless/shared/parsers.js
  2. 1 0
      webpack.html

+ 6 - 1
src/headless/shared/parsers.js

@@ -127,10 +127,15 @@ export function getOpenGraphMetadata (stanza) {
         const applies_to_id = fastening.getAttribute('id');
         const meta = sizzle(`> meta[xmlns="${Strophe.NS.XHTML}"]`, fastening);
         if (meta.length) {
+            const msg_limit = api.settings.get('message_limit');
             const data = meta.reduce((acc, el) => {
                 const property = el.getAttribute('property');
                 if (property) {
-                    acc[property] = decodeHTMLEntities(el.getAttribute('content') || '');
+                    let value = decodeHTMLEntities(el.getAttribute('content') || '');
+                    if (msg_limit && property === 'og:description' && value.length >= msg_limit) {
+                        value = `${value.slice(0, msg_limit)}${decodeHTMLEntities('…')}`;
+                    }
+                    acc[property] = value;
                 }
                 return acc;
             }, {

+ 1 - 0
webpack.html

@@ -26,6 +26,7 @@
         auto_away: 300,
         auto_register_muc_nickname: true,
         loglevel: 'debug',
+        message_limit: 300,
         modtools_disable_assign: ['owner', 'moderator', 'participant', 'visitor'],
         modtools_disable_query: ['moderator', 'participant', 'visitor'],
         enable_smacks: true,