@juzi/wechaty 1.0.22 → 1.0.25
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 +90 -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 +92 -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 +104 -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
|
|
|
@@ -280,7 +282,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
280
282
|
return
|
|
281
283
|
}
|
|
282
284
|
|
|
283
|
-
this.emit('message',
|
|
285
|
+
this.emit('message', msg)
|
|
284
286
|
|
|
285
287
|
const room = msg.room()
|
|
286
288
|
const listener = msg.listener()
|
|
@@ -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,18 +544,18 @@ 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 addedTags = difference.newValue?.filter(ele => !oldTagsSet.has(ele
|
|
465
|
-
const removedTags = difference.oldValue?.filter(ele => !newTagsSet.has(ele
|
|
550
|
+
const oldTagsSet = new Set(difference.oldValue)
|
|
551
|
+
const newTagsSet = new Set(difference.newValue)
|
|
552
|
+
const addedTags = difference.newValue?.filter(ele => !oldTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
553
|
+
const removedTags = difference.oldValue?.filter(ele => !newTagsSet.has(ele)).map(ele => this.Tag.find({ id: ele })) || []
|
|
466
554
|
if (addedTags.length > 0) {
|
|
467
555
|
this.emit('contact-tag-add', contact, addedTags)
|
|
468
556
|
}
|
|
469
557
|
if (removedTags.length > 0) {
|
|
470
|
-
this.emit('contact-tag-
|
|
558
|
+
this.emit('contact-tag-remove', contact, removedTags)
|
|
471
559
|
}
|
|
472
560
|
break
|
|
473
561
|
}
|
|
@@ -504,7 +592,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
504
592
|
const newPayload = JSON.parse(JSON.stringify(room?.payload || {}))
|
|
505
593
|
|
|
506
594
|
const differences = diffPayload<PUPPET.payloads.Room>(oldPayload, newPayload)
|
|
507
|
-
const
|
|
595
|
+
const importantDifferences = differences.filter(ele => ele && RoomImportantFields.some(key => key === ele.key))
|
|
508
596
|
const regularDifferences = differences.filter(ele => ele && !RoomImportantFields.some(key => key === ele.key)) as RoomUpdatableValuePair[]
|
|
509
597
|
if (regularDifferences.length > 0) {
|
|
510
598
|
const updateEvent: InfoUpdateInterface = {
|
|
@@ -515,7 +603,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
515
603
|
this.emit('update', updateEvent)
|
|
516
604
|
room?.emit('update', updateEvent)
|
|
517
605
|
}
|
|
518
|
-
for (const difference of
|
|
606
|
+
for (const difference of importantDifferences) {
|
|
519
607
|
switch (difference?.key) {
|
|
520
608
|
case 'ownerId': {
|
|
521
609
|
const oldOwner = (await this.Contact.find({ id: difference.oldValue }))!
|
|
@@ -545,6 +633,10 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
|
|
|
545
633
|
case PUPPET.types.Payload.Message:
|
|
546
634
|
// Message does not need to dirty (?)
|
|
547
635
|
break
|
|
636
|
+
case PUPPET.types.Payload.Tag:
|
|
637
|
+
break
|
|
638
|
+
case PUPPET.types.Payload.TagGroup:
|
|
639
|
+
break
|
|
548
640
|
|
|
549
641
|
case PUPPET.types.Payload.Unspecified:
|
|
550
642
|
default:
|