(data)
| 279 | } |
| 280 | |
| 281 | handleMsg (data) { |
| 282 | data.forEach(msg => { |
| 283 | Promise.resolve().then(() => { |
| 284 | if (!this.contacts[msg.FromUserName] || |
| 285 | (msg.FromUserName.startsWith('@@') && this.contacts[msg.FromUserName].MemberCount == 0)) { |
| 286 | return this.batchGetContact([{ |
| 287 | UserName: msg.FromUserName |
| 288 | }]).then(contacts => { |
| 289 | this.updateContacts(contacts) |
| 290 | }).catch(err => { |
| 291 | debug(err) |
| 292 | this.emit('error', err) |
| 293 | }) |
| 294 | } |
| 295 | }).then(() => { |
| 296 | msg = this.Message.extend(msg) |
| 297 | this.emit('message', msg) |
| 298 | if (msg.MsgType === this.CONF.MSGTYPE_STATUSNOTIFY) { |
| 299 | let userList = msg.StatusNotifyUserName.split(',').filter(UserName => !this.contacts[UserName]) |
| 300 | .map(UserName => { |
| 301 | return { |
| 302 | UserName: UserName |
| 303 | } |
| 304 | }) |
| 305 | Promise.all(_.chunk(userList, 50).map(list => { |
| 306 | return this.batchGetContact(list).then(res => { |
| 307 | debug('batchGetContact data length: ', res.length) |
| 308 | this.updateContacts(res) |
| 309 | }) |
| 310 | })).catch(err => { |
| 311 | debug(err) |
| 312 | this.emit('error', err) |
| 313 | }) |
| 314 | } |
| 315 | if (msg.ToUserName === 'filehelper' && msg.Content === '退出wechat4u' || |
| 316 | /^(.\udf1a\u0020\ud83c.){3}$/.test(msg.Content)) { |
| 317 | this.stop() |
| 318 | } |
| 319 | }).catch(err => { |
| 320 | this.emit('error', err) |
| 321 | debug(err) |
| 322 | }) |
| 323 | }) |
| 324 | } |
| 325 | |
| 326 | updateContacts (contacts) { |
| 327 | if (!contacts || contacts.length == 0) { |
no test coverage detected