Forráskód Böngészése

Fix chats filter in events

painor 3 éve
szülő
commit
95e7d4dfc9

+ 1 - 1
gramjs/Utils.ts

@@ -1188,7 +1188,7 @@ export function getMessageId(message: any): number | undefined {
 export function parsePhone(phone: string) {
     phone = phone.toString().replace(/[()\s-]/gm, "");
     if (phone.startsWith("+") && phone.split("+").length - 1 == 1) {
-        return !isNaN(Number(phone)) ? phone : undefined;
+        return !isNaN(Number(phone)) ? phone.replace("+","") : undefined;
     }
 }
 

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.0.4";
+export const version = "2.0.6";

+ 0 - 1
gramjs/events/Album.ts

@@ -23,7 +23,6 @@ const _ALBUM_DELAY = 500; // 0.5 sec
  * ```
  */
 export class Album extends EventBuilder {
-    chats?: EntityLike[];
     func?: { (event: Album): boolean };
 
     constructor(albumParams: DefaultEventInterface) {

+ 2 - 2
gramjs/events/CallbackQuery.ts

@@ -71,10 +71,10 @@ export class CallbackQuery extends EventBuilder {
 
         if (this.chats) {
             let inside = this.chats.includes(
-                event.query.chatInstance as unknown as EntityLike
+                event.query.chatInstance.toString()
             );
             if (event.chatId) {
-                inside = inside || this.chats.includes(event.chatId);
+                inside = inside || this.chats.includes(event.chatId.toString());
             }
 
             if (inside === this.blacklistChats) {

+ 0 - 1
gramjs/events/NewMessage.ts

@@ -67,7 +67,6 @@ export interface NewMessageInterface extends DefaultEventInterface {
  * ```
  */
 export class NewMessage extends EventBuilder {
-    chats?: EntityLike[];
     func?: { (event: NewMessageEvent): boolean };
     incoming?: boolean;
     outgoing?: boolean;

+ 3 - 3
gramjs/events/common.ts

@@ -95,14 +95,14 @@ export interface DefaultEventInterface {
  * All events inherit this.
  */
 export class EventBuilder {
-    chats?: EntityLike[];
+    chats?: string[];
     blacklistChats: boolean;
     resolved: boolean;
     func?: CallableFunction;
     client?: TelegramClient;
 
     constructor(eventParams: DefaultEventInterface) {
-        this.chats = eventParams.chats;
+        this.chats = eventParams.chats?.map((x)=>x.toString());
         this.blacklistChats = eventParams.blacklistChats || false;
         this.resolved = false;
         this.func = eventParams.func;
@@ -138,7 +138,7 @@ export class EventBuilder {
             if (event.chatId == undefined) {
                 return;
             }
-            const inside = this.chats.includes(event.chatId);
+            const inside = this.chats.includes(event.chatId.toString());
             if (inside == this.blacklistChats) {
                 // If this chat matches but it's a blacklist ignore.
                 // If it doesn't match but it's a whitelist ignore.

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

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