Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Release v2.2.2-beta
Browse files Browse the repository at this point in the history
* Fixed bug with Cyrillic text encoding
* Fixed bug with several broken methods invocations
* Optimized authorization performance
* Added fix for automatic base data center selection
  • Loading branch information
zerobias committed Mar 26, 2017
2 parents 7951d03 + 3268713 commit 1006de5
Show file tree
Hide file tree
Showing 38 changed files with 2,077 additions and 817 deletions.
19 changes: 9 additions & 10 deletions .babelrc
@@ -1,20 +1,19 @@
{
"presets": [
// ["es2015", { "modules": false }]
],
"plugins": [
"transform-flow-strip-types",
// ["fast-async", {
// "useRuntimeModule":true
// }],
"transform-exponentiation-operator",
["transform-es2015-for-of", {
"loose": true
}],
"transform-class-properties",
"transform-async-to-generator",
// ["transform-async-to-module-method", {
// "module": "bluebird",
// "method": "coroutine"
// }],
["transform-object-rest-spread", { "useBuiltIns": true }],
"closure-elimination"
["transform-es2015-block-scoping", {
"throwIfClosureRequired": true
}],
["transform-object-rest-spread", { "useBuiltIns": true }]
,"closure-elimination"
],
"env": {
"commonjs": {
Expand Down
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
lib/**
es/**
dist/**
3 changes: 2 additions & 1 deletion .flowconfig
Expand Up @@ -13,4 +13,5 @@

[options]
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue
suppress_type=$FlowIssue
suppress_type=$FlowIssue
unsafe.enable_getters_and_setters=true
46 changes: 46 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,46 @@
# 2.2.2
* Fixed bug with cyrillic text encoding
* Fixed bug with several broken methods invocations
* Optimized authorization performance
* Added fix for automatic base data center selection by [@goodmind][]

# 2.2.1
* Flag (optional type) fields now acts like common fields.
* Zeroes, empty strings and empty types now can be omited. write only useful fields.
* *invokeWithLayer* api field now may detects internally and don't required (but still valid).
* Type check argument fields
* Fix auth race condition
* Add batch async logger

# 2.2.0

* **breaking** Instance now creates without `new`
* **breaking** Rename module exports from `ApiManager` to `MTProto`

# =<2.1.0

Several early alpha versions based on new architechture

---

# 1.1.0 *(beta)*

* **breaking** Remove all functions from response. Just use the field values.
* Remove logger from response
* Add changelog.md

# 1.0.6 *(beta)*

* Https connection. Usage:
```javascript
const { network } = require('telegram-mtproto')
const connection = network.http({ host: 'ip', port: '80', protocol: 'https' })
```
* Websockets connection. Usage:
```javascript
const connection = network.wc({ host: 'ip', port: '80' })
```
* Precision timing
* Major performance boost

[@goodmind]: https://github.com/goodmind/
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -63,7 +63,6 @@ const phone = {
}

const api = {
invokeWithLayer: 0xda9b0d0d,
layer : 57,
initConnection : 0x69796de9,
api_id : 49631
Expand Down
18 changes: 13 additions & 5 deletions examples/chat-history.js
@@ -1,13 +1,11 @@
const { pluck, last } = require('ramda')
const { pluck } = require('ramda')
const { inputField } = require('./fixtures')

const telegram = require('./init')

const getChat = async () => {
const dialogs = await telegram('messages.getDialogs', {
offset : 0,
limit : 50,
offset_peer: { _: 'inputPeerEmpty' }
limit: 50,
})
const { chats } = dialogs
const selectedChat = await selectChat(chats)
Expand Down Expand Up @@ -70,7 +68,17 @@ const printMessages = messages => {
return formatted
}


const searchUsers = async (username) => {
const results = await telegram('contacts.search', {
q : username,
limit: 100,
})
return results
}

module.exports = {
getChat,
chatHistory
chatHistory,
searchUsers
}
36 changes: 36 additions & 0 deletions examples/from-readme.js
@@ -0,0 +1,36 @@
const { MTProto } = require('../lib')

const phone = {
num : '+9996620001',
code: '22222'
}

const api = {
layer : 57,
initConnection: 0x69796de9,
api_id : 49631
}

const server = {
dev: true //We will connect to the test server.
} //Any empty configurations fields can just not be specified

const client = MTProto({ server, api })

async function connect(){
const { phone_code_hash } = await client('auth.sendCode', {
phone_number : phone.num,
current_number: false,
api_id : 49631,
api_hash : 'fb050b8f6771e15bfda5df2409931569'
})
const { user } = await client('auth.signIn', {
phone_number: phone.num,
phone_code_hash,
phone_code : phone.code
})

console.log('signed as ', user)
}

connect()
11 changes: 7 additions & 4 deletions examples/index.js
@@ -1,10 +1,13 @@
const login = require('./login')
const { getChat, chatHistory } = require('./chat-history')
const { getChat, chatHistory, searchUsers } = require('./chat-history')
const updateProfile = require('./update-profile')

const run = async () => {
await login()
const chat = await getChat()
await chatHistory(chat)
const first_name = await login()
const res = await searchUsers()
await updateProfile(first_name)
// const chat = await getChat()
// await chatHistory(chat)
}

run()
2 changes: 1 addition & 1 deletion examples/login.js
Expand Up @@ -34,7 +34,7 @@ const login = async () => {
username = ''
} = user
console.log('signIn', first_name, username, user.phone)
return telegram
return first_name
} catch (error) {
console.error(error)
}
Expand Down
11 changes: 11 additions & 0 deletions examples/update-profile.js
@@ -0,0 +1,11 @@
const telegram = require('./init')

const updateProfile = async (currentName) => {
const result = await telegram('account.updateProfile', {
first_name: 'lam'//currentName + 'test'
})
console.log('updateProfile', result)
return result
}

module.exports = updateProfile
10 changes: 7 additions & 3 deletions index.d.ts
Expand Up @@ -38,6 +38,7 @@ declare module 'telegram-mtproto' {

interface ApiManagerInstance {
readonly storage: AsyncStorage
readonly updates: any
<T>(method: string): Promise<T>
<T>(method: string, params: Object): Promise<T>
<T>(method: string, params: Object, options: Object): Promise<T>
Expand All @@ -48,16 +49,19 @@ declare module 'telegram-mtproto' {
new (): ApiManagerInstance
new ({ server, api, app, schema, mtSchema }: Config): ApiManagerInstance
}
export var ApiManager: IApiManager
export const ApiManager: IApiManager
class ApiManagerClass {
readonly storage: AsyncStorage
setUserAuth<T>(dc: number, userAuth: T): void
on(event: string|string[], handler: Function)
}
export interface AsyncStorage {
get(...keys: string[]): Promise<any[]>
set(obj: Object): Promise<Object>
get(key: string): Promise<any>
set(key: string, val: any): Promise<any>
remove(...keys: string[]): Promise<any>
clear(): Promise<{}>
}

function MTProto({ server, api, app, schema, mtSchema }: Config): ApiManagerInstance
export default MTProto
}
20 changes: 12 additions & 8 deletions package.json
Expand Up @@ -29,10 +29,11 @@
"ajv": "^4.11.5",
"ajv-keywords": "^1.5.1",
"axios": "^0.15.3",
"bluebird": "^3.4.7",
"bluebird": "^3.5.0",
"debug": "^2.6.3",
"detect-node": "^2.0.3",
"eventemitter2": "^3.0.2",
"memoizee": "^0.4.4",
"pako": "^1.0.4",
"ramda": "^0.23.0",
"randombytes": "^2.0.3",
Expand All @@ -41,23 +42,26 @@
},
"devDependencies": {
"@types/debug": "0.0.29",
"@types/memoizee": "^0.4.0",
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.4.0",
"babel-eslint": "^7.2.0",
"babel-loader": "^6.4.1",
"babel-plugin-closure-elimination": "^1.1.14",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-async-to-module-method": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-es2015-block-scoping": "^6.23.0",
"babel-plugin-transform-es2015-for-of": "^6.23.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.0",
"babel-plugin-transform-exponentiation-operator": "^6.22.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"cross-env": "^3.2.4",
"eslint": "^3.17.1",
"eslint": "^3.18.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.30.3",
"eslint-plugin-flowtype": "^2.30.4",
"eslint-plugin-promise": "^3.5.0",
"flow-bin": "^0.41.0",
"flow-bin": "^0.42.0",
"hirestime": "^3.1.0",
"nightmare": "^2.10.0",
"prompt": "^1.0.0",
Expand Down Expand Up @@ -99,5 +103,5 @@
"type": "git",
"url": "git+https://github.com/zerobias/telegram-mtproto.git"
},
"version": "2.2.0"
"version": "2.2.2"
}
37 changes: 20 additions & 17 deletions src/bin.js
Expand Up @@ -14,6 +14,16 @@ import { eGCD_, greater, divide_, str2bigInt, equalsInt,

const rushaInstance = new Rusha(1024 * 1024)



export function stringToChars(str: string) {
const ln = str.length
const result: number[] = Array(ln)
for (let i = 0; i < ln; ++i)
result[i] = str.charCodeAt(i)
return result
}

export const strDecToHex = str => toLower(
bigInt2str(
str2bigInt(str, 10, 0), 16
Expand All @@ -27,7 +37,7 @@ export function bytesToHex(bytes = []) {
return arr.join('')
}

export function bytesFromHex(hexString) {
export function bytesFromHex(hexString: string) {
const len = hexString.length
let start = 0
const bytes = []
Expand Down Expand Up @@ -163,7 +173,7 @@ const dividerLem = str2bigInt('100000000', 16, 4)
// () => console.log(`Timer L ${timeL} B ${timeB}`, ...a, ...b, n || ''),
// 100)

export function longToInts(sLong) {
export function longToInts(sLong: string) {
const lemNum = str2bigInt(sLong, 10, 6)
const div = new Array(lemNum.length)
const rem = new Array(lemNum.length)
Expand Down Expand Up @@ -195,23 +205,16 @@ export const rshift32 = str => {
return bigInt2str(num, 10)
}

// export function longFromLem(high, low) {
// const highNum = int2bigInt(high, 96, 0)
// leftShift_(highNum, 32)

// addInt_(highNum, low)
// const res = bigInt2str(highNum, 10)
// return res
// }

export function intToUint(val) {
val = parseInt(val) //TODO PERF parseInt is a perfomance issue
if (val < 0)
val = val + 0x100000000
return val
export function intToUint(val: string) {
let result = ~~val
if (result < 0)
result = result + 0x100000000
return result
}

const middle = 0x100000000 / 2 - 1
export function uintToInt(val) {

export function uintToInt(val: number): number {
if (val > middle)
val = val - 0x100000000
return val
Expand Down
2 changes: 1 addition & 1 deletion src/error.js
@@ -1,6 +1,6 @@
//@flow

import type { TypeBuffer } from './tl/types'
import type { TypeBuffer } from './tl/type-buffer'

export class MTError extends Error {
static getMessage(code: number, type: string, message: string) {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -3,6 +3,7 @@ import MTProto from './service/main/wrap'
export { CryptoWorker } from './crypto'
export { bin } from './bin'
export { ApiManager } from './service/api-manager/index'
export { setLogger } from './util/log'

import * as MtpTimeManager from './service/time-manager'
export { MtpTimeManager }
Expand Down

0 comments on commit 1006de5

Please sign in to comment.