Skip to content

Commit

Permalink
updated WAMessage definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
adiwajshing committed Sep 8, 2020
1 parent fab5c26 commit 6e22cea
Show file tree
Hide file tree
Showing 8 changed files with 24,544 additions and 20,229 deletions.
8,546 changes: 4,783 additions & 3,763 deletions WAMessage/WAMessage.d.ts

Large diffs are not rendered by default.

35,679 changes: 19,417 additions & 16,262 deletions WAMessage/WAMessage.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build:docs": "typedoc",
"build:tsc": "tsc",
"example": "npx ts-node Example/example.ts",
"gen-protobuf": "ts-node src/Binary/GenerateStatics.ts",
"browser-decode": "npx ts-node src/BrowserMessageDecoding.ts"
},
"author": "Adhiraj Singh",
Expand Down
4 changes: 2 additions & 2 deletions src/Binary/Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class Decoder {
readString(tag: number): string {
if (tag >= 3 && tag <= 235) {
const token = this.getToken(tag)
return token === 's.whatsapp.net' ? 'c.us' : token
return token// === 's.whatsapp.net' ? 'c.us' : token
}

switch (tag) {
Expand All @@ -131,7 +131,7 @@ export default class Decoder {
case WA.Tags.JID_PAIR:
const i = this.readString(this.readByte())
const j = this.readString(this.readByte())
if (i && j) {
if (typeof i === 'string' && j) {
return i + '@' + j
}
throw new Error('invalid jid pair: ' + i + ', ' + j)
Expand Down
6 changes: 2 additions & 4 deletions src/Binary/Encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export default class Encoder {
}
}
writeString(token: string, i: boolean = null) {
if (token === 'c.us') {
token = 's.whatsapp.net'
}

if (token === 'c.us') token = 's.whatsapp.net'

const tokenIndex = WA.SingleByteTokens.indexOf(token)
if (!i && token === 's.whatsapp.net') {
this.writeToken(tokenIndex)
Expand Down
10 changes: 10 additions & 0 deletions src/Binary/GenerateStatics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { promisify } from 'util'
import { exec as exec0 } from 'child_process'

const exec = promisify (exec0)

async function run () {
await exec ('pbjs -t static-module -w commonjs -o ./WAMessage/WAMessage.js ./src/Binary/def.proto')
await exec ('pbts -o ./WAMessage/WAMessage.d.ts ./WAMessage/WAMessage.js')
}
run ()
Loading

0 comments on commit 6e22cea

Please sign in to comment.