whalibmob 5.9.0 → 5.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/cli.js +7 -0
- package/lib/Client.js +16 -7
- package/lib/proto/MessageProto.js +20 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1112,6 +1112,7 @@ connect()
|
|
|
1112
1112
|
| `app_state_sync` | `{ collections, applied }` | An app-state sync finished; see [Reading Changes Made Elsewhere](#app-state-sync) |
|
|
1113
1113
|
| `app_state_mutation` | `{ collection, index, action, removed }` | An app-state change this library does not model |
|
|
1114
1114
|
| `app_state_key_missing` | `{ collection, keyId }` | App state cannot be read until your phone shares this key |
|
|
1115
|
+
| `app_state_keys` | `{ keys }` | Your phone shared app-state sync keys; a sync starts automatically |
|
|
1115
1116
|
|
|
1116
1117
|
`remote: true` on a chat event means the change was made on your phone or another
|
|
1117
1118
|
linked device rather than by this session. Your own calls carry `synced` instead,
|
package/cli.js
CHANGED
|
@@ -600,6 +600,13 @@ function attachEvents(client) {
|
|
|
600
600
|
_rl && (_rl.resume(), _rl.prompt(true));
|
|
601
601
|
});
|
|
602
602
|
|
|
603
|
+
client.on('app_state_keys', (e) => {
|
|
604
|
+
_rl && _rl.pause();
|
|
605
|
+
out(' app state: received ' + e.keys.length + ' sync key(s) from your phone —' +
|
|
606
|
+
' pins, archives, mutes and stars will sync from now on');
|
|
607
|
+
_rl && (_rl.resume(), _rl.prompt(true));
|
|
608
|
+
});
|
|
609
|
+
|
|
603
610
|
client.on('decrypt_error', (e) => {
|
|
604
611
|
_rl && _rl.pause();
|
|
605
612
|
out(' DECRYPT_ERROR from ' + e.from + ' id ' + e.id + ' : ' + (e.err && e.err.message));
|
package/lib/Client.js
CHANGED
|
@@ -1984,13 +1984,13 @@ class WhalibmobClient extends EventEmitter {
|
|
|
1984
1984
|
if (decoded.type === 'protocol') {
|
|
1985
1985
|
_whaDbg('[DBG] PROTO subtype=' + decoded.subtype + ' id=' + id);
|
|
1986
1986
|
|
|
1987
|
-
//
|
|
1988
|
-
|
|
1987
|
+
// Keyed off what the message actually carried rather than off the
|
|
1988
|
+
// type that announced it. A payload that is present is the payload,
|
|
1989
|
+
// whatever the type number turns out to mean.
|
|
1990
|
+
if (decoded.historySyncNotification) {
|
|
1989
1991
|
this._handleHistorySync(decoded.historySyncNotification, id);
|
|
1990
1992
|
}
|
|
1991
|
-
|
|
1992
|
-
// ── APP_STATE_SYNC_KEY_SHARE ──────────────────────────────────────
|
|
1993
|
-
if (decoded.subtype === 'app_state_sync_key_share' && decoded.appStateSyncKeyShare) {
|
|
1993
|
+
if (decoded.appStateSyncKeyShare) {
|
|
1994
1994
|
this._handleAppStateSyncKeyShare(decoded.appStateSyncKeyShare);
|
|
1995
1995
|
}
|
|
1996
1996
|
|
|
@@ -2025,10 +2025,10 @@ class WhalibmobClient extends EventEmitter {
|
|
|
2025
2025
|
const decoded = this._decodeMsg(plaintext);
|
|
2026
2026
|
if (decoded.type === 'senderKeyDistribution') return;
|
|
2027
2027
|
if (decoded.type === 'protocol') {
|
|
2028
|
-
if (decoded.
|
|
2028
|
+
if (decoded.historySyncNotification) {
|
|
2029
2029
|
this._handleHistorySync(decoded.historySyncNotification, id);
|
|
2030
2030
|
}
|
|
2031
|
-
if (decoded.
|
|
2031
|
+
if (decoded.appStateSyncKeyShare) {
|
|
2032
2032
|
this._handleAppStateSyncKeyShare(decoded.appStateSyncKeyShare);
|
|
2033
2033
|
}
|
|
2034
2034
|
return;
|
|
@@ -3700,6 +3700,15 @@ class WhalibmobClient extends EventEmitter {
|
|
|
3700
3700
|
}
|
|
3701
3701
|
|
|
3702
3702
|
this.emit('app_state_keys', { keys: keyShare.keys });
|
|
3703
|
+
|
|
3704
|
+
// The key is what app state was waiting on. Anything the server has been
|
|
3705
|
+
// holding for us can be read now, so go and get it rather than sitting on
|
|
3706
|
+
// it until the next dirty bit happens along.
|
|
3707
|
+
if (this._connected && this._appState) {
|
|
3708
|
+
this.syncAppState().catch(err => {
|
|
3709
|
+
_whaDbg('[DBG] APP_STATE sync after key share failed: ' + (err && err.message));
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3703
3712
|
}
|
|
3704
3713
|
|
|
3705
3714
|
/**
|
|
@@ -672,28 +672,38 @@ function decodeMessageContainer(buf) {
|
|
|
672
672
|
try {
|
|
673
673
|
const pm = _decodeFields(f[12]);
|
|
674
674
|
const pmType = pm[2];
|
|
675
|
+
// ProtocolMessage.Type. These are not the field numbers the payloads
|
|
676
|
+
// live in and the two must not be confused: HISTORY_SYNC_NOTIFICATION
|
|
677
|
+
// is type 5 carried in field 6, APP_STATE_SYNC_KEY_SHARE is type 6
|
|
678
|
+
// carried in field 7. Having those two the wrong way round meant a key
|
|
679
|
+
// share was read as a history notification, looked in the field it does
|
|
680
|
+
// not use, found nothing, and was dropped — so app state could never be
|
|
681
|
+
// decrypted at all.
|
|
675
682
|
const typeNames = {
|
|
676
683
|
0: 'revoke',
|
|
677
684
|
3: 'ephemeral',
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
685
|
+
4: 'ephemeral_sync_response',
|
|
686
|
+
5: 'history_sync',
|
|
687
|
+
6: 'app_state_sync_key_share',
|
|
688
|
+
7: 'app_state_sync_key_request',
|
|
689
|
+
9: 'initial_security_notification_setting_sync',
|
|
690
|
+
10: 'app_state_fatal_exception',
|
|
691
|
+
11: 'share_phone_number',
|
|
692
|
+
14: 'message_edit'
|
|
681
693
|
};
|
|
682
694
|
const subtype = typeNames[pmType] || String(pmType);
|
|
683
695
|
msgResult = { type: 'protocol', subtype };
|
|
684
696
|
|
|
685
|
-
//
|
|
686
|
-
//
|
|
687
|
-
|
|
697
|
+
// The payloads are read by the field they occupy rather than by the
|
|
698
|
+
// type that announced them, so a type number this list does not know
|
|
699
|
+
// about still delivers what it carried.
|
|
700
|
+
if (pm[6] && Buffer.isBuffer(pm[6])) {
|
|
688
701
|
try {
|
|
689
702
|
const { decodeHistorySyncNotification } = require('../HistorySyncHandler');
|
|
690
703
|
msgResult.historySyncNotification = decodeHistorySyncNotification(pm[6]);
|
|
691
704
|
} catch (_hse) {}
|
|
692
705
|
}
|
|
693
|
-
|
|
694
|
-
// ── APP_STATE_SYNC_KEY_SHARE (pmType=5) ──────────────────────────────
|
|
695
|
-
// ProtocolMessage field 7 holds the AppStateSyncKeyShare bytes.
|
|
696
|
-
if (pmType === 5 && pm[7] && Buffer.isBuffer(pm[7])) {
|
|
706
|
+
if (pm[7] && Buffer.isBuffer(pm[7])) {
|
|
697
707
|
try {
|
|
698
708
|
const { decodeAppStateSyncKeyShare } = require('../HistorySyncHandler');
|
|
699
709
|
msgResult.appStateSyncKeyShare = decodeAppStateSyncKeyShare(pm[7]);
|