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wechat.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/jo-wechat4u@0.0.9/lib/wechat.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import WechatCore from './core'\nimport EventEmitter from 'events'\nimport * as un from 'underscore';\nimport _ from 'lodash'\nimport {\n  getCONF,\n  isStandardBrowserEnv\n} from './util'\n\nimport ContactFactory from './interface/contact'\nimport MessageFactory from './interface/message'\n\nimport _debug from 'debug'\nconst debug = _debug('wechat')\n\nif (!isStandardBrowserEnv) {\n  process.on('uncaughtException', err => {\n    console.log('uncaughtException', err)\n  })\n}\n\nclass Wechat extends WechatCore {\n\n  constructor(inst={cookie:'{}', obj:'{}'}) {\n    super(JSON.parse(inst.cookie));\n    _.extend(this, new EventEmitter())\n    this.state = this.CONF.STATE.init\n    this.contacts = {} // 所有联系人\n    this.Contact = ContactFactory(this)\n    this.Message = MessageFactory(this)\n    this.lastReportTime = 0\n    this.syncErrorCount = 0\n    _.extend(this, JSON.parse(inst.obj));\n    console.log(this.serialObj());\n  }\n  serialObj() {\n    let nthis = un.pick(this, 'PROP', 'user', 'state', 'lastReportTime', 'rediUri');\n    nthis.user.userAvatar = 'avatar...';\n    console.log('keys:', un.keys(nthis));\n    return {uuid: this.PROP.uuid,\n      cookie: JSON.stringify(this.request_.cm.list),\n      obj: JSON.stringify(nthis)\n    };\n  }\n  get friendList() {\n    let members = []\n\n    for (let key in this.contacts) {\n      let member = this.contacts[key]\n      members.push({\n        username: member['UserName'],\n        nickname: this.Contact.getDisplayName(member),\n        py: member['RemarkPYQuanPin'] ? member['RemarkPYQuanPin'] : member['PYQuanPin'],\n        avatar: member.AvatarUrl\n      })\n    }\n\n    return members\n  }\n\n  syncPolling(callback) {\n    this.syncCheck().then(selector => {\n      debug('Sync Check Selector: ', selector)\n      if (selector != this.CONF.SYNCCHECK_SELECTOR_NORMAL) {\n        return this.sync().then(data => {\n          this.syncErrorCount = 0\n          callback(data)\n        })\n      }\n    }).then(() => {\n      this.syncPolling(callback)\n      this.emit('save');\n      if (+new Date() - this.lastReportTime > 5 * 60 * 1000) {\n        debug('Status Report')\n        this.notifyMobile(this.user.UserName)\n        this.statReport()\n        this.sendText('心跳：' + new Date().toLocaleString(), 'filehelper')\n        this.lastReportTime = +new Date()\n      }\n    }).catch(err => {\n     /* this.emit('error', err)\n      if (this.syncErrorCount++ > 5) {\n        debug(err)\n        this.logout()\n        this.state = this.CONF.STATE.logout\n        callback()\n      } else {\n        setTimeout(() => {\n          this.syncPolling(callback)\n        }, 1000 * this.syncErrorCount)\n      }*/\n      if (this.syncErrorCount++ < 2) {\n        this.emit('logout');\n        this.logout();\n        this.state = this.CONF.STATE.logout;\n      }\n    });\n  }\n\n  async start() {\n    // return;\n    let ret = undefined\n    try {\n      if (this.state != this.CONF.STATE.login) {\n        ret = await this.getUUID()\n        debug('getUUID: ', ret)\n        this.emit('uuid', ret)\n        this.state = this.CONF.STATE.uuid\n        do {\n          ret = await this.checkLogin()\n          debug('checkLogin: ', ret)\n          if (ret.code == 201 && ret.userAvatar) {\n            this.emit('user-avatar', ret.userAvatar)\n          }\n        } while (ret.code !== 200)\n        await this.login()\n      }\n      let result = await this.init()\n      if(result==\"initFailed\") { \n        this.emit('logout');\n        return;\n      }\n      await this.notifyMobile()\n      ret = await this.getContact()\n      debug('getContact data length: ', ret.length)\n      this.updateContacts(ret)\n      this.syncPolling(msg => {\n        if (!msg) {\n          this.emit('logout')\n          this.state = this.CONF.STATE.logout\n        } else if (msg.AddMsgCount) {\n          debug('syncPolling messages count: ', msg.AddMsgCount)\n          this.handleMsg(msg.AddMsgList)\n        }\n      })\n      if (this.state != this.CONF.STATE.login)\n        this.emit('login')\n      this.state = this.CONF.STATE.login\n    } catch (err) {\n      this.emit('error', err)\n      debug(err)\n      this.stop()\n    }\n  }\n\n  stop() {\n    this.logout()\n  }\n\n  handleMsg(data) {\n    data.forEach(msg => {\n      Promise.resolve().then(() => {\n        if (!this.contacts[msg.FromUserName]) {\n          return this.batchGetContact([{\n            UserName: msg.FromUserName\n          }]).catch(err => {\n            debug(err)\n            return [{\n              UserName: msg.FromUserName\n            }]\n          }).then(contacts => {\n            this.updateContacts(contacts)\n          })\n        }\n      }).then(() => {\n        msg = this.Message.extend(msg)\n        this.emit('message', msg)\n        if (msg.MsgType == this.CONF.MSGTYPE_STATUSNOTIFY) {\n          let userList = msg.StatusNotifyUserName.split(',').map(UserName => {\n            return {\n              UserName: UserName\n            }\n          })\n          Promise.all(_.chunk(userList, 50).map(list => {\n            return this.batchGetContact(list).then(res => {\n              debug('batchGetContact data length: ', res.length)\n              this.updateContacts(res)\n            })\n          })).catch(err => {\n            debug(err)\n          })\n        }\n      }).catch(err => {\n        this.emit('error', err)\n        debug(err)\n      })\n    })\n  }\n\n  updateContacts(contacts) {\n    contacts.forEach(contact => {\n      this.contacts[contact.UserName] = this.Contact.extend(contact)\n    })\n    this.emit('contacts-updated', contacts)\n  }\n}\n\nWechat.STATE = getCONF().STATE\n\nexports = module.exports = Wechat\n"]}