Ver Fonte

Update attributes to accept list for send album

Painor há 1 ano atrás
pai
commit
8579962aaf

+ 11 - 11
__tests__/extensions/MarkdownV2.spec.ts

@@ -50,17 +50,17 @@ describe("MarkdownV2Parser", () => {
       );
     });
 
-    test("it should parse custom emoji", () =>{
-        const [text, entities] = MarkdownV2Parser.parse(
-            "![👍](tg://emoji?id=5368324170671202286)"
-        );
-        expect(text).toEqual("👍");
-        expect(entities.length).toEqual(1);
-        expect(entities[0]).toBeInstanceOf(types.MessageEntityCustomEmoji);
-        expect((entities[0] as types.MessageEntityCustomEmoji).documentId).toEqual(
-            "5368324170671202286"
-        );
-    } )
+    test("it should parse custom emoji", () => {
+      const [text, entities] = MarkdownV2Parser.parse(
+        "![👍](tg://emoji?id=5368324170671202286)"
+      );
+      expect(text).toEqual("👍");
+      expect(entities.length).toEqual(1);
+      expect(entities[0]).toBeInstanceOf(types.MessageEntityCustomEmoji);
+      expect(
+        (entities[0] as types.MessageEntityCustomEmoji).documentId
+      ).toEqual("5368324170671202286");
+    });
 
     test("it should parse multiple entities", () => {
       const [text, entities] = MarkdownV2Parser.parse("-Hello- *world*");

+ 1 - 2
gramjs/Utils.ts

@@ -1120,7 +1120,6 @@ export function sanitizeParseMode(
     throw new Error(`Invalid parse mode type ${mode}`);
 }
 
-
 /**
  Convert the given peer into its marked ID by default.
 
@@ -1362,4 +1361,4 @@ export function  isListLike(item) {
         )
     )
 }
-*/
+*/

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.18.33";
+export const version = "2.18.37";

+ 2 - 1
gramjs/client/dialogs.ts

@@ -183,7 +183,8 @@ export class _DialogsIter extends RequestIter {
         this.request.excludePinned = true;
         this.request.offsetId = lastMessage ? lastMessage.id : 0;
         this.request.offsetDate = lastMessage ? lastMessage.date! : 0;
-        this.request.offsetPeer = this.buffer[this.buffer.length - 1]?.inputEntity;
+        this.request.offsetPeer =
+            this.buffer[this.buffer.length - 1]?.inputEntity;
     }
 }
 

+ 3 - 5
gramjs/client/updates.ts

@@ -218,16 +218,14 @@ export async function _updateLoop(client: TelegramClient) {
                     PING_FAIL_INTERVAL
                 );
             } else {
-                let wakeUpWarningTimeout: Timeout | undefined | number = setTimeout(
-                    () => {
+                let wakeUpWarningTimeout: Timeout | undefined | number =
+                    setTimeout(() => {
                         _handleUpdate(
                             client,
                             UpdateConnectionState.disconnected
                         );
                         wakeUpWarningTimeout = undefined;
-                    },
-                    PING_WAKE_UP_WARNING_TIMEOUT
-                );
+                    }, PING_WAKE_UP_WARNING_TIMEOUT);
 
                 await timeout(ping, PING_WAKE_UP_TIMEOUT);
 

+ 11 - 2
gramjs/client/uploads.ts

@@ -249,7 +249,7 @@ export interface SendFileInterface {
     /** Same as `replyTo` from {@link sendMessage}. */
     replyTo?: MessageIDLike;
     /** Optional attributes that override the inferred ones, like {@link Api.DocumentAttributeFilename} and so on.*/
-    attributes?: Api.TypeDocumentAttribute[];
+    attributes?: Api.TypeDocumentAttribute[] | Api.TypeDocumentAttribute[][];
     /** Optional JPEG thumbnail (for documents). Telegram will ignore this parameter unless you pass a .jpg file!<br/>
      * The file must also be small in dimensions and in disk size. Successful thumbnails were files below 20kB and 320x320px.<br/>
      *  Width/height and dimensions/size ratios may be important.
@@ -545,6 +545,11 @@ export async function _sendAlbum(
     } else {
         replyTo = utils.getMessageId(replyTo);
     }
+    if (!attributes) {
+        attributes = [];
+    }
+
+    let index = 0;
     const albumFiles = [];
     for (const file of files) {
         let { fileHandle, media, image } = await _fileToMedia(client, {
@@ -552,13 +557,15 @@ export async function _sendAlbum(
             forceDocument: forceDocument,
             fileSize: fileSize,
             progressCallback: progressCallback,
-            attributes: attributes,
+            // @ts-ignore
+            attributes: attributes[index],
             thumb: thumb,
             voiceNote: voiceNote,
             videoNote: videoNote,
             supportsStreaming: supportsStreaming,
             workers: workers,
         });
+        index++;
         if (
             media instanceof Api.InputMediaUploadedPhoto ||
             media instanceof Api.InputMediaPhotoExternal
@@ -667,6 +674,7 @@ export async function sendFile(
             caption: caption,
             replyTo: replyTo,
             parseMode: parseMode,
+            attributes: attributes,
             silent: silent,
             scheduleDate: scheduleDate,
             supportsStreaming: supportsStreaming,
@@ -695,6 +703,7 @@ export async function sendFile(
         forceDocument: forceDocument,
         fileSize: fileSize,
         progressCallback: progressCallback,
+        // @ts-ignore
         attributes: attributes,
         thumb: thumb,
         voiceNote: voiceNote,

+ 4 - 3
gramjs/extensions/html.ts

@@ -226,9 +226,10 @@ export class HTMLParser {
                     `<a href="tg://user?id=${entity.userId}">${entityText}</a>`
                 );
             } else if (entity instanceof Api.MessageEntityCustomEmoji) {
-                html.push(`<tg-emoji emoji-id="${entity.documentId}">${entityText}</tg-emoji>`);
-            }
-            else {
+                html.push(
+                    `<tg-emoji emoji-id="${entity.documentId}">${entityText}</tg-emoji>`
+                );
+            } else {
                 skipEntity = true;
             }
             lastOffset = relativeOffset + (skipEntity ? 0 : length);

+ 34 - 25
gramjs/extensions/markdownv2.ts

@@ -4,67 +4,76 @@ import { HTMLParser } from "./html";
 export class MarkdownV2Parser {
     static parse(message: string): [string, Api.TypeMessageEntity[]] {
         // Bold
-        message = message.replace(/\*(.*?)\*/g, '<b>$1</b>');
+        message = message.replace(/\*(.*?)\*/g, "<b>$1</b>");
 
         // underline
-        message = message.replace(/__(.*?)__/g, '<u>$1</u>');
+        message = message.replace(/__(.*?)__/g, "<u>$1</u>");
 
         // strikethrough
-        message = message.replace(/~(.*?)~/g, '<s>$1</s>');
+        message = message.replace(/~(.*?)~/g, "<s>$1</s>");
 
         // italic
-        message = message.replace(/-(.*?)-/g, '<i>$1</i>');
-        
+        message = message.replace(/-(.*?)-/g, "<i>$1</i>");
+
         // pre
-        message = message.replace(/```(.*?)```/g, '<pre>$1</pre>');
-        
+        message = message.replace(/```(.*?)```/g, "<pre>$1</pre>");
+
         // code
-        message = message.replace(/`(.*?)`/g, '<code>$1</code>');
+        message = message.replace(/`(.*?)`/g, "<code>$1</code>");
 
-        // Spoiler 
-        message = message.replace(/\|\|(.*?)\|\|/g, '<spoiler>$1</spoiler>');
+        // Spoiler
+        message = message.replace(/\|\|(.*?)\|\|/g, "<spoiler>$1</spoiler>");
 
         // Inline URL
-        message = message.replace(/(?<!\!)\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
+        message = message.replace(
+            /(?<!\!)\[([^\]]+)\]\(([^)]+)\)/g,
+            '<a href="$2">$1</a>'
+        );
 
