@juzi/wechaty 1.0.19 → 1.0.21
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/package-json.js +4 -4
- package/dist/cjs/src/user-modules/contact.d.ts +2 -11
- package/dist/cjs/src/user-modules/contact.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/contact.js +30 -29
- package/dist/cjs/src/user-modules/contact.js.map +1 -1
- package/dist/cjs/src/user-modules/room.d.ts +2 -2
- package/dist/cjs/src/user-modules/room.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/room.js +10 -3
- package/dist/cjs/src/user-modules/room.js.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.d.ts +7 -1
- package/dist/cjs/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag-group.js +40 -13
- package/dist/cjs/src/user-modules/tag-group.js.map +1 -1
- package/dist/cjs/src/user-modules/tag.d.ts +11 -4
- package/dist/cjs/src/user-modules/tag.d.ts.map +1 -1
- package/dist/cjs/src/user-modules/tag.js +53 -17
- package/dist/cjs/src/user-modules/tag.js.map +1 -1
- package/dist/esm/src/package-json.js +4 -4
- package/dist/esm/src/user-modules/contact.d.ts +2 -11
- package/dist/esm/src/user-modules/contact.d.ts.map +1 -1
- package/dist/esm/src/user-modules/contact.js +30 -29
- package/dist/esm/src/user-modules/contact.js.map +1 -1
- package/dist/esm/src/user-modules/room.d.ts +2 -2
- package/dist/esm/src/user-modules/room.d.ts.map +1 -1
- package/dist/esm/src/user-modules/room.js +10 -3
- package/dist/esm/src/user-modules/room.js.map +1 -1
- package/dist/esm/src/user-modules/tag-group.d.ts +7 -1
- package/dist/esm/src/user-modules/tag-group.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag-group.js +40 -13
- package/dist/esm/src/user-modules/tag-group.js.map +1 -1
- package/dist/esm/src/user-modules/tag.d.ts +11 -4
- package/dist/esm/src/user-modules/tag.d.ts.map +1 -1
- package/dist/esm/src/user-modules/tag.js +53 -17
- package/dist/esm/src/user-modules/tag.js.map +1 -1
- package/package.json +3 -3
- package/src/package-json.ts +4 -4
- package/src/user-modules/contact.ts +34 -30
- package/src/user-modules/room.ts +11 -4
- package/src/user-modules/tag-group.ts +48 -12
- package/src/user-modules/tag.ts +63 -17
|
@@ -32,11 +32,19 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
32
32
|
name() {
|
|
33
33
|
return this.payload.name;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
group() {
|
|
36
|
+
return this.wechaty.TagGroup.load(this.groupId());
|
|
37
|
+
}
|
|
38
|
+
static pool = [];
|
|
39
|
+
static async list(forceSync = false) {
|
|
40
|
+
log.verbose('Tag', 'list(%s)', forceSync);
|
|
41
|
+
if (this.pool.length > 0 && !forceSync) {
|
|
42
|
+
return this.pool;
|
|
43
|
+
}
|
|
37
44
|
try {
|
|
38
45
|
const payloads = await this.wechaty.puppet.tagTagList();
|
|
39
|
-
|
|
46
|
+
this.pool = payloads.map(payload => new this(payload));
|
|
47
|
+
return this.pool;
|
|
40
48
|
}
|
|
41
49
|
catch (e) {
|
|
42
50
|
this.wechaty.emitError(e);
|
|
@@ -44,23 +52,46 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
44
52
|
return [];
|
|
45
53
|
}
|
|
46
54
|
}
|
|
55
|
+
static async sync() {
|
|
56
|
+
log.verbose('Tag', 'sync()');
|
|
57
|
+
await this.list(true);
|
|
58
|
+
}
|
|
59
|
+
static load(tag) {
|
|
60
|
+
log.verbose('TagGroup', 'load(%s)', tag);
|
|
61
|
+
for (const item of this.pool) {
|
|
62
|
+
if (item.id() === tag.id && (item.groupId() === tag.groupId || (!item.groupId() && !tag.groupId))) {
|
|
63
|
+
return item;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
47
68
|
async contactList() {
|
|
48
|
-
log.verbose('Tag', 'contactList() for tag
|
|
49
|
-
const
|
|
69
|
+
log.verbose('Tag', 'contactList() for tag : %s', this);
|
|
70
|
+
const tag = { id: this.id(), groupId: this.groupId() };
|
|
71
|
+
const contactIds = await this.wechaty.puppet.tagTagContactList(tag);
|
|
50
72
|
const contactPromises = contactIds.map(id => this.wechaty.Contact.find({ id }));
|
|
51
73
|
return Promise.all(contactPromises);
|
|
52
74
|
}
|
|
53
|
-
async tag(
|
|
54
|
-
log.verbose('Tag', 'tag(%s) for tag
|
|
55
|
-
const
|
|
56
|
-
|
|
75
|
+
async tag(contacts) {
|
|
76
|
+
log.verbose('Tag', 'tag(%s) for tag : %s', contacts, this);
|
|
77
|
+
const tag = { id: this.id(), groupId: this.groupId() };
|
|
78
|
+
let contactIds;
|
|
79
|
+
if (Array.isArray(contacts)) {
|
|
80
|
+
contactIds = contacts.map(c => c.id);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
contactIds = [contacts.id];
|
|
84
|
+
}
|
|
85
|
+
await this.wechaty.puppet.tagContactTagAdd([tag], contactIds);
|
|
57
86
|
}
|
|
58
|
-
static async createTag(
|
|
59
|
-
log.verbose('Tag', 'createTag(%s, %s)',
|
|
87
|
+
static async createTag(name, tagGroup) {
|
|
88
|
+
log.verbose('Tag', 'createTag(%s, %s)', tagGroup, name);
|
|
60
89
|
try {
|
|
61
|
-
const payload = await this.wechaty.puppet.tagTagAdd(
|
|
90
|
+
const payload = await this.wechaty.puppet.tagTagAdd(name, tagGroup?.name());
|
|
62
91
|
if (payload) {
|
|
63
|
-
|
|
92
|
+
const newTag = new this(payload);
|
|
93
|
+
this.pool.push(newTag);
|
|
94
|
+
return newTag;
|
|
64
95
|
}
|
|
65
96
|
}
|
|
66
97
|
catch (e) {
|
|
@@ -68,16 +99,21 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
68
99
|
log.error('Contact', 'createTag() exception: %s', e.message);
|
|
69
100
|
}
|
|
70
101
|
}
|
|
71
|
-
static async deleteTag(
|
|
72
|
-
log.verbose('Tag', 'deleteTag(%s, %s)',
|
|
102
|
+
static async deleteTag(tagInstance) {
|
|
103
|
+
log.verbose('Tag', 'deleteTag(%s, %s)', tagInstance);
|
|
104
|
+
const tag = { id: tagInstance.id(), groupId: tagInstance.groupId() };
|
|
73
105
|
try {
|
|
74
|
-
await this.wechaty.puppet.tagTagDelete(tag
|
|
106
|
+
await this.wechaty.puppet.tagTagDelete(tag);
|
|
107
|
+
this.pool.splice(this.pool.indexOf(tagInstance), 1);
|
|
75
108
|
}
|
|
76
109
|
catch (e) {
|
|
77
110
|
this.wechaty.emitError(e);
|
|
78
|
-
log.error('
|
|
111
|
+
log.error('Tag', 'deleteTag() exception: %s', e.message);
|
|
79
112
|
}
|
|
80
113
|
}
|
|
114
|
+
toString() {
|
|
115
|
+
return `<Tag#${this.name() || this.id()}>`;
|
|
116
|
+
}
|
|
81
117
|
}
|
|
82
118
|
class TagImpl extends validationMixin(TagMixin)() {
|
|
83
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../../../src/user-modules/tag.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../../../src/user-modules/tag.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EACL,kBAAkB,GACnB,MAA0B,6BAA6B,CAAA;AAIxD,MAAM,QAAS,SAAQ,kBAAkB,EAAE;IAiBvB;IAflB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAE,OAA4B;QACzC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;QAE9B,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED;;OAEG;IACH,YACkB,OAA4B;QAE5C,KAAK,EAAE,CAAA;QAFS,YAAO,GAAP,OA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,CAAC,KAAK,CAAC,SAAS,CAAE,WAAyB;QAC/C,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,mBAAmB,EAAE,WAAW,CAAC,CAAA;QAEpD,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,EAAmB,CAAA;QAErF,IAAI;YACF,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;YAC3C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;SACpD;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YACzB,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,2BAA2B,EAAG,CAAW,CAAC,OAAO,CAAC,CAAA;SACpE;IACH,CAAC;IAEQ,QAAQ;QACf,OAAO,QAAQ,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,EAAE,GAAG,CAAA;IAC5C,CAAC;;AAIH,MAAM,OAAQ,SAAQ,eAAe,CAAC,QAAQ,CAAC,EAAgB;CAAG;AAYlE,OAAO,EACL,OAAO,GACR,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juzi/wechaty",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "Wechaty is a RPA SDK for Chatbot Makers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
},
|
|
110
110
|
"homepage": "https://github.com/wechaty/",
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@juzi/wechaty-puppet": "^1.0.
|
|
113
|
-
"@juzi/wechaty-puppet-service": "^1.0.
|
|
112
|
+
"@juzi/wechaty-puppet": "^1.0.15",
|
|
113
|
+
"@juzi/wechaty-puppet-service": "^1.0.18",
|
|
114
114
|
"clone-class": "^1.1.1",
|
|
115
115
|
"cmd-ts": "^0.10.0",
|
|
116
116
|
"cockatiel": "^2.0.2",
|
package/src/package-json.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { PackageJsonWechaty } from './config'
|
|
6
6
|
|
|
7
|
-
export const GIT_COMMIT_HASH: string = '
|
|
7
|
+
export const GIT_COMMIT_HASH: string = 'fc0b844832f84f684254ef8a0b1c7431675fdc2f'
|
|
8
8
|
export const packageJson: PackageJsonWechaty = {
|
|
9
9
|
"name": "@juzi/wechaty",
|
|
10
|
-
"version": "1.0.
|
|
10
|
+
"version": "1.0.21",
|
|
11
11
|
"description": "Wechaty is a RPA SDK for Chatbot Makers.",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"exports": {
|
|
@@ -116,8 +116,8 @@ export const packageJson: PackageJsonWechaty = {
|
|
|
116
116
|
},
|
|
117
117
|
"homepage": "https://github.com/wechaty/",
|
|
118
118
|
"dependencies": {
|
|
119
|
-
"@juzi/wechaty-puppet": "^1.0.
|
|
120
|
-
"@juzi/wechaty-puppet-service": "^1.0.
|
|
119
|
+
"@juzi/wechaty-puppet": "^1.0.15",
|
|
120
|
+
"@juzi/wechaty-puppet-service": "^1.0.18",
|
|
121
121
|
"clone-class": "^1.1.1",
|
|
122
122
|
"cmd-ts": "^0.10.0",
|
|
123
123
|
"cockatiel": "^2.0.2",
|
|
@@ -207,28 +207,6 @@ class ContactMixin extends MixinBase implements SayableSayer {
|
|
|
207
207
|
log.verbose('Contact', 'static delete(%s)', contact.id)
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
/**
|
|
211
|
-
* Get tags for all contact
|
|
212
|
-
*
|
|
213
|
-
* @static
|
|
214
|
-
* @returns {Promise<TagInterface[]>}
|
|
215
|
-
* @example
|
|
216
|
-
* const tags = await wechaty.Contact.tags()
|
|
217
|
-
*/
|
|
218
|
-
static async tags (): Promise<TagInterface[]> {
|
|
219
|
-
log.verbose('Contact', 'static tags() for %s', this)
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
const tagIdList = await this.wechaty.puppet.tagTagList()
|
|
223
|
-
const tagList = tagIdList.map(id => this.wechaty.Tag.create(id))
|
|
224
|
-
return tagList
|
|
225
|
-
} catch (e) {
|
|
226
|
-
this.wechaty.emitError(e)
|
|
227
|
-
log.error('Contact', 'static tags() exception: %s', (e as Error).message)
|
|
228
|
-
return []
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
210
|
/**
|
|
233
211
|
*
|
|
234
212
|
* Instance properties
|
|
@@ -674,8 +652,13 @@ class ContactMixin extends MixinBase implements SayableSayer {
|
|
|
674
652
|
|
|
675
653
|
try {
|
|
676
654
|
const tagPayloadList = await this.wechaty.puppet.tagContactTagList(this.id)
|
|
677
|
-
|
|
678
|
-
|
|
655
|
+
|
|
656
|
+
let tagList = tagPayloadList.map(tag => this.wechaty.Tag.load(tag))
|
|
657
|
+
if (tagList.some(tag => typeof tag === 'undefined')) {
|
|
658
|
+
await this.wechaty.Tag.sync()
|
|
659
|
+
tagList = tagPayloadList.map(tag => this.wechaty.Tag.load(tag))
|
|
660
|
+
}
|
|
661
|
+
return tagList.filter(tag => !!tag) as TagInterface[]
|
|
679
662
|
} catch (e) {
|
|
680
663
|
this.wechaty.emitError(e)
|
|
681
664
|
log.error('Contact', 'tags() exception: %s', (e as Error).message)
|
|
@@ -687,10 +670,20 @@ class ContactMixin extends MixinBase implements SayableSayer {
|
|
|
687
670
|
* Add a Tag
|
|
688
671
|
*/
|
|
689
672
|
|
|
690
|
-
async tag (
|
|
691
|
-
log.verbose('Contact', 'tag(%s) for %s',
|
|
673
|
+
async tag (tags: TagInterface | TagInterface[]): Promise<void> {
|
|
674
|
+
log.verbose('Contact', 'tag(%s) for %s', JSON.stringify(tags), this)
|
|
692
675
|
|
|
693
|
-
|
|
676
|
+
if (!Array.isArray(tags)) {
|
|
677
|
+
tags = [tags]
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const tagIdentifiers = tags.map(tag => {
|
|
681
|
+
return {
|
|
682
|
+
id: tag.id(),
|
|
683
|
+
groupId: tag.groupId(),
|
|
684
|
+
}
|
|
685
|
+
})
|
|
686
|
+
await this.wechaty.puppet.tagContactTagAdd(tagIdentifiers, [this.id])
|
|
694
687
|
|
|
695
688
|
}
|
|
696
689
|
|
|
@@ -698,10 +691,21 @@ class ContactMixin extends MixinBase implements SayableSayer {
|
|
|
698
691
|
* Remove a Tag
|
|
699
692
|
*/
|
|
700
693
|
|
|
701
|
-
async tagRemove (
|
|
702
|
-
log.verbose('Contact', 'tagRemove(%s) for %s',
|
|
694
|
+
async tagRemove (tags: TagInterface | TagInterface[]): Promise<void> {
|
|
695
|
+
log.verbose('Contact', 'tagRemove(%s) for %s', JSON.stringify(tags), this)
|
|
696
|
+
|
|
697
|
+
if (!Array.isArray(tags)) {
|
|
698
|
+
tags = [tags]
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const tagIdentifiers = tags.map(tag => {
|
|
702
|
+
return {
|
|
703
|
+
id: tag.id(),
|
|
704
|
+
groupId: tag.groupId(),
|
|
705
|
+
}
|
|
706
|
+
})
|
|
703
707
|
|
|
704
|
-
await this.wechaty.puppet.tagContactTagRemove(
|
|
708
|
+
await this.wechaty.puppet.tagContactTagRemove(tagIdentifiers, [this.id])
|
|
705
709
|
|
|
706
710
|
}
|
|
707
711
|
|
package/src/user-modules/room.ts
CHANGED
|
@@ -728,9 +728,16 @@ class RoomMixin extends MixinBase implements SayableSayer {
|
|
|
728
728
|
* }
|
|
729
729
|
* }
|
|
730
730
|
*/
|
|
731
|
-
async remove (
|
|
732
|
-
log.verbose('Room', 'del(%s)',
|
|
733
|
-
|
|
731
|
+
async remove (contacts: ContactInterface | ContactInterface[]): Promise<void> {
|
|
732
|
+
log.verbose('Room', 'del(%s)', contacts)
|
|
733
|
+
|
|
734
|
+
let contactIds: string[]
|
|
735
|
+
if (Array.isArray(contacts)) {
|
|
736
|
+
contactIds = contacts.map(c => c.id)
|
|
737
|
+
} else {
|
|
738
|
+
contactIds = [contacts.id]
|
|
739
|
+
}
|
|
740
|
+
await this.wechaty.puppet.roomDel(this.id, contactIds)
|
|
734
741
|
// this.delLocal(contact)
|
|
735
742
|
}
|
|
736
743
|
|
|
@@ -738,7 +745,7 @@ class RoomMixin extends MixinBase implements SayableSayer {
|
|
|
738
745
|
* Huan(202106): will be removed after Dec 31, 2023
|
|
739
746
|
* @deprecated use remove(contact) instead.
|
|
740
747
|
*/
|
|
741
|
-
async del (contact: ContactImpl): Promise<void> {
|
|
748
|
+
async del (contact: ContactImpl | ContactImpl[]): Promise<void> {
|
|
742
749
|
log.warn('Room', 'del() is DEPRECATED, use remove() instead.\n%s', new Error().stack)
|
|
743
750
|
return this.remove(contact)
|
|
744
751
|
}
|
|
@@ -26,6 +26,7 @@ import { validationMixin } from '../user-mixins/validation.js'
|
|
|
26
26
|
import {
|
|
27
27
|
wechatifyMixinBase,
|
|
28
28
|
} from '../user-mixins/wechatify.js'
|
|
29
|
+
import type { TagInterface } from './tag.js'
|
|
29
30
|
|
|
30
31
|
class TagGroupMixin extends wechatifyMixinBase() {
|
|
31
32
|
|
|
@@ -58,13 +59,52 @@ class TagGroupMixin extends wechatifyMixinBase() {
|
|
|
58
59
|
return this.payload.name
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
private static pool: TagGroupInterface[] = []
|
|
63
|
+
|
|
64
|
+
static async list (forceSync = false): Promise<TagGroupInterface[]> {
|
|
65
|
+
log.verbose('TagGroup', 'list(%s)', forceSync)
|
|
66
|
+
|
|
67
|
+
if (this.pool.length > 0 && !forceSync) {
|
|
68
|
+
return this.pool
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const payloads = await this.wechaty.puppet.tagGroupList()
|
|
73
|
+
this.pool = payloads.map(payload => new this(payload))
|
|
74
|
+
return this.pool
|
|
75
|
+
} catch (e) {
|
|
76
|
+
this.wechaty.emitError(e)
|
|
77
|
+
log.error('TagGroup', 'list() exception: %s', (e as Error).message)
|
|
78
|
+
return []
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static async sync (): Promise<void> {
|
|
83
|
+
log.verbose('TagGroup', 'sync()')
|
|
84
|
+
|
|
85
|
+
await this.list(true)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static load (tagGroupId: string): TagGroupInterface | undefined {
|
|
89
|
+
log.verbose('TagGroup', 'load(%s)', tagGroupId)
|
|
90
|
+
|
|
91
|
+
for (const item of this.pool) {
|
|
92
|
+
if (item.id() === tagGroupId) {
|
|
93
|
+
return item
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
61
99
|
static async createTagGroup (name: string): Promise<TagGroupInterface | void> {
|
|
62
100
|
log.verbose('TagGroup', 'createTagGroup(%s, %s)', name)
|
|
63
101
|
|
|
64
102
|
try {
|
|
65
103
|
const payload = await this.wechaty.puppet.tagGroupAdd(name)
|
|
66
104
|
if (payload) {
|
|
67
|
-
|
|
105
|
+
const newTagGroup = new this(payload)
|
|
106
|
+
this.pool.push(newTagGroup)
|
|
107
|
+
return newTagGroup
|
|
68
108
|
}
|
|
69
109
|
} catch (e) {
|
|
70
110
|
this.wechaty.emitError(e)
|
|
@@ -77,23 +117,19 @@ class TagGroupMixin extends wechatifyMixinBase() {
|
|
|
77
117
|
|
|
78
118
|
try {
|
|
79
119
|
await this.wechaty.puppet.tagGroupDelete(tagGroup.id())
|
|
120
|
+
this.pool.splice(this.pool.indexOf(tagGroup), 1)
|
|
80
121
|
} catch (e) {
|
|
81
122
|
this.wechaty.emitError(e)
|
|
82
|
-
log.error('
|
|
123
|
+
log.error('TagGroup', 'deleteTagGroup() exception: %s', (e as Error).message)
|
|
83
124
|
}
|
|
84
125
|
}
|
|
85
126
|
|
|
86
|
-
|
|
87
|
-
|
|
127
|
+
async tags (): Promise<TagInterface[]> {
|
|
128
|
+
return (await this.wechaty.Tag.list()).filter(tag => tag.groupId() === this.id())
|
|
129
|
+
}
|
|
88
130
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return payloads.map(payload => new this(payload))
|
|
92
|
-
} catch (e) {
|
|
93
|
-
this.wechaty.emitError(e)
|
|
94
|
-
log.error('TagGroup', 'list() exception: %s', (e as Error).message)
|
|
95
|
-
return []
|
|
96
|
-
}
|
|
131
|
+
override toString () {
|
|
132
|
+
return `<TagGroup#${this.name() || this.id()}>`
|
|
97
133
|
}
|
|
98
134
|
|
|
99
135
|
}
|
package/src/user-modules/tag.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
import type * as PUPPET from '@juzi/wechaty-puppet'
|
|
21
|
+
import type { TagIdentifier } from '@juzi/wechaty-puppet/filters'
|
|
21
22
|
|
|
22
23
|
import type { Constructor } from 'clone-class'
|
|
23
24
|
import { log } from '../config.js'
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
wechatifyMixinBase,
|
|
28
29
|
} from '../user-mixins/wechatify.js'
|
|
29
30
|
import type { ContactInterface } from './contact.js'
|
|
31
|
+
import type { TagGroupInterface } from './tag-group.js'
|
|
30
32
|
|
|
31
33
|
class TagMixin extends wechatifyMixinBase() {
|
|
32
34
|
|
|
@@ -67,12 +69,23 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
67
69
|
return this.payload.name
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
group (): TagGroupInterface | undefined {
|
|
73
|
+
return this.wechaty.TagGroup.load(this.groupId())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private static pool: TagInterface[] = []
|
|
77
|
+
|
|
78
|
+
static async list (forceSync = false): Promise<TagInterface[]> {
|
|
79
|
+
log.verbose('Tag', 'list(%s)', forceSync)
|
|
80
|
+
|
|
81
|
+
if (this.pool.length > 0 && !forceSync) {
|
|
82
|
+
return this.pool
|
|
83
|
+
}
|
|
72
84
|
|
|
73
85
|
try {
|
|
74
86
|
const payloads = await this.wechaty.puppet.tagTagList()
|
|
75
|
-
|
|
87
|
+
this.pool = payloads.map(payload => new this(payload))
|
|
88
|
+
return this.pool
|
|
76
89
|
} catch (e) {
|
|
77
90
|
this.wechaty.emitError(e)
|
|
78
91
|
log.error('Tag', 'list() exception: %s', (e as Error).message)
|
|
@@ -80,28 +93,54 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
|
|
96
|
+
static async sync (): Promise<void> {
|
|
97
|
+
log.verbose('Tag', 'sync()')
|
|
98
|
+
|
|
99
|
+
await this.list(true)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static load (tag: TagIdentifier): TagInterface | undefined {
|
|
103
|
+
log.verbose('TagGroup', 'load(%s)', tag)
|
|
104
|
+
|
|
105
|
+
for (const item of this.pool) {
|
|
106
|
+
if (item.id() === tag.id && (item.groupId() === tag.groupId || (!item.groupId() && !tag.groupId))) {
|
|
107
|
+
return item
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return undefined
|
|
111
|
+
}
|
|
112
|
+
|
|
83
113
|
async contactList (): Promise<ContactInterface[]> {
|
|
84
|
-
log.verbose('Tag', 'contactList() for tag
|
|
114
|
+
log.verbose('Tag', 'contactList() for tag : %s', this)
|
|
85
115
|
|
|
86
|
-
const
|
|
116
|
+
const tag = { id: this.id(), groupId: this.groupId() } as TagIdentifier
|
|
117
|
+
const contactIds = await this.wechaty.puppet.tagTagContactList(tag)
|
|
87
118
|
const contactPromises = contactIds.map(id => this.wechaty.Contact.find({ id })) as Promise<ContactInterface>[]
|
|
88
119
|
return Promise.all(contactPromises)
|
|
89
120
|
}
|
|
90
121
|
|
|
91
|
-
async tag (
|
|
92
|
-
log.verbose('Tag', 'tag(%s) for tag
|
|
122
|
+
async tag (contacts: ContactInterface | ContactInterface[]): Promise<void> {
|
|
123
|
+
log.verbose('Tag', 'tag(%s) for tag : %s', contacts, this)
|
|
93
124
|
|
|
94
|
-
const
|
|
95
|
-
|
|
125
|
+
const tag = { id: this.id(), groupId: this.groupId() } as TagIdentifier
|
|
126
|
+
let contactIds: string[]
|
|
127
|
+
if (Array.isArray(contacts)) {
|
|
128
|
+
contactIds = contacts.map(c => c.id)
|
|
129
|
+
} else {
|
|
130
|
+
contactIds = [contacts.id]
|
|
131
|
+
}
|
|
132
|
+
await this.wechaty.puppet.tagContactTagAdd([tag], contactIds)
|
|
96
133
|
}
|
|
97
134
|
|
|
98
|
-
static async createTag (
|
|
99
|
-
log.verbose('Tag', 'createTag(%s, %s)',
|
|
135
|
+
static async createTag (name: string, tagGroup?: TagGroupInterface): Promise<TagInterface | void> {
|
|
136
|
+
log.verbose('Tag', 'createTag(%s, %s)', tagGroup, name)
|
|
100
137
|
|
|
101
138
|
try {
|
|
102
|
-
const payload = await this.wechaty.puppet.tagTagAdd(
|
|
139
|
+
const payload = await this.wechaty.puppet.tagTagAdd(name, tagGroup?.name())
|
|
103
140
|
if (payload) {
|
|
104
|
-
|
|
141
|
+
const newTag = new this(payload)
|
|
142
|
+
this.pool.push(newTag)
|
|
143
|
+
return newTag
|
|
105
144
|
}
|
|
106
145
|
} catch (e) {
|
|
107
146
|
this.wechaty.emitError(e)
|
|
@@ -109,17 +148,24 @@ class TagMixin extends wechatifyMixinBase() {
|
|
|
109
148
|
}
|
|
110
149
|
}
|
|
111
150
|
|
|
112
|
-
static async deleteTag (
|
|
113
|
-
log.verbose('Tag', 'deleteTag(%s, %s)',
|
|
151
|
+
static async deleteTag (tagInstance: TagInterface): Promise<void> {
|
|
152
|
+
log.verbose('Tag', 'deleteTag(%s, %s)', tagInstance)
|
|
153
|
+
|
|
154
|
+
const tag = { id: tagInstance.id(), groupId: tagInstance.groupId() } as TagIdentifier
|
|
114
155
|
|
|
115
156
|
try {
|
|
116
|
-
await this.wechaty.puppet.tagTagDelete(tag
|
|
157
|
+
await this.wechaty.puppet.tagTagDelete(tag)
|
|
158
|
+
this.pool.splice(this.pool.indexOf(tagInstance), 1)
|
|
117
159
|
} catch (e) {
|
|
118
160
|
this.wechaty.emitError(e)
|
|
119
|
-
log.error('
|
|
161
|
+
log.error('Tag', 'deleteTag() exception: %s', (e as Error).message)
|
|
120
162
|
}
|
|
121
163
|
}
|
|
122
164
|
|
|
165
|
+
override toString () {
|
|
166
|
+
return `<Tag#${this.name() || this.id()}>`
|
|
167
|
+
}
|
|
168
|
+
|
|
123
169
|
}
|
|
124
170
|
|
|
125
171
|
class TagImpl extends validationMixin(TagMixin)<TagInterface>() {}
|