瀏覽代碼

Use cached `media_urls` if available

JC Brand 4 月之前
父節點
當前提交
2eaea9ecc6
共有 2 個文件被更改,包括 4 次插入5 次删除
  1. 1 0
      src/headless/utils/url.js
  2. 3 5
      src/shared/texture/texture.js

+ 1 - 0
src/headless/utils/url.js

@@ -259,6 +259,7 @@ export function addMediaURLsOffset(arr, text, offset = 0) {
             return Object.assign({}, o, {
                 start,
                 end,
+                url: text.substring(o.start-offset, o.end-offset), // BBB
             });
         })
         .filter((o) => o);

+ 3 - 5
src/shared/texture/texture.js

@@ -170,11 +170,9 @@ export class Texture extends String {
      *  offset from the start of the original message stanza's body text).
      */
     async addHyperlinks(text, local_offset) {
-        const media_urls = addMediaURLsOffset(
-            getMediaURLsMetadata(text, local_offset).media_urls || [],
-            text,
-            local_offset
-        );
+        const full_offset = local_offset + this.offset;
+        const urls_meta = this.media_urls || getMediaURLsMetadata(text, local_offset).media_urls || [];
+        const media_urls = addMediaURLsOffset(urls_meta, text, full_offset);
         await Promise.all(
             media_urls
                 .filter((o) => !o.is_encrypted)