Ver Fonte

Fix iterParticipants

painor há 3 anos atrás
pai
commit
0e3a534e82
5 ficheiros alterados com 22 adições e 20 exclusões
  1. 1 1
      gramjs/Version.ts
  2. 9 10
      gramjs/client/chats.ts
  3. 9 6
      gramjs/network/MTProtoState.ts
  4. 2 2
      package-lock.json
  5. 1 1
      package.json

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.0.8";
+export const version = "2.0.9";

+ 9 - 10
gramjs/client/chats.ts

@@ -220,17 +220,17 @@ export class _ParticipantsIter extends RequestIter {
                     return false;
                 }
 
-                const users = new Map();
+                const users = new Map<string, Entity>();
                 for (const user of full.users) {
-                    users.set(user.id, user);
+                    users.set(user.id.toString(), user);
                 }
                 for (const participant of full.fullChat.participants
                     .participants) {
-                    const user = users.get(participant.userId);
+                    const user = users.get(participant.userId.toString())!;
                     if (!this.filterEntity(user)) {
                         continue;
                     }
-                    user.participant = participant;
+                    (user as any).participant = participant;
                     this.buffer?.push(user);
                 }
                 return true;
@@ -240,8 +240,7 @@ export class _ParticipantsIter extends RequestIter {
             if (this.limit != 0) {
                 const user = await this.client.getEntity(entity);
                 if (this.filterEntity(user)) {
-                    // @ts-ignore
-                    user.participant = null;
+                    (user as any).participant = undefined;
                     this.buffer?.push(user);
                 }
             }
@@ -277,19 +276,19 @@ export class _ParticipantsIter extends RequestIter {
             }
 
             this.requests[i].offset += participants.participants.length;
-            const users = new Map();
+            const users = new Map<string, Entity>();
             for (const user of participants.users) {
-                users.set(user.id, user);
+                users.set(user.id.toString(), user);
             }
             for (const participant of participants.participants) {
                 if (!("userId" in participant)) {
                     continue;
                 }
-                const user = users.get(participant.userId);
+                const user = users.get(participant.userId.toString())!;
                 if (this.filterEntity && !this.filterEntity(user)) {
                     continue;
                 }
-                user.participant = participant;
+                (user as any).participant = participant;
                 this.buffer?.push(user);
             }
         }

+ 9 - 6
gramjs/network/MTProtoState.ts

@@ -17,7 +17,7 @@ export class MTProtoState {
     private id: bigInt.BigInteger;
     _sequence: number;
     private _lastMsgId: bigInt.BigInteger;
-    private msgIds: Set<String>;
+    private msgIds: string[];
 
     /**
      *
@@ -51,7 +51,7 @@ export class MTProtoState {
         this.salt = bigInt.zero;
         this._sequence = 0;
         this.id = this._lastMsgId = bigInt.zero;
-        this.msgIds = new Set();
+        this.msgIds = [];
         this.reset();
     }
 
@@ -63,7 +63,7 @@ export class MTProtoState {
         this.id = helpers.generateRandomLong(true);
         this._sequence = 0;
         this._lastMsgId = bigInt.zero;
-        this.msgIds = new Set<String>();
+        this.msgIds = [];
     }
 
     /**
@@ -228,15 +228,18 @@ export class MTProtoState {
         const reader = new BinaryReader(body);
         reader.readLong(); // removeSalt
         const serverId = reader.readLong();
-        if (serverId !== this.id) {
+        if (serverId.neq(this.id)) {
             // throw new SecurityError('Server replied with a wrong session ID');
         }
 
         const remoteMsgId = reader.readLong();
-        if (this.msgIds.has(remoteMsgId.toString())) {
+        if (this.msgIds.includes(remoteMsgId.toString())) {
             throw new SecurityError("Duplicate msgIds");
         }
-        this.msgIds.add(remoteMsgId.toString());
+        if (this.msgIds.length > 500) {
+            this.msgIds.shift();
+        }
+        this.msgIds.push(remoteMsgId.toString());
         const remoteSequence = reader.readInt();
         reader.readInt(); // msgLen for the inner object, padding ignored
 

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

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