Skip to content

Commit

Permalink
fix(satori): sync hidden over protocol, close #189
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 25, 2023
1 parent 71cc428 commit d740216
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export abstract class Bot<C extends Context = Context, T = any> implements Login
}

update(login: Login) {
this._status = login.status
this.user = login.user
this.dispatchUpdate()
// make sure `status` is the last property to be assigned
// so that `login-updated` event can be dispatched after all properties are updated
const { status, ...rest } = login
Object.assign(this, rest)
this.status = status
}

dispose() {
Expand All @@ -76,10 +78,6 @@ export abstract class Bot<C extends Context = Context, T = any> implements Login
this.dispatch(session)
}

dispatchUpdate() {
this.dispatchLoginEvent('login-updated')
}

get status() {
return this._status
}
Expand All @@ -89,7 +87,7 @@ export abstract class Bot<C extends Context = Context, T = any> implements Login
this._status = value
if (this.ctx.bots.includes(this)) {
this.context.emit('bot-status-updated', this)
this.dispatchUpdate()
this.dispatchLoginEvent('login-updated')
}
}

Expand Down Expand Up @@ -186,7 +184,7 @@ export abstract class Bot<C extends Context = Context, T = any> implements Login
}

toJSON(): Login {
return clone(pick(this, ['platform', 'selfId', 'status', 'user']))
return clone(pick(this, ['platform', 'selfId', 'status', 'user', 'hidden']))
}

async getLogin() {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export interface Login {
user?: User
platform?: string
selfId?: string
hidden?: boolean
status: Status
}

Expand Down

0 comments on commit d740216

Please sign in to comment.