Bläddra i källkod

Fix empty input entities in RAW Api.

painor 3 år sedan
förälder
incheckning
ba812f999b
5 ändrade filer med 17 tillägg och 35 borttagningar
  1. 7 2
      gramjs/Utils.ts
  2. 1 1
      gramjs/Version.ts
  3. 6 29
      gramjs/sessions/Memory.ts
  4. 2 2
      package-lock.json
  5. 1 1
      package.json

+ 7 - 2
gramjs/Utils.ts

@@ -231,7 +231,6 @@ export function getInputChannel(entity: EntityLike) {
     if (entity.SUBCLASS_OF_ID === undefined) {
     if (entity.SUBCLASS_OF_ID === undefined) {
         _raiseCastFail(entity, "InputChannel");
         _raiseCastFail(entity, "InputChannel");
     }
     }
-
     if (entity.SUBCLASS_OF_ID === 0x40f202fd) {
     if (entity.SUBCLASS_OF_ID === 0x40f202fd) {
         // crc32(b'InputChannel')
         // crc32(b'InputChannel')
         return entity;
         return entity;
@@ -313,7 +312,13 @@ export function getInputUser(entity: EntityLike): Api.TypeInputUser {
             accessHash: entity.accessHash,
             accessHash: entity.accessHash,
         });
         });
     }
     }
-
+    if (entity instanceof Api.InputPeerUserFromMessage) {
+        return new Api.InputUserFromMessage({
+            userId: entity.userId,
+            peer: entity.peer,
+            msgId: entity.msgId,
+        });
+    }
     _raiseCastFail(entity, "InputUser");
     _raiseCastFail(entity, "InputUser");
 }
 }
 
 

+ 1 - 1
gramjs/Version.ts

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

+ 6 - 29
gramjs/sessions/Memory.ts

@@ -235,37 +235,14 @@ export class MemorySession extends Session {
             !bigInt.isInstance(key) &&
             !bigInt.isInstance(key) &&
             key.SUBCLASS_OF_ID
             key.SUBCLASS_OF_ID
         ) {
         ) {
-            if (key.SUBCLASS_OF_ID == 0xc91c90b6) {
+            if (
+                key.SUBCLASS_OF_ID == 0xc91c90b6 ||
+                key.SUBCLASS_OF_ID == 0xe669bf46 ||
+                key.SUBCLASS_OF_ID == 0x40f202fd
+            ) {
+                // @ts-ignore
                 return key;
                 return key;
             }
             }
-            if (key.SUBCLASS_OF_ID == 0xe669bf46) {
-                if (key instanceof Api.InputUserSelf) {
-                    return new Api.InputPeerSelf();
-                }
-                if (key instanceof Api.InputUserEmpty) {
-                    return new Api.InputPeerEmpty();
-                }
-                if (key instanceof Api.InputUserFromMessage) {
-                    return key.peer;
-                }
-                return new Api.InputPeerUser({
-                    userId: key.userId,
-                    accessHash: key.accessHash,
-                });
-            }
-            if (key.SUBCLASS_OF_ID == 0x40f202fd) {
-                if (key instanceof Api.InputChannelEmpty) {
-                    return new Api.InputPeerEmpty();
-                }
-                if (key instanceof Api.InputChannelFromMessage) {
-                    return key.peer;
-                }
-                return new Api.InputPeerChannel({
-                    channelId: key.channelId,
-                    accessHash: key.accessHash,
-                });
-            }
-
             // Try to early return if this key can be casted as input peer
             // Try to early return if this key can be casted as input peer
             return utils.getInputPeer(key);
             return utils.getInputPeer(key);
         } else {
         } else {

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

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