@juzi/wechaty 1.0.23 → 1.0.26
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/dist/cjs/src/config.d.ts +2 -0
- package/dist/cjs/src/config.d.ts.map +1 -1
- package/dist/cjs/src/config.js +3 -1
- package/dist/cjs/src/config.js.map +1 -1
- package/dist/cjs/src/package-json.js +4 -4
- package/dist/cjs/src/pure-functions/update.d.ts +1 -0
- package/dist/cjs/src/pure-functions/update.d.ts.map +1 -1
- package/dist/cjs/src/pure-functions/update.js +12 -1
- package/dist/cjs/src/pure-functions/update.js.map +1 -1
- package/dist/cjs/src/schemas/wechaty-events.d.ts +8 -2
- package/dist/cjs/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/cjs/src/schemas/wechaty-events.js.map +1 -1
- package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/contact.js +7 -20
- package/dist/cjs/src/user-modules/contact.js.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.d.ts +55 -20
- package/dist/cjs/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.js +113 -44
- package/dist/cjs/src/user-modules/tag-group.js.map +1 -1
- package/dist/cjs/src/user-modules/tag.d.ts +58 -24
- package/dist/cjs/src/user-modules/tag.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag.js +142 -51
- package/dist/cjs/src/user-modules/tag.js.map +1 -1
- package/dist/cjs/src/wechaty/wechaty-base.d.ts +7 -7
- package/dist/cjs/src/wechaty-mixins/gerror-mixin.d.ts +1 -1
- package/dist/cjs/src/wechaty-mixins/io-mixin.d.ts +2 -2
- package/dist/cjs/src/wechaty-mixins/login-mixin.d.ts +5 -5
- package/dist/cjs/src/wechaty-mixins/misc-mixin.d.ts +5 -5
- package/dist/cjs/src/wechaty-mixins/plugin-mixin.d.ts +6 -6
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts +32 -6
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js +92 -10
- package/dist/cjs/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/cjs/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +1 -1
- package/dist/esm/src/config.d.ts +2 -0
- package/dist/esm/src/config.d.ts.map +1 -1
- package/dist/esm/src/config.js +2 -0
- package/dist/esm/src/config.js.map +1 -1
- package/dist/esm/src/package-json.js +4 -4
- package/dist/esm/src/pure-functions/update.d.ts +1 -0
- package/dist/esm/src/pure-functions/update.d.ts.map +1 -1
- package/dist/esm/src/pure-functions/update.js +10 -0
- package/dist/esm/src/pure-functions/update.js.map +1 -1
- package/dist/esm/src/schemas/wechaty-events.d.ts +8 -2
- package/dist/esm/src/schemas/wechaty-events.d.ts.map +1 -1
- package/dist/esm/src/schemas/wechaty-events.js.map +1 -1
- package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
- package/dist/esm/src/user-modules/contact.js +7 -20
- package/dist/esm/src/user-modules/contact.js.map +1 -1
- package/dist/esm/src/user-modules/tag-group.d.ts +55 -20
- package/dist/esm/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag-group.js +114 -45
- package/dist/esm/src/user-modules/tag-group.js.map +1 -1
- package/dist/esm/src/user-modules/tag.d.ts +58 -24
- package/dist/esm/src/user-modules/tag.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag.js +120 -52
- package/dist/esm/src/user-modules/tag.js.map +1 -1
- package/dist/esm/src/wechaty/wechaty-base.d.ts +7 -7
- package/dist/esm/src/wechaty-mixins/gerror-mixin.d.ts +1 -1
- package/dist/esm/src/wechaty-mixins/io-mixin.d.ts +2 -2
- package/dist/esm/src/wechaty-mixins/login-mixin.d.ts +5 -5
- package/dist/esm/src/wechaty-mixins/misc-mixin.d.ts +5 -5
- package/dist/esm/src/wechaty-mixins/plugin-mixin.d.ts +6 -6
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts +32 -6
- package/dist/esm/src/wechaty-mixins/puppet-mixin.d.ts.map +1 -1
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js +94 -12
- package/dist/esm/src/wechaty-mixins/puppet-mixin.js.map +1 -1
- package/dist/esm/src/wechaty-mixins/wechatify-user-module-mixin.d.ts +1 -1
- package/package.json +3 -3
- package/src/config.ts +3 -0
- package/src/package-json.ts +4 -4
- package/src/pure-functions/update.ts +11 -0
- package/src/schemas/wechaty-events.ts +7 -0
- package/src/user-modules/contact.ts +7 -20
- package/src/user-modules/tag-group.ts +147 -53
- package/src/user-modules/tag.ts +126 -58
- package/src/wechaty-mixins/puppet-mixin.ts +106 -12
|
@@ -11,12 +11,14 @@ import type {
|
|
|
11
11
|
StateSwitchInterface,
|
|
12
12
|
} from 'state-switch'
|
|
13
13
|
|
|
14
|
-
import { config,
|
|
14
|
+
import { config, PUPPET_PAYLOAD_SYNC_GAP, PUPPET_PAYLOAD_SYNC_MAX_RETRY } from '../config.js'
|
|
15
15
|
import { timestampToDate } from '../pure-functions/timestamp-to-date.js'
|
|
16
16
|
import type {
|
|
17
17
|
ContactImpl,
|
|
18
18
|
ContactInterface,
|
|
19
19
|
RoomImpl,
|
|
20
|
+
TagGroupInterface,
|
|
21
|
+
TagInterface,
|
|
20
22
|
} from '../user-modules/mod.js'
|
|
21
23
|
|
|
22
24
|
import type {
|
|
@@ -26,7 +28,7 @@ import type {
|
|
|
26
28
|
import type { GErrorMixin } from './gerror-mixin.js'
|
|
27
29
|
import type { IoMixin } from './io-mixin.js'
|
|
28
30
|
import { ContactImportantFields, ContactUpdatableValuePair, InfoUpdateInterface, RoomImportantFields, RoomUpdatableValuePair } from '../schemas/update.js'
|
|
29
|
-
import { diffPayload } from '../pure-functions/update.js'
|
|
31
|
+
import { checkUntilChanged, diffPayload } from '../pure-functions/update.js'
|
|
30
32
|
|
|
31
33
|
const PUPPET_MEMORY_NAME = 'puppet'
|
|
32
34
|
|
|
@@ -427,6 +429,92 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
427
429
|
})
|
|
428
430
|
break
|
|
429
431
|
|
|
432
|
+
case 'tag':
|
|
433
|
+
puppet.on('tag', async payload => {
|
|
434
|
+
switch (payload.type) {
|
|
435
|
+
case PUPPET.types.TagEvent.TagCreate: {
|
|
436
|
+
const newTagPromises = payload.idList.map(id => this.Tag.find({ id }))
|
|
437
|
+
const newTags = await Promise.all(newTagPromises)
|
|
438
|
+
this.emit('tag', payload.type, newTags)
|
|
439
|
+
break
|
|
440
|
+
}
|
|
441
|
+
case PUPPET.types.TagEvent.TagDelete: {
|
|
442
|
+
const deletedTagPromises = payload.idList.map(id => this.Tag.find({ id }))
|
|
443
|
+
const deletedTags = await Promise.all(deletedTagPromises)
|
|
444
|
+
this.emit('tag', payload.type, deletedTags)
|
|
445
|
+
// TODO: bind tag-delete to tag instance
|
|
446
|
+
break
|
|
447
|
+
}
|
|
448
|
+
case PUPPET.types.TagEvent.TagRename: {
|
|
449
|
+
const renamedTagPromises = payload.idList.map(id => this.Tag.find({ id }))
|
|
450
|
+
const renamedTags = (await Promise.all(renamedTagPromises)) as TagInterface[]
|
|
451
|
+
await Promise.all(renamedTags.map(async tag => {
|
|
452
|
+
const oldName = tag.name()
|
|
453
|
+
const result = await checkUntilChanged(PUPPET_PAYLOAD_SYNC_GAP, PUPPET_PAYLOAD_SYNC_MAX_RETRY, async () => {
|
|
454
|
+
await tag.sync()
|
|
455
|
+
return tag.name() === oldName
|
|
456
|
+
})
|
|
457
|
+
if (!result) {
|
|
458
|
+
log.warn('WechatyPuppetMixin', 'tagRenameEvent still get old name after %s retries for tag %s', PUPPET_PAYLOAD_SYNC_MAX_RETRY, tag.id)
|
|
459
|
+
}
|
|
460
|
+
}))
|
|
461
|
+
this.emit('tag', payload.type, renamedTags)
|
|
462
|
+
// TODO: bind tag-rename to tag instance
|
|
463
|
+
break
|
|
464
|
+
}
|
|
465
|
+
default:
|
|
466
|
+
throw new Error('tagEventType ' + payload.type + ' unsupported!')
|
|
467
|
+
}
|
|
468
|
+
})
|
|
469
|
+
break
|
|
470
|
+
|
|
471
|
+
case 'tag-group':
|
|
472
|
+
puppet.on('tag-group', async payload => {
|
|
473
|
+
switch (payload.type) {
|
|
474
|
+
|
|
475
|
+
case PUPPET.types.TagGroupEvent.TagGroupCreate: {
|
|
476
|
+
const newTagGroupPromises = payload.idList.map(id =>
|
|
477
|
+
this.TagGroup.find({ id }),
|
|
478
|
+
)
|
|
479
|
+
const newTagGroups = await Promise.all(newTagGroupPromises)
|
|
480
|
+
this.emit('tag-group', payload.type, newTagGroups)
|
|
481
|
+
break
|
|
482
|
+
}
|
|
483
|
+
case PUPPET.types.TagGroupEvent.TagGroupDelete: {
|
|
484
|
+
const deletedTagGroupPromises = payload.idList.map(id =>
|
|
485
|
+
this.TagGroup.find({ id }),
|
|
486
|
+
)
|
|
487
|
+
const deletedTagGroups = await Promise.all(deletedTagGroupPromises)
|
|
488
|
+
this.emit('tag-group', payload.type, deletedTagGroups)
|
|
489
|
+
break
|
|
490
|
+
// TODO: bind tagGroup-delete to tagGroup instance
|
|
491
|
+
}
|
|
492
|
+
case PUPPET.types.TagGroupEvent.TagGroupRename: {
|
|
493
|
+
const renamedTagGroupPromises = payload.idList.map(id =>
|
|
494
|
+
this.TagGroup.find({ id }),
|
|
495
|
+
)
|
|
496
|
+
const renamedTagGroups = (await Promise.all(renamedTagGroupPromises)) as TagGroupInterface[]
|
|
497
|
+
await Promise.all(renamedTagGroups.map(async tagGroup => {
|
|
498
|
+
const oldName = tagGroup.name()
|
|
499
|
+
const result = await checkUntilChanged(PUPPET_PAYLOAD_SYNC_GAP, PUPPET_PAYLOAD_SYNC_MAX_RETRY, async () => {
|
|
500
|
+
await tagGroup.sync()
|
|
501
|
+
return tagGroup.name() === oldName
|
|
502
|
+
})
|
|
503
|
+
if (!result) {
|
|
504
|
+
log.warn('WechatyPuppetMixin', 'tagGroupRenameEvent still get old name after %s retries for tagGroup %s', PUPPET_PAYLOAD_SYNC_MAX_RETRY, tagGroup.id)
|
|
505
|
+
}
|
|
506
|
+
}))
|
|
507
|
+
this.emit('tag-group', payload.type, renamedTagGroups)
|
|
508
|
+
// TODO: bind tagGroup-rename to tagGroup instance
|
|
509
|
+
break
|
|
510
|
+
}
|
|
511
|
+
default:
|
|
512
|
+
throw new Error('tagGroupEventType ' + payload.type + ' unsupported!')
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
})
|
|
516
|
+
break
|
|
517
|
+
|
|
430
518
|
case 'reset':
|
|
431
519
|
// Do not propagation `reset` event from puppet
|
|
432
520
|
break
|
|
@@ -445,7 +533,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
445
533
|
const newPayload = JSON.parse(JSON.stringify(contact?.payload || {}))
|
|
446
534
|
|
|
447
535
|
const differences = diffPayload<PUPPET.payloads.Contact>(oldPayload, newPayload)
|
|
448
|
-
const
|
|
536
|
+
const importantDifferences = differences.filter(ele => ele && ContactImportantFields.some(key => key === ele.key))
|
|
449
537
|
const regularDifferences = differences.filter(ele => ele && !ContactImportantFields.some(key => key === ele.key)) as ContactUpdatableValuePair[]
|
|
450
538
|
if (regularDifferences.length > 0) {
|
|
451
539
|
const updateEvent: InfoUpdateInterface = {
|
|
@@ -456,17 +544,19 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
456
544
|
this.emit('update', updateEvent)
|
|
457
545
|
contact?.emit('update', updateEvent)
|
|
458
546
|
}
|
|
459
|
-
for (const difference of
|
|
547
|
+
for (const difference of importantDifferences) {
|
|
460
548
|
switch (difference?.key) {
|
|
461
549
|
case 'tags': {
|
|
462
|
-
const oldTagsSet = new Set(difference.oldValue
|
|
463
|
-
const newTagsSet = new Set(difference.newValue
|
|
464
|
-
const
|
|
465
|
-
const
|
|
466
|
-
if (
|
|
550
|
+
const oldTagsSet = new Set(difference.oldValue)
|
|
551
|
+
const newTagsSet = new Set(difference.newValue)
|
|
552
|
+
const addedTagPromises = difference.newValue?.filter(ele => !oldTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
553
|
+
const removedTagPromises = difference.oldValue?.filter(ele => !newTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
554
|
+
if (addedTagPromises.length > 0) {
|
|
555
|
+
const addedTags = await Promise.all(addedTagPromises)
|
|
467
556
|
this.emit('contact-tag-add', contact, addedTags)
|
|
468
557
|
}
|
|
469
|
-
if (
|
|
558
|
+
if (removedTagPromises.length > 0) {
|
|
559
|
+
const removedTags = await Promise.all(removedTagPromises)
|
|
470
560
|
this.emit('contact-tag-remove', contact, removedTags)
|
|
471
561
|
}
|
|
472
562
|
break
|
|
@@ -504,7 +594,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
504
594
|
const newPayload = JSON.parse(JSON.stringify(room?.payload || {}))
|
|
505
595
|
|
|
506
596
|
const differences = diffPayload<PUPPET.payloads.Room>(oldPayload, newPayload)
|
|
507
|
-
const
|
|
597
|
+
const importantDifferences = differences.filter(ele => ele && RoomImportantFields.some(key => key === ele.key))
|
|
508
598
|
const regularDifferences = differences.filter(ele => ele && !RoomImportantFields.some(key => key === ele.key)) as RoomUpdatableValuePair[]
|
|
509
599
|
if (regularDifferences.length > 0) {
|
|
510
600
|
const updateEvent: InfoUpdateInterface = {
|
|
@@ -515,7 +605,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
515
605
|
this.emit('update', updateEvent)
|
|
516
606
|
room?.emit('update', updateEvent)
|
|
517
607
|
}
|
|
518
|
-
for (const difference of
|
|
608
|
+
for (const difference of importantDifferences) {
|
|
519
609
|
switch (difference?.key) {
|
|
520
610
|
case 'ownerId': {
|
|
521
611
|
const oldOwner = (await this.Contact.find({ id: difference.oldValue }))!
|
|
@@ -545,6 +635,10 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
545
635
|
case PUPPET.types.Payload.Message:
|
|
546
636
|
// Message does not need to dirty (?)
|
|
547
637
|
break
|
|
638
|
+
case PUPPET.types.Payload.Tag:
|
|
639
|
+
break
|
|
640
|
+
case PUPPET.types.Payload.TagGroup:
|
|
641
|
+
break
|
|
548
642
|
|
|
549
643
|
case PUPPET.types.Payload.Unspecified:
|
|
550
644
|
default:
|