提交 79486d02 编写于 作者: ruiruibupt's avatar ruiruibupt

Merge branch 'master' of github.com:Chatie/wechaty into bug-compatible-createroom

{
"name": "wechaty",
"version": "0.15.170",
"version": "0.15.172",
"description": "Wechat for Bot(Personal Account)",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
......
......@@ -530,18 +530,13 @@ export class Contact extends Accessory implements Sayable {
* await contact.sync()
*/
public async sync(): Promise<void> {
// TODO: make sure the contact.* works when we are refreshing the data
// if (this.isReady()) {
// this.dirtyObj = this.obj
// }
// this.payload = undefined
await this.ready(true)
}
/**
* @private
*/
public async ready(noCache = false): Promise<void> {
public async ready(dirty = false): Promise<void> {
log.silly('Contact', 'ready() @ %s', this.puppet)
if (this.isReady()) { // already ready
......@@ -550,7 +545,7 @@ export class Contact extends Accessory implements Sayable {
}
try {
await this.puppet.contactPayload(this.id, noCache)
await this.puppet.contactPayload(this.id, dirty)
// log.silly('Contact', `ready() this.puppet.contactPayload(%s) resolved`, this)
} catch (e) {
......
......@@ -167,7 +167,7 @@ export class Friendship extends Accessory {
}
/**
* no `noCache` support because Friendship has no rawPayload(yet)
* no `dirty` support because Friendship has no rawPayload(yet)
*/
public async ready(): Promise<void> {
if (this.payload) {
......
......@@ -164,11 +164,9 @@ export class PadchatManager extends PadchatRpc {
&& this.cacheRoomMemberRawPayload
&& this.cacheRoomRawPayload
) {
await Promise.all([
this.cacheContactRawPayload.close(),
this.cacheRoomMemberRawPayload.close(),
this.cacheRoomRawPayload.close(),
])
await this.cacheContactRawPayload.close(),
await this.cacheRoomMemberRawPayload.close(),
await this.cacheRoomRawPayload.close(),
this.cacheContactRawPayload = undefined
this.cacheRoomMemberRawPayload = undefined
......@@ -485,6 +483,14 @@ export class PadchatManager extends PadchatRpc {
const autoLoginResult = await this.WXAutoLogin(token)
// const autoLoginResult = await this.padchatRpc.WXAutoLogin(this.autoData.token)
if (!autoLoginResult) {
/**
* 1.1 Delete token for prevent future useless auto login retry
*/
delete deviceInfo.token
this.options.memory.set(MEMORY_SLOT_NAME, memorySlot)
await this.options.memory.save()
await this.emitLoginQrcode()
return false
}
......@@ -513,6 +519,14 @@ export class PadchatManager extends PadchatRpc {
* 4 Send Login Request to user fail, emit QrCode for scan.
*/
await this.emitLoginQrcode()
/**
* 5 Delete token for prevent future useless auto login retry
*/
delete deviceInfo.token
this.options.memory.set(MEMORY_SLOT_NAME, memorySlot)
await this.options.memory.save()
return false
}
......@@ -584,6 +598,10 @@ export class PadchatManager extends PadchatRpc {
*/
if (memorySlot.currentUserId === userId) {
log.silly('PuppetPadchatManager', 'refresh62Data() userId did not change since last login, keep the data as the same')
// Update Token
memorySlot.device[userId]!.token = await this.WXGetLoginToken()
return memorySlot
}
......@@ -748,7 +766,17 @@ export class PadchatManager extends PadchatRpc {
if (!memberListPayload || !('user_name' in memberListPayload)) { // check user_name too becasue the server might return {}
// console.log('memberListPayload', memberListPayload)
throw new Error('no memberListPayload')
// throw new Error('no memberListPayload')
/**
* Room Id not exist
* See: https://github.com/lijiarui/wechaty-puppet-padchat/issues/64#issuecomment-397319016
*/
this.roomMemberRawPayloadDirty(roomId)
this.roomRawPayloadDirty(roomId)
return {}
}
log.silly('PuppetPadchatManager', 'syncRoomMember(%s) total %d members',
......
......@@ -709,12 +709,18 @@ export class PadchatRpc extends EventEmitter {
* Get all member of a room by room id
* @param {any} roomId chatroom_id
*/
public async WXGetChatRoomMember(roomId: string): Promise<PadchatRoomMemberListPayload> {
public async WXGetChatRoomMember(roomId: string): Promise<null | PadchatRoomMemberListPayload> {
const result = await this.rpcCall('WXGetChatRoomMember', roomId)
if (!result) {
throw Error('PadchatRpc, WXGetChatRoomMember, cannot get result from websocket server!')
}
// roomId not exist. (or no permision?)
// See: https://github.com/lijiarui/wechaty-puppet-padchat/issues/64#issuecomment-397319016
if (result.status === -19) {
return null
}
log.silly('PadchatRpc', 'WXGetChatRoomMember() result: %s', JSON.stringify(result).substr(0, 500))
// 00:40:44 SILL PadchatRpc WXGetChatRoomMember() result: {"chatroom_id":0,"count":0,"member":"null\n","message":"","status":0,"user_name":""}
......
......@@ -18,8 +18,6 @@
*/
import path from 'path'
// import fs from 'fs'
// import cuid from 'cuid'
import LRU from 'lru-cache'
import flatten from 'array-flatten'
......@@ -262,7 +260,7 @@ export class PuppetPadchat extends Puppet {
* 1. Sometimes will get duplicated same messages from rpc, drop the same message from here.
*/
if (this.cachePadchatMessagePayload.has(rawPayload.msg_id)) {
log.warn('PuppetPadchat', 'onPadchatMessage(id=%s) duplicate message: %s',
log.silly('PuppetPadchat', 'onPadchatMessage(id=%s) duplicate message: %s',
rawPayload.msg_id,
JSON.stringify(rawPayload).substr(0, 500),
)
......@@ -360,7 +358,7 @@ export class PuppetPadchat extends Puppet {
/**
* Dirty Cache
*/
this.roomMemberPayloadDirty(roomId)
await this.roomMemberPayloadDirty(roomId)
return retry(new Error('roomMemberSearch() not found'))
......@@ -419,7 +417,8 @@ export class PuppetPadchat extends Puppet {
/**
* Dirty Cache
*/
this.roomMemberPayloadDirty(roomId)
await this.roomMemberPayloadDirty(roomId)
await this.roomPayloadDirty(roomId)
this.emit('room-leave', roomId, leaverIdList, removerId)
}
......@@ -439,8 +438,8 @@ export class PuppetPadchat extends Puppet {
const roomId = roomTopicEvent.roomId
log.silly('PuppetPadchat', 'onPadchatMessageRoomEventTopic() roomTopicEvent="%s"', JSON.stringify(roomTopicEvent))
const roomPayload = await this.roomPayload(roomId)
const oldTopic = roomPayload.topic
const roomOldPayload = await this.roomPayload(roomId)
const oldTopic = roomOldPayload.topic
const changerIdList = await this.roomMemberSearch(roomId, changerName)
if (changerIdList.length < 1) {
......@@ -456,11 +455,10 @@ export class PuppetPadchat extends Puppet {
/**
* Update Room Payload to new Topic
*/
const updateRoomPayload = await this.roomPayload(roomId)
updateRoomPayload.topic = newTopic
this.cacheRoomPayload.set(roomId, updateRoomPayload)
this.roomPayloadDirty(roomId)
// const updateRoomPayload = await this.roomPayload(roomId)
// updateRoomPayload.topic = newTopic
// this.cacheRoomPayload.set(roomId, updateRoomPayload)
await this.roomPayloadDirty(roomId)
this.emit('room-topic', roomId, newTopic, oldTopic, changerId)
}
......@@ -1176,7 +1174,7 @@ export class PuppetPadchat extends Puppet {
// this.padchatManager.friendshipRawPayloadDirty(friendshipId)
}
this.friendshipPayloadDirty(friendshipId)
await super.friendshipPayloadDirty(friendshipId)
}
public async friendshipRawPayload(friendshipId: string): Promise<PadchatMessagePayload> {
......
......@@ -471,18 +471,16 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public async contactPayload(
contactId: string,
noCache = false,
dirty = false,
): Promise<ContactPayload> {
// log.silly('Puppet', 'contactPayload(id=%s, noCache=%s) @ %s', contactId, noCache, this)
// log.silly('Puppet', 'contactPayload(id=%s, dirty=%s) @ %s', contactId, dirty, this)
if (!contactId) {
throw new Error('no id')
}
if (noCache) {
log.silly('Puppet', 'contactPayload(%s) cache PURGE', contactId)
this.cacheContactPayload.del(contactId)
if (dirty) {
this.contactPayloadDirty(contactId)
} else {
const cachedPayload = this.contactPayloadCache(contactId)
......@@ -539,18 +537,16 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public async friendshipPayload(
friendshipId: string,
noCache = false,
dirty = false,
): Promise<FriendshipPayload> {
log.verbose('Puppet', 'friendshipPayload(id=%s, noCache=%s)', friendshipId, noCache)
log.verbose('Puppet', 'friendshipPayload(id=%s, dirty=%s)', friendshipId, dirty)
if (!friendshipId) {
throw new Error('no id')
}
if (noCache) {
log.silly('Puppet', 'friendshipPayload(%s) cache PURGE', friendshipId)
this.cacheFriendshipPayload.del(friendshipId)
if (dirty) {
this.friendshipPayloadDirty(friendshipId)
} else {
const cachedPayload = this.friendshipPayloadCache(friendshipId)
......@@ -608,18 +604,16 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public async messagePayload(
messageId: string,
noCache = false,
dirty = false,
): Promise<MessagePayload> {
log.verbose('Puppet', 'messagePayload(id=%s, noCache=%s)', messageId, noCache)
log.verbose('Puppet', 'messagePayload(id=%s, dirty=%s)', messageId, dirty)
if (!messageId) {
throw new Error('no id')
}
if (noCache) {
log.silly('Puppet', 'messagePayload(%s) cache PURGE', messageId)
this.cacheMessagePayload.del(messageId)
if (dirty) {
this.messagePayloadDirty(messageId)
} else {
const cachedPayload = this.messagePayloadCache(messageId)
......@@ -828,18 +822,16 @@ export abstract class Puppet extends EventEmitter implements Sayable {
public async roomPayload(
roomId: string,
noCache = false,
dirty = false,
): Promise<RoomPayload> {
log.verbose('Puppet', 'roomPayload(id=%s, noCache=%s)', roomId, noCache)
log.verbose('Puppet', 'roomPayload(id=%s, dirty=%s)', roomId, dirty)
if (!roomId) {
throw new Error('no id')
}
if (noCache) {
log.silly('Puppet', 'roomPayload(%s) cache PURGE', roomId)
this.cacheRoomPayload.del(roomId)
if (dirty) {
this.roomPayloadDirty(roomId)
} else {
const cachedPayload = this.roomPayloadCache(roomId)
......@@ -905,7 +897,7 @@ export abstract class Puppet extends EventEmitter implements Sayable {
contactId : string,
dirty = false,
): Promise<RoomMemberPayload> {
log.verbose('Puppet', 'roomMemberPayload(roomId=%s, contactId=%s noCache=%s)', roomId, contactId, dirty)
log.verbose('Puppet', 'roomMemberPayload(roomId=%s, contactId=%s dirty=%s)', roomId, contactId, dirty)
if (!roomId || !contactId) {
throw new Error('no id')
......
......@@ -240,15 +240,15 @@ export class Room extends Accessory implements Sayable {
* @private
*/
public async ready(
noCache = false,
dirty = false,
): Promise<void> {
log.verbose('Room', 'ready()')
if (!noCache && this.isReady()) {
if (!dirty && this.isReady()) {
return
}
await this.puppet.roomPayload(this.id, noCache)
await this.puppet.roomPayload(this.id, dirty)
const memberIdList = await this.puppet.roomMemberList(this.id)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册