Skip to content

Commit

Permalink
Merge pull request #73 from juzibot/feat/dirty-propagation
Browse files Browse the repository at this point in the history
feat: 🎸 dirty propagation
  • Loading branch information
hcfw007 authored Oct 30, 2023
2 parents 3850af2 + 6dcd127 commit 6e9df75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/wechaty",
"version": "1.0.74",
"version": "1.0.75",
"description": "Wechaty is a RPA SDK for Chatbot Makers.",
"type": "module",
"exports": {
Expand Down Expand Up @@ -132,7 +132,7 @@
"@chatie/eslint-config": "^1.0.4",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^4.6.3",
"@juzi/wechaty-puppet": "^1.0.66",
"@juzi/wechaty-puppet": "^1.0.68",
"@juzi/wechaty-puppet-mock": "^1.0.1",
"@swc/core": "1.3.44",
"@swc/helpers": "^0.3.6",
Expand Down
3 changes: 3 additions & 0 deletions src/schemas/wechaty-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type WechatyEventListenerTagGroup = (type: PUPPET.types.TagGroupEvent,
type WechatyEventListenerPostComment = (comment: PostInterface, post: PostInterface) => void | Promise<void>
type WechatyEventListenerPostTap = (post: PostInterface, contact: ContactInterface, type: PUPPET.types.Tap, tap: boolean, date?: Date) => void | Promise<void>
type WechatyEventListenerVerifyCode = (id: string, message: string, scene: PUPPET.types.VerifyCodeScene, status: PUPPET.types.VerifyCodeStatus) => void | Promise<void>
type WechatyEventListenerDirty = (id: string, type: PUPPET.types.Dirty) => void | Promise<void>

/**
* @desc Wechaty Class Event Type
Expand Down Expand Up @@ -261,6 +262,7 @@ interface WechatyEventListeners {
'post-comment' : WechatyEventListenerPostComment
'post-tap' : WechatyEventListenerPostTap
'verify-code' : WechatyEventListenerVerifyCode
'dirty' : WechatyEventListenerDirty
}

const WechatyEventEmitter = EventEmitter as any as new () => TypedEventEmitter<
Expand Down Expand Up @@ -302,6 +304,7 @@ export type {
WechatyEventListenerPostComment,
WechatyEventListenerPostTap,
WechatyEventListenerVerifyCode,
WechatyEventListenerDirty,
}
export {
WechatyEventEmitter,
Expand Down
5 changes: 3 additions & 2 deletions src/wechaty-mixins/puppet-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
const differences = diffPayload<PUPPET.payloads.Contact>(oldPayload, newPayload)
if (differences.length === 0) {
log.info('WechatyPuppetMixin', `got dirty for contact ${payloadId} but cannot find any difference. old payload: ${JSON.stringify(oldPayload)}, new payload: ${JSON.stringify(newPayload)}`)
return
break
}

const importantDifferences = differences.filter(ele => ele && ContactImportantFields.some(key => key === ele.key))
Expand Down Expand Up @@ -721,7 +721,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &

if (differences.length === 0) {
log.info('WechatyPuppetMixin', `got dirty for room ${payloadId} but cannot find any difference. old payload: ${JSON.stringify(oldPayload)}, new payload: ${JSON.stringify(newPayload)}`)
return
break
}

const importantDifferences = differences.filter(ele => ele && RoomImportantFields.some(key => key === ele.key))
Expand Down Expand Up @@ -778,6 +778,7 @@ const puppetMixin = <MixinBase extends WechatifyUserModuleMixin & GErrorMixin &
default:
throw new Error('unknown payload type: ' + payloadType)
}
this.emit('dirty', payloadId, payloadType)
} catch (e) {
this.emit('error', GError.from(e))
}
Expand Down

0 comments on commit 6e9df75

Please sign in to comment.