瀏覽代碼

GramJS: Comment out unused things

painor 5 年之前
父節點
當前提交
c18d7d4c60

+ 10 - 4
src/lib/gramjs/Helpers.js

@@ -143,7 +143,8 @@ function generateRandomBytes(count) {
  * @param client
  * @returns {{iv: Buffer, key: Buffer}}
  */
-
+/*CONTEST
+this is mtproto 1 (mostly used for secret chats)
 async function calcKey(sharedKey, msgKey, client) {
     const x = client === true ? 0 : 8
     const [sha1a, sha1b, sha1c, sha1d] = await Promise.all([
@@ -160,6 +161,8 @@ async function calcKey(sharedKey, msgKey, client) {
     }
 }
 
+ */
+
 /**
  * Generates the key data corresponding to the given nonces
  * @param serverNonce
@@ -266,6 +269,9 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
  * @param obj
  * @returns {boolean}
  */
+/*
+CONTEST
+we do'nt support array requests anyway
 function isArrayLike(obj) {
     if (!obj) return false
     const l = obj.length
@@ -279,7 +285,7 @@ function isArrayLike(obj) {
     }
     return true
 }
-
+*/
 // Taken from https://stackoverflow.com/questions/18638900/javascript-crc32/18639999#18639999
 function makeCRCTable() {
     let c
@@ -319,7 +325,7 @@ module.exports = {
     mod,
     crc32,
     generateRandomBytes,
-    calcKey,
+    //calcKey,
     generateKeyDataFromNonce,
     sha1,
     sha256,
@@ -328,6 +334,6 @@ module.exports = {
     getRandomInt,
     sleep,
     getByteArray,
-    isArrayLike,
+    //isArrayLike,
     toSignedLittleBuffer
 }

+ 5 - 2
src/lib/gramjs/Password.js

@@ -11,6 +11,8 @@ const SIZE_FOR_HASH = 256
  * @param prime{BigInteger}
  * @param g{BigInteger}
  */
+/*
+We don't support changing passwords yet
 function checkPrimeAndGoodCheck(prime, g) {
     console.error('Unsupported function `checkPrimeAndGoodCheck` call. Arguments:', prime, g)
 
@@ -53,7 +55,7 @@ function checkPrimeAndGoodCheck(prime, g) {
         throw new Error('(prime - 1) // 2 is not prime')
     }
 }
-
+*/
 /**
  *
  * @param primeBytes{Buffer}
@@ -83,7 +85,8 @@ function checkPrimeAndGood(primeBytes, g) {
             return // It's good
         }
     }
-    checkPrimeAndGoodCheck(readBigIntFromBuffer(primeBytes, false), g)
+    throw new Error("Changing passwords unsupported")
+    //checkPrimeAndGoodCheck(readBigIntFromBuffer(primeBytes, false), g)
 }
 
 /**

+ 39 - 21
src/lib/gramjs/Utils.js

@@ -125,6 +125,7 @@ function getInputPeer(entity, allowSelf = true, checkHash = true) {
  * @param entity
  * @returns {InputChannel|*}
  */
+/*CONTEST
 function getInputChannel(entity) {
     if (entity.SUBCLASS_OF_ID === undefined) {
         _raiseCastFail(entity, 'InputChannel')
@@ -149,7 +150,7 @@ function getInputChannel(entity) {
     }
     _raiseCastFail(entity, 'InputChannel')
 }
-
+*/
 /**
  Similar to :meth:`get_input_peer`, but for :tl:`InputUser`'s alone.
 
@@ -161,6 +162,7 @@ function getInputChannel(entity) {
 
  * @param entity
  */
+/*CONTEST
 function getInputUser(entity) {
     if (entity.SUBCLASS_OF_ID === undefined) {
         _raiseCastFail(entity, 'InputUser')
@@ -199,11 +201,12 @@ function getInputUser(entity) {
 
     _raiseCastFail(entity, 'InputUser')
 }
-
+*/
 /**
  Similar to :meth:`get_input_peer`, but for dialogs
  * @param dialog
  */
+/*CONTEST
 function getInputDialog(dialog) {
     try {
         if (dialog.SUBCLASS_OF_ID === 0xa21c9795) { // crc32(b'InputDialogPeer')
@@ -224,6 +227,8 @@ function getInputDialog(dialog) {
     }
     _raiseCastFail(dialog, 'InputDialogPeer')
 }
+*/
+/*CONTEST
 
 function getInputMessage(message) {
     try {
@@ -242,7 +247,7 @@ function getInputMessage(message) {
 
     _raiseCastFail(message, 'InputMessage')
 }
-
+*/
 
 /**
  * Adds the JPG header and footer to a stripped image.
@@ -262,7 +267,7 @@ function strippedPhotoToJpg(stripped) {
     return Buffer.concat([header, stripped.slice(3), JPEG_FOOTER])
 }
 
-
+/*CONTEST
 function getInputLocation(location) {
     try {
         if (!location.SUBCLASS_OF_ID) {
@@ -314,7 +319,7 @@ function getInputLocation(location) {
     }
     _raiseCastFail(location, 'InputFileLocation')
 }
-
+*/
 
 /**
  * Gets the appropriated part size when uploading or downloading files,
@@ -336,7 +341,7 @@ function getAppropriatedPartSize(fileSize) {
     throw new Error('File size too large')
 }
 
-
+/*CONTEST
 function getPeer(peer) {
     try {
         if (typeof peer === 'number') {
@@ -381,7 +386,7 @@ function getPeer(peer) {
     }
     _raiseCastFail(peer, 'peer')
 }
-
+*/
 
 /**
  Convert the given peer into its marked ID by default.
@@ -399,6 +404,7 @@ function getPeer(peer) {
  * @param peer
  * @param addMark
  */
+/*CONTEST
 function getPeerId(peer, addMark = true) {
     // First we assert it's a Peer TLObject, or early return for integers
     if (typeof peer == 'number') {
@@ -441,11 +447,12 @@ function getPeerId(peer, addMark = true) {
         }
     }
 }
-
+*/
 /**
  * Given a marked ID, returns the original ID and its :tl:`Peer` type.
  * @param markedId
  */
+/*CONTEST
 function resolveId(markedId) {
     if (markedId >= 0) {
         return [markedId, constructors.PeerUser]
@@ -462,6 +469,7 @@ function resolveId(markedId) {
     }
     return [-markedId, constructors.PeerChat]
 }
+*/
 
 /**
  * returns an entity pair
@@ -472,6 +480,8 @@ function resolveId(markedId) {
  * @returns {{inputEntity: *, entity: *}}
  * @private
  */
+/*CONTEST
+
 function _getEntityPair(entityId, entities, cache, getInputPeer = getInputPeer) {
     const entity = entities.get(entityId)
     let inputEntity = cache[entityId]
@@ -487,6 +497,7 @@ function _getEntityPair(entityId, entities, cache, getInputPeer = getInputPeer)
         inputEntity
     }
 }
+*/
 
 function getMessageId(message) {
     if (message === null || message === undefined) {
@@ -501,6 +512,7 @@ function getMessageId(message) {
     throw new Error(`Invalid message type: ${message.constructor.name}`)
 }
 
+
 /**
  * Parses the given phone, or returns `None` if it's invalid.
  * @param phone
@@ -527,6 +539,8 @@ function parsePhone(phone) {
 
  * @param username {string}
  */
+/*CONTEST
+
 function parseUsername(username) {
     username = username.trim()
     const m = username.match(USERNAME_RE) || username.match(TG_JOIN_RE)
@@ -561,6 +575,8 @@ function rtrim(s, mask) {
     return s
 }
 
+ */
+
 /**
  * Gets the display name for the given :tl:`User`,
  :tl:`Chat` or :tl:`Channel`. Returns an empty string otherwise
@@ -588,6 +604,8 @@ function getDisplayName(entity) {
  * @param item
  * @returns {boolean}
  */
+/*CONTEST
+Duplicate ?
 function isListLike(item) {
     return (
         Array.isArray(item) ||
@@ -601,7 +619,7 @@ function isListLike(item) {
         )
     )
 }
-
+*/
 function getDC(dcId, cdn = false) {
     switch (dcId) {
         case 1:
@@ -657,21 +675,21 @@ function getDC(dcId, cdn = false) {
 
 module.exports = {
     getMessageId,
-    _getEntityPair,
-    getInputMessage,
-    getInputDialog,
-    getInputUser,
-    getInputChannel,
+    //_getEntityPair,
+    //getInputMessage,
+    //getInputDialog,
+    //getInputUser,
+    //getInputChannel,
     getInputPeer,
-    parsePhone,
-    parseUsername,
-    getPeer,
-    getPeerId,
+    //parsePhone,
+    //parseUsername,
+    //getPeer,
+    //getPeerId,
     getDisplayName,
-    resolveId,
-    isListLike,
+    //resolveId,
+    //isListLike,
     getAppropriatedPartSize,
-    getInputLocation,
+    //getInputLocation,
     strippedPhotoToJpg,
     getDC
 }

+ 25 - 11
src/lib/gramjs/client/TelegramClient.js

@@ -319,6 +319,7 @@ class TelegramClient {
      * @returns {Promise<Buffer>}
      */
     async downloadFile(inputLocation, args = {}) {
+
         let { partSizeKb, fileSize } = args
         const { dcId } = args
 
@@ -337,9 +338,8 @@ class TelegramClient {
         if (partSize % MIN_CHUNK_SIZE !== 0) {
             throw new Error('The part size must be evenly divisible by 4096')
         }
-
         const fileWriter = new BinaryWriter(Buffer.alloc(0))
-        const res = utils.getInputLocation(inputLocation)
+
         let exported = dcId && this.session.dcId !== dcId
 
         let sender
@@ -367,8 +367,13 @@ class TelegramClient {
             while (true) {
                 let result
                 try {
+<<<<<<< HEAD
                     result = await sender.send(new requests.upload.GetFileRequest({
                         location: res.inputLocation,
+=======
+                    result = await sender.send(new requests.upload.GetFile({
+                        location: inputLocation,
+>>>>>>> 3f7f5bfa... GramJS: Comment out unused things
                         offset: offset,
                         limit: partSize,
                     }))
@@ -482,6 +487,7 @@ class TelegramClient {
             }
             photo = entity.photo
         }
+
         let dcId
         let loc
         if (photo instanceof constructors.UserProfilePhoto || photo instanceof constructors.ChatPhoto) {
@@ -489,7 +495,7 @@ class TelegramClient {
             dcId = photo.dcId
             const size = isBig ? photo.photoBig : photo.photoSmall
             loc = new constructors.InputPeerPhotoFileLocation({
-                peer: await this.getInputEntity(entity),
+                peer: utils.getInputPeer(entity),
                 localId: size.localId,
                 volumeId: size.volumeId,
                 big: isBig,
@@ -511,7 +517,9 @@ class TelegramClient {
             })
             return result
         } catch (e) {
-            if (e.message === 'LOCATION_INVALID') {
+            // TODO this should never raise
+            throw e;
+            /*if (e.message === 'LOCATION_INVALID') {
                 const ie = await this.getInputEntity(entity)
                 if (ie instanceof constructors.InputPeerChannel) {
                     const full = await this.invoke(new requests.channels.GetFullChannelRequest({
@@ -527,7 +535,7 @@ class TelegramClient {
                 }
             } else {
                 throw e
-            }
+            }*/
         }
 
 
@@ -706,7 +714,7 @@ class TelegramClient {
         if (request.classType !== 'request') {
             throw new Error('You can only invoke MTProtoRequests')
         }
-        await request.resolve(this, utils)
+        //await request.resolve(this, utils)
 
         if (request.CONSTRUCTOR_ID in this._floodWaitedRequests) {
             const due = this._floodWaitedRequests[request.CONSTRUCTOR_ID]
@@ -730,7 +738,7 @@ class TelegramClient {
             try {
                 const promise = this._sender.send(request)
                 const result = await promise
-                this.session.processEntities(result)
+                //this.session.processEntities(result)
                 this._entityCache.add(result)
                 return result
             } catch (e) {
@@ -1073,14 +1081,14 @@ class TelegramClient {
             this._dispatchUpdate({ update: new UpdateConnectionState(update) })
             return
         }
-        this.session.processEntities(update)
+        //this.session.processEntities(update)
         this._entityCache.add(update)
 
         if (update instanceof constructors.Updates || update instanceof constructors.UpdatesCombined) {
             // TODO deal with entities
-            const entities = {}
+            const entities = []
             for (const x of [...update.users, ...update.chats]) {
-                entities[utils.getPeerId(x)] = x
+                entities.push(x)
             }
             for (const u of update.updates) {
                 this._processUpdate(u, update.updates, entities)
@@ -1122,6 +1130,7 @@ class TelegramClient {
      * @returns {Promise<void>}
      * @private
      */
+    /*CONTEST
     async _getEntityFromString(string) {
         const phone = utils.parsePhone(string)
         if (phone) {
@@ -1187,7 +1196,7 @@ class TelegramClient {
         }
         throw new Error(`Cannot find any entity corresponding to "${string}"`)
     }
-
+    */
     // endregion
 
 
@@ -1256,6 +1265,7 @@ class TelegramClient {
      * @param peer
      * @returns {Promise<>}
      */
+    /*CONTEST
     async getInputEntity(peer) {
         // Short-circuit if the input parameter directly maps to an InputPeer
         try {
@@ -1335,11 +1345,15 @@ class TelegramClient {
             ' find out more details.',
         )
     }
+<<<<<<< HEAD
 
 
     // endregion
 
 
+=======
+    */
+>>>>>>> 3f7f5bfa... GramJS: Comment out unused things
     async _dispatchUpdate(args = {
         update: null,
         others: null,

+ 2 - 0
src/lib/gramjs/events/NewMessage.js

@@ -1,3 +1,4 @@
+/*CONTEST
 const { EventBuilder, EventCommon } = require('./common')
 const { constructors } = require('../tl')
 
@@ -90,3 +91,4 @@ class Event extends EventCommon {
 }
 
 module.exports = NewMessage
+*/

+ 6 - 6
src/lib/gramjs/extensions/PromisedWebSockets.js

@@ -7,10 +7,13 @@ const closeError = new Error('WebSocket was closed')
 
 class PromisedWebSockets {
     constructor() {
+        /*CONTEST
         this.isBrowser = typeof process === 'undefined' ||
             process.type === 'renderer' ||
             process.browser === true ||
             process.__nwjs
+
+         */
         this.client = null
         this.closed = true
     }
@@ -89,7 +92,8 @@ class PromisedWebSockets {
                     this.resolveRead(false)
                     this.closed = true
             }
-            if (this.isBrowser && typeof window !== 'undefined'){
+            //CONTEST
+            if (typeof window !== 'undefined'){
                 window.addEventListener('offline', async () => {
                     await this.close()
                     this.resolveRead(false)
@@ -116,12 +120,8 @@ class PromisedWebSockets {
             const release = await mutex.acquire()
             try {
                 let data
-                if (this.isBrowser) {
+                //CONTEST BROWSER
                     data = Buffer.from(await new Response(message.data).arrayBuffer())
-                } else {
-                    data = Buffer.from(message.data)
-                }
-
                 this.stream = Buffer.concat([this.stream, data])
                 this.resolveRead(true)
             } finally {

+ 6 - 2
src/lib/gramjs/network/MTProtoSender.js

@@ -215,14 +215,18 @@ class MTProtoSender {
         if (!this._user_connected) {
             throw new Error('Cannot send requests while disconnected')
         }
-
+        //CONTEST
+        const state = new RequestState(request)
+        this._send_queue.append(state)
+        return state.promise
+        /*
         if (!Helpers.isArrayLike(request)) {
             const state = new RequestState(request)
             this._send_queue.append(state)
             return state.promise
         } else {
             throw new Error('not supported')
-        }
+        }*/
     }
 
     /**

+ 175 - 0
src/lib/gramjs/sessions/Abstract.js

@@ -0,0 +1,175 @@
+class Session {
+    constructor() {
+
+    }
+
+    /**
+     * Creates a clone of this session file
+     * @param toInstance {Session|null}
+     * @returns {Session}
+     */
+    /* CONTEST
+    clone(toInstance = null) {
+        return toInstance || new this.constructor()
+    }*/
+
+    /**
+     * Sets the information of the data center address and port that
+     * the library should connect to, as well as the data center ID,
+     * which is currently unused.
+     * @param dcId {number}
+     * @param serverAddress {string}
+     * @param port {number}
+     */
+    setDC(dcId, serverAddress, port) {
+        throw new Error('Not implemented')
+    }
+
+    /**
+     * Returns the currently-used data center ID.
+     */
+    get dcId() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Returns the server address where the library should connect to.
+     */
+    get serverAddress() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Returns the port to which the library should connect to.
+     */
+    get port() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Returns an ``AuthKey`` instance associated with the saved
+     * data center, or `None` if a new one should be generated.
+     */
+    get authKey() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Sets the ``AuthKey`` to be used for the saved data center.
+     * @param value
+     */
+    set authKey(value) {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Returns an ID of the takeout process initialized for this session,
+     * or `None` if there's no were any unfinished takeout requests.
+     */
+    /*CONTEST
+    get takeoutId() {
+        throw new Error('Not Implemented')
+    }
+    */
+    /**
+     * Sets the ID of the unfinished takeout process for this session.
+     * @param value
+     */
+    /*CONTEST
+    set takeoutId(value) {
+        throw new Error('Not Implemented')
+    }
+    */
+    /**
+     * Returns the ``UpdateState`` associated with the given `entity_id`.
+     * If the `entity_id` is 0, it should return the ``UpdateState`` for
+     * no specific channel (the "general" state). If no state is known
+     * it should ``return None``.
+     * @param entityId
+     */
+    /*CONTEST
+    getUpdateState(entityId) {
+        throw new Error('Not Implemented')
+    }
+
+     */
+
+    /**
+     * Sets the given ``UpdateState`` for the specified `entity_id`, which
+     * should be 0 if the ``UpdateState`` is the "general" state (and not
+     * for any specific channel).
+     * @param entityId
+     * @param state
+     */
+    /*CONTEST
+    setUpdateState(entityId, state) {
+        throw new Error('Not Implemented')
+    }
+
+     */
+
+    /**
+     * Called on client disconnection. Should be used to
+     * free any used resources. Can be left empty if none.
+     */
+    /*CONTEST
+    close() {
+
+    }
+
+     */
+
+    /**
+     * called whenever important properties change. It should
+     * make persist the relevant session information to disk.
+     */
+    save() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Called upon client.log_out(). Should delete the stored
+     * information from disk since it's not valid anymore.
+     */
+
+    delete() {
+        throw new Error('Not Implemented')
+    }
+
+    /**
+     * Lists available sessions. Not used by the library itself.
+     */
+    /*CONTEST
+    listSessions() {
+        throw new Error('Not Implemented')
+    }
+
+     */
+
+    /**
+     * Processes the input ``TLObject`` or ``list`` and saves
+     * whatever information is relevant (e.g., ID or access hash).
+     * @param tlo
+     */
+    /*CONTEST
+    processEntities(tlo) {
+        throw new Error('Not Implemented')
+    }
+
+     */
+
+    /**
+     * Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
+     * The library uses this method whenever an ``InputPeer`` is needed
+     * to suit several purposes (e.g. user only provided its ID or wishes
+     * to use a cached username to avoid extra RPC).
+     */
+    /*CONTEST
+    getInputEntity(key) {
+        throw new Error('Not Implemented')
+    }
+
+     */
+}
+
+module.exports = Session

+ 2 - 2
src/lib/gramjs/sessions/Memory.js

@@ -40,7 +40,7 @@ class MemorySession extends Session {
     set authKey(value) {
         this._authKey = value
     }
-
+    /* CONTEST
     get takeoutId() {
         return this._takeoutId
     }
@@ -250,7 +250,7 @@ class MemorySession extends Session {
         } else {
             throw new Error('Could not find input entity with key ' + key)
         }
-    }
+    }*/
 }
 
 module.exports = MemorySession

+ 7 - 0
src/lib/gramjs/tl/AllTLObjects.js

@@ -1,4 +1,11 @@
+<<<<<<< HEAD
 /*! File generated by TLObjects' generator. All changes will be ERASED !*/
+=======
+const api = require('./api')
+const LAYER = 105
+const tlobjects = {}
+
+>>>>>>> 3f7f5bfa... GramJS: Comment out unused things
 
 const { constructors, requests, patched } = require('./index');
 const LAYER = 105;

+ 0 - 4
src/lib/gramjs/tl/core/GZIPPacked.js

@@ -21,10 +21,6 @@ class GZIPPacked {
         return data
     }
 
-    static gzip(input) {
-        throw new Error("Not Implemented")
-    }
-
     static ungzip(input) {
         return Buffer.from(inflate(input))
     }

+ 16 - 3
src/lib/gramjs/tl/gramJsApi.js

@@ -14,8 +14,12 @@ const {
 <<<<<<< HEAD:src/lib/gramjs/tl/gramJsApi.js
 =======
 const { readBufferFromBigInt,toSignedLittleBuffer } = require('../Helpers')
+<<<<<<< HEAD:src/lib/gramjs/tl/gramJsApi.js
 >>>>>>> 1a0b5c54... GramJS: Fix images loading: add `async-mutex`; Fix signed LE ints; Bring back `readExactly`:src/lib/gramjs/tl/api.js
 
+=======
+/*CONTEST
+>>>>>>> 3f7f5bfa... GramJS: Comment out unused things:src/lib/gramjs/tl/api.js
 const NAMED_AUTO_CASTS = new Set([
     'chatId,int'
 ])
@@ -34,7 +38,13 @@ const AUTO_CASTS = new Set([
     'InputDocument',
     'InputChatPhoto',
 ])
+<<<<<<< HEAD:src/lib/gramjs/tl/gramJsApi.js
 const struct = require('python-struct')
+=======
+
+ */
+const CACHING_SUPPORTED = typeof self !== 'undefined' && self.localStorage !== undefined
+>>>>>>> 3f7f5bfa... GramJS: Comment out unused things:src/lib/gramjs/tl/api.js
 
 const { readBufferFromBigInt } = require('../Helpers')
 
@@ -121,7 +131,8 @@ function argToBytes(x, type) {
             throw new Error("unsupported")
     }
 }
-
+/*
+CONTEST
 async function getInputFromResolve(utils, client, peer, peerType) {
     switch (peerType) {
         case 'InputPeer':
@@ -152,7 +163,7 @@ async function getInputFromResolve(utils, client, peer, peerType) {
     }
 
 }
-
+*/
 function getArgFromReader(reader, arg) {
     if (arg.isVector) {
         if (arg.useVectorId) {
@@ -387,7 +398,9 @@ function createClasses(classesType, params) {
                 }
             }
 
+            /*CONTEST
             async resolve(client, utils) {
+
                 if (classesType !== 'request') {
                     throw new Error('`resolve()` called for non-request instance')
                 }
@@ -415,7 +428,7 @@ function createClasses(classesType, params) {
                         }
                     }
                 }
-            }
+            }*/
         }
 
         if (namespace) {