-        // Emoji 
-        message = message.replace(/!\[([^\]]+)\]\(tg:\/\/emoji\?id=(\d+)\)/g, '<tg-emoji emoji-id="$2">$1</tg-emoji>');
-        return HTMLParser.parse(message)
+        // Emoji
+        message = message.replace(
+            /!\[([^\]]+)\]\(tg:\/\/emoji\?id=(\d+)\)/g,
+            '<tg-emoji emoji-id="$2">$1</tg-emoji>'
+        );
+        return HTMLParser.parse(message);
     }
 
     static unparse(
         text: string,
         entities: Api.TypeMessageEntity[] | undefined
     ) {
-        text = HTMLParser.unparse(text, entities)
+        text = HTMLParser.unparse(text, entities);
 
         // Bold
-        text = text.replace(/<b>(.*?)<\/b>/g, '*$1*');
+        text = text.replace(/<b>(.*?)<\/b>/g, "*$1*");
 
         // Underline
-        text = text.replace(/<u>(.*?)<\/u>/g, '__$1__');
+        text = text.replace(/<u>(.*?)<\/u>/g, "__$1__");
 
         // Code
-        text = text.replace(/<code>(.*?)<\/code>/g, '`$1`');
+        text = text.replace(/<code>(.*?)<\/code>/g, "`$1`");
 
         // Pre
-        text = text.replace(/<pre>(.*?)<\/pre>/g, '```$1```');
+        text = text.replace(/<pre>(.*?)<\/pre>/g, "```$1```");
 
         // strikethrough
-        text = text.replace(/<s>(.*?)<\/s>/g, '~$1~');
+        text = text.replace(/<s>(.*?)<\/s>/g, "~$1~");
 
         // Italic
-        text = text.replace(/<i>(.*?)<\/i>/g, '-$1-');
+        text = text.replace(/<i>(.*?)<\/i>/g, "-$1-");
 
         // Spoiler
-        text = text.replace(/<spoiler>(.*?)<\/spoiler>/g, '||$1||');
+        text = text.replace(/<spoiler>(.*?)<\/spoiler>/g, "||$1||");
 
         // Inline URL
-        text = text.replace(/<a href="([^"]+)">([^<]+)<\/a>/g, '[$2]($1)');
+        text = text.replace(/<a href="([^"]+)">([^<]+)<\/a>/g, "[$2]($1)");
 
         // Emoji
-        text = text.replace(/<tg-emoji emoji-id="(\d+)">([^<]+)<\/tg-emoji>/g, '![$2](tg://emoji?id=$1)');
+        text = text.replace(
+            /<tg-emoji emoji-id="(\d+)">([^<]+)<\/tg-emoji>/g,
+            "![$2](tg://emoji?id=$1)"
+        );
 
-        return text
+        return text;
     }
 }

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "telegram",
-  "version": "2.18.34",
+  "version": "2.18.38",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "telegram",
-      "version": "2.18.34",
+      "version": "2.18.38",
       "license": "MIT",
       "dependencies": {
         "@cryptography/aes": "^0.1.1",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "2.18.34",
+  "version": "2.18.38",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",