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

try to fix contact.findAll() return empty (#1358)

上级 c6797aec
......@@ -388,11 +388,22 @@ export abstract class Puppet extends EventEmitter {
return searchIdList
}
const searchContactPayloadList: ContactPayload[] = await Promise.all(
searchIdList.map(
id => this.contactPayload(id),
),
)
const searchContactPayloadList: ContactPayload[] = (
await Promise.all(
searchIdList.map(
async id => {
try {
const payload = await this.contactPayload(id)
return payload
} catch (e) {
// compatible with {} payload, which means that
// contact id is not friend with the current user
return {} as any
}
},
),
)
).filter(payload => Object.keys(payload).length > 0)
const filterFuncion: ContactPayloadFilterFunction = this.contactQueryFilterFactory(query)
......
......@@ -186,11 +186,11 @@ export class Contact extends Accessory implements Sayable {
*/
public static async findAll<T extends typeof Contact>(
this : T,
query : string | ContactQueryFilter = { name: /.*/ },
query? : string | ContactQueryFilter,
): Promise<T['prototype'][]> {
log.verbose('Cotnact', 'findAll(%s)', JSON.stringify(query))
if (Object.keys(query).length !== 1) {
if (query && Object.keys(query).length !== 1) {
throw new Error('query only support one key. multi key support is not availble now.')
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册