提交 4cc52f1a 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

fix sync for contact; add roomMemberPayloadDirty for sync; prepare for #1552

上级 42faaf66
......@@ -632,30 +632,36 @@ export class Contact extends Accessory implements Sayable {
}
/**
* Force reload(re-ready()) data for Contact,
* Force reload data for Contact, Sync data from lowlevel API again.
*
* @returns {Promise<this>}
* @example
* await contact.sync()
* @private
*/
public async sync (): Promise<void> {
await this.ready(true)
}
/**
* `ready()` is For FrameWork ONLY!
*
* Please not to use `ready()` at the user land.
* If you want to sync data, uyse `sync()` instead.
*
* @private
*/
public async ready (noCache = false): Promise<void> {
public async ready (
forceSync = false,
): Promise<void> {
log.silly('Contact', 'ready() @ %s', this.puppet)
if (this.isReady()) { // already ready
if (!forceSync && this.isReady()) { // already ready
log.silly('Contact', 'ready() isReady() true')
return
}
try {
if (noCache) {
if (forceSync) {
await this.puppet.contactPayloadDirty(this.id)
}
this.payload = await this.puppet.contactPayload(this.id)
......
......@@ -315,19 +315,45 @@ export class Room extends Accessory implements Sayable {
}
/**
* @ignore
* @private
* @deprecated: Use `sync()` instead
*/
public async refresh (): Promise<void> {
await this.sync()
}
/**
* Force reload data for Room, Sync data from lowlevel API again.
*
* @returns {Promise<void>}
* @example
* await room.sync()
*/
public async sync (): Promise<void> {
await this.ready(true)
}
/**
* `ready()` is For FrameWork ONLY!
*
* Please not to use `ready()` at the user land.
* If you want to sync data, uyse `sync()` instead.
*
* @private
*/
public async ready (
dirty = false,
forceSync = false,
): Promise<void> {
log.verbose('Room', 'ready()')
if (!dirty && this.isReady()) {
if (!forceSync && this.isReady()) {
return
}
if (dirty) {
if (forceSync) {
await this.puppet.roomPayloadDirty(this.id)
await this.puppet.roomMemberPayloadDirty(this.id)
}
this.payload = await this.puppet.roomPayload(this.id)
......@@ -342,8 +368,8 @@ export class Room extends Accessory implements Sayable {
.map(id => this.wechaty.Contact.load(id))
.map(contact => {
contact.ready()
.catch(() => {
//
.catch(e => {
log.verbose('Room', 'ready() member.ready() rejection: %s', e)
})
}),
)
......@@ -932,25 +958,6 @@ export class Room extends Accessory implements Sayable {
return contactList
}
/**
* @ignore
*/
public async refresh (): Promise<void> {
return this.sync()
}
/**
* Force reload data for Room, Sync data for Room
*
* @returns {Promise<void>}
* @example
* await room.sync()
* @private
*/
public async sync (): Promise<void> {
await this.ready(true)
}
/**
* Get room's owner from the room.
* > Tips:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册