Skip to content

Commit

Permalink
Merge pull request #73 from juzibot/feat/add-modify-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
binsee authored Feb 23, 2024
2 parents 97a6e0b + db922a3 commit 74e013e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 29 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/wechaty-puppet-service",
"version": "1.0.91",
"version": "1.0.92",
"description": "Puppet Service for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"@chatie/eslint-config": "^1.0.4",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^4.6.3",
"@juzi/wechaty-puppet": "^1.0.83",
"@juzi/wechaty-puppet": "^1.0.84",
"@juzi/wechaty-puppet-mock": "^1.0.1",
"@swc/core": "1.3.39",
"@types/google-protobuf": "^3.15.5",
Expand All @@ -70,10 +70,10 @@
"why-is-node-running": "^2.2.1"
},
"peerDependencies": {
"@juzi/wechaty-puppet": "^1.0.77"
"@juzi/wechaty-puppet": "^1.0.84"
},
"dependencies": {
"@juzi/wechaty-grpc": "^1.0.77",
"@juzi/wechaty-grpc": "^1.0.79",
"clone-class": "^1.1.1",
"ducks": "^1.0.2",
"file-box": "^1.5.5",
Expand Down
45 changes: 29 additions & 16 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,35 +2333,38 @@ class PuppetService extends PUPPET.Puppet {
}

override async tagTagAdd (
tagName: string,
tagNameList: string[],
tagGroupId?: string,
): Promise<string | void> {
log.verbose('PuppetService', 'tagTagAdd(%s, %s)', tagName, tagGroupId)
): Promise<PUPPET.types.TagInfo[] | void> {
log.verbose('PuppetService', 'tagTagAdd(%s, %s)', tagNameList, tagGroupId)

const request = new grpcPuppet.TagTagAddRequest()

if (typeof tagGroupId !== 'undefined') {
request.setTagGroupId(tagGroupId)
}
request.setTagName(tagName)
request.setTagNameList(tagNameList)

const result = await util.promisify(
this.grpcManager.client.tagTagAdd
.bind(this.grpcManager.client),
)(request)

const id = result.getTagId()
const tagInfoList:PUPPET.types.TagInfo[] = result.getTagInfoList().map(i => ({
id : i.getTagId(),
name: i.getTagName(),
}))

return id
return tagInfoList
}

override async tagTagDelete (
tagId: string,
tagIdList: string[],
): Promise<void> {
log.verbose('PuppetService', 'tagTagDelete(%s)', tagId)
log.verbose('PuppetService', 'tagTagDelete(%s)', tagIdList)

const request = new grpcPuppet.TagTagDeleteRequest()
request.setTagId(tagId)
request.setTagIdList(tagIdList)

await util.promisify(
this.grpcManager.client.tagTagDelete
Expand All @@ -2371,20 +2374,30 @@ class PuppetService extends PUPPET.Puppet {
}

override async tagTagModify (
tagId: string,
tagNewName: string,
): Promise<void> {
log.verbose('PuppetService', 'tagTagModify(%s, %s)', tagId, tagNewName)
tagNewInfoList: PUPPET.types.TagInfo[],
): Promise<PUPPET.types.TagInfo[] | void> {
log.verbose('PuppetService', 'tagTagModify(%o)', tagNewInfoList)

const request = new grpcPuppet.TagTagModifyRequest()
request.setTagId(tagId)
request.setTagNewName(tagNewName)
const newInfoList = tagNewInfoList.map(i => {
const tagInfo = new grpcPuppet.TagTagInfo()
tagInfo.setTagId(i.id)
tagInfo.setTagName(i.name)
return tagInfo
})
request.setTagNewInfoList(newInfoList)

await util.promisify(
const result = await util.promisify(
this.grpcManager.client.tagTagModify
.bind(this.grpcManager.client),
)(request)

const tagInfoList:PUPPET.types.TagInfo[] = result.getTagInfoList().map(i => ({
id : i.getTagId(),
name: i.getTagName(),
}))

return tagInfoList
}

override async tagGroupList (): Promise<string[]> {
Expand Down
40 changes: 31 additions & 9 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1916,13 +1916,19 @@ function puppetImplementation (

try {
const tagGroupId = call.request.getTagGroupId()
const tagName = call.request.getTagName()
const tagNameList = call.request.getTagNameList()

const result = await puppet.tagTagAdd(tagName, tagGroupId)
const result = await puppet.tagTagAdd(tagNameList, tagGroupId)
const response = new grpcPuppet.TagTagAddResponse()

if (result) {
response.setTagId(result)
const tagInfoList : grpcPuppet.TagTagInfo[] = result.map(i => {
const tagInfo = new grpcPuppet.TagTagInfo()
tagInfo.setTagId(i.id)
tagInfo.setTagName(i.name)
return tagInfo
})
response.setTagInfoList(tagInfoList)
}

return callback(null, response)
Expand All @@ -1935,9 +1941,9 @@ function puppetImplementation (
log.verbose('PuppetServiceImpl', 'tagTagDelete()')

try {
const tagId = call.request.getTagId()
const tagIdList = call.request.getTagIdList()

await puppet.tagTagDelete(tagId)
await puppet.tagTagDelete(tagIdList)

return callback(null, new grpcPuppet.TagTagDeleteResponse())
} catch (e) {
Expand All @@ -1949,12 +1955,28 @@ function puppetImplementation (
log.verbose('PuppetServiceImpl', 'tagTagModify()')

try {
const tagId = call.request.getTagId()
const tagNewName = call.request.getTagNewName()
const tagInfoList = call.request.getTagNewInfoList()
const newInfoList : PUPPET.types.TagInfo[] = tagInfoList.map(i => {
const info :PUPPET.types.TagInfo = {
id : i.getTagId(),
name: i.getTagName(),
}
return info
})

await puppet.tagTagModify(tagId, tagNewName)
const result = await puppet.tagTagModify(newInfoList)
const response = new grpcPuppet.TagTagModifyResponse()
if (result) {
const tagInfoList : grpcPuppet.TagTagInfo[] = result.map(i => {
const tagInfo = new grpcPuppet.TagTagInfo()
tagInfo.setTagId(i.id)
tagInfo.setTagName(i.name)
return tagInfo
})
response.setTagInfoList(tagInfoList)
}

return callback(null, new grpcPuppet.TagTagModifyResponse())
return callback(null, response)
} catch (e) {
return grpcError('tagTagModify', e, callback)
}
Expand Down

0 comments on commit 74e013e

Please sign in to comment.