• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript flash-store.FlashStoreSync类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中flash-store.FlashStoreSync的典型用法代码示例。如果您正苦于以下问题:TypeScript FlashStoreSync类的具体用法?TypeScript FlashStoreSync怎么用?TypeScript FlashStoreSync使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FlashStoreSync类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: initCache

  protected async initCache(
    token  : string,
    userId : string,
  ): Promise<void> {
    log.verbose('PuppetPadchatManager', 'initCache(%s, %s)', token, userId)

    if (   this.cacheContactRawPayload
        || this.cacheRoomMemberRawPayload
        || this.cacheRoomRawPayload
    ) {
      throw new Error('cache exists')
    }

    const baseDir = path.join(
      os.homedir(),
      path.sep,
      '.wechaty',
      'puppet-padchat-cache',
      path.sep,
      token,
      path.sep,
      userId,
    )

    const baseDirExist = await fs.pathExists(baseDir)

    if (!baseDirExist) {
      await fs.mkdirp(baseDir)
    }

    this.cacheContactRawPayload    = new FlashStoreSync(path.join(baseDir, 'contact-raw-payload'))
    this.cacheRoomMemberRawPayload = new FlashStoreSync(path.join(baseDir, 'room-member-raw-payload'))
    this.cacheRoomRawPayload       = new FlashStoreSync(path.join(baseDir, 'room-raw-payload'))

    await Promise.all([
      this.cacheContactRawPayload.ready(),
      this.cacheRoomMemberRawPayload.ready(),
      this.cacheRoomRawPayload.ready(),
    ])

    const roomMemberTotalNum = [...this.cacheRoomMemberRawPayload.values()].reduce(
      (accuVal, currVal) => {
        return accuVal + Object.keys(currVal).length
      },
      0,
    )

    log.verbose('PuppetPadchatManager', 'initCache() inited %d Contacts, %d RoomMembers, %d Rooms, cachedir="%s"',
                                      this.cacheContactRawPayload.size,
                                      roomMemberTotalNum,
                                      this.cacheRoomRawPayload.size,
                                      baseDir,
              )
  }
开发者ID:miggame,项目名称:wechaty,代码行数:54,代码来源:padchat-manager.ts


示例2: getRoomMemberIdList

  public async getRoomMemberIdList(
    roomId: string,
    dirty = false,
  ): Promise<string[]> {
    log.verbose('PuppetPadchatManager', 'getRoomMemberIdList(%d)', roomId)
    if (!this.cacheRoomMemberRawPayload) {
      throw new Error('cache not inited' )
    }

    if (dirty) {
      this.roomMemberRawPayloadDirty(roomId)
    }

    const memberRawPayloadDict = this.cacheRoomMemberRawPayload.get(roomId)
                                || await this.syncRoomMember(roomId)

    if (!memberRawPayloadDict) {
      // or return [] ?
      throw new Error('roomId not found: ' + roomId)
    }

    const memberIdList = Object.keys(memberRawPayloadDict)

    // console.log('memberRawPayloadDict:', memberRawPayloadDict)
    log.verbose('PuppetPadchatManager', 'getRoomMemberIdList(%d) length=%d', roomId, memberIdList.length)
    return memberIdList
  }
开发者ID:miggame,项目名称:wechaty,代码行数:27,代码来源:padchat-manager.ts


示例3: onLogin

  protected async onLogin(userId: string): Promise<void> {
    log.verbose('PuppetPadchatManager', `login(%s)`, userId)

    if (this.userId) {
      throw new Error('userId exist')
    }
    this.userId = userId

    await this.stopCheckScan()

    /**
     * Update Memory Slot
     */
    this.memorySlot = await this.refreshMemorySlotData(
      this.memorySlot,
      userId,
    )
    await this.options.memory.set(MEMORY_SLOT_NAME, this.memorySlot)
    await this.options.memory.save()

    /**
     * Init persistence cache
     */
    await this.initCache(this.options.token, this.userId)

    /**
     * Refresh the login-ed user payload
     */
    if (this.cacheContactRawPayload) {
      this.cacheContactRawPayload.delete(this.userId)
      await this.contactRawPayload(this.userId)
    }

    this.emit('login', this.userId)
  }
开发者ID:miggame,项目名称:wechaty,代码行数:35,代码来源:padchat-manager.ts


示例4: contactRawPayloadDirty

 public contactRawPayloadDirty(
   contactId: string,
 ): void {
   log.verbose('PuppetPadchatManager', 'contactRawPayloadDirty(%d)', contactId)
   if (!this.cacheContactRawPayload) {
     throw new Error('cache not inited' )
   }
   this.cacheContactRawPayload.delete(contactId)
 }
开发者ID:miggame,项目名称:wechaty,代码行数:9,代码来源:padchat-manager.ts


示例5: roomRawPayloadDirty

 public roomRawPayloadDirty(
   roomId: string,
 ): void {
   log.verbose('PuppetPadchatManager', 'roomRawPayloadDirty(%d)', roomId)
   if (!this.cacheRoomRawPayload) {
     throw new Error('cache not inited' )
   }
   this.cacheRoomRawPayload.delete(roomId)
 }
开发者ID:miggame,项目名称:wechaty,代码行数:9,代码来源:padchat-manager.ts


示例6: getRoomIdList

 public getRoomIdList(): string[] {
   log.verbose('PuppetPadchatManager', 'getRoomIdList()')
   if (!this.cacheRoomRawPayload) {
     throw new Error('cache not inited' )
   }
   const roomIdList = [...this.cacheRoomRawPayload.keys()]
   log.verbose('PuppetPadchatManager', 'getRoomIdList()=%d', roomIdList.length)
   return roomIdList
 }
开发者ID:miggame,项目名称:wechaty,代码行数:9,代码来源:padchat-manager.ts


示例7: getContactIdList

 public getContactIdList(): string[] {
   log.verbose('PuppetPadchatManager', 'getContactIdList()')
   if (!this.cacheContactRawPayload) {
     throw new Error('cache not inited' )
   }
   const contactIdList = [...this.cacheContactRawPayload.keys()]
   log.silly('PuppetPadchatManager', 'getContactIdList() = %d', contactIdList.length)
   return contactIdList
 }
开发者ID:miggame,项目名称:wechaty,代码行数:9,代码来源:padchat-manager.ts


示例8: syncRoomMember

  public async syncRoomMember(
    roomId: string,
  ): Promise<{ [contactId: string]: PadchatRoomMemberPayload }> {
    log.silly('PuppetPadchatManager', 'syncRoomMember(%s)', roomId)

    const memberListPayload = await this.WXGetChatRoomMember(roomId)

    if (!memberListPayload || !('user_name' in memberListPayload)) { // check user_name too becasue the server might return {}
      /**
       * 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',
                                      roomId,
                                      Object.keys(memberListPayload).length,
              )

    const memberDict: { [contactId: string]: PadchatRoomMemberPayload } = {}

    for (const memberPayload of memberListPayload.member) {
      const      contactId  = memberPayload.user_name
      memberDict[contactId] = memberPayload
    }

    if (!this.cacheRoomMemberRawPayload) {
      throw new Error('cache not inited' )
    }

    const oldMemberDict = this.cacheRoomMemberRawPayload.get(roomId)
    const newMemberDict = {
      ...oldMemberDict,
      ...memberDict,
    }
    this.cacheRoomMemberRawPayload.set(roomId, newMemberDict)

    return newMemberDict
  }
开发者ID:miggame,项目名称:wechaty,代码行数:44,代码来源:padchat-manager.ts


示例9: releaseCache

  protected async releaseCache(): Promise<void> {
    log.verbose('PuppetPadchatManager', 'releaseCache()')

    if (   this.cacheContactRawPayload
        && this.cacheRoomMemberRawPayload
        && this.cacheRoomRawPayload
    ) {
      await this.cacheContactRawPayload.close(),
      await this.cacheRoomMemberRawPayload.close(),
      await this.cacheRoomRawPayload.close(),

      this.cacheContactRawPayload    = undefined
      this.cacheRoomMemberRawPayload = undefined
      this.cacheRoomRawPayload       = undefined

      log.silly('PuppetPadchatManager', 'releaseCache() cache closed.')
    } else {
      log.verbose('PuppetPadchatManager', 'releaseCache() cache not exist.')
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:20,代码来源:padchat-manager.ts


示例10: Error

    const rawPayload = await Misc.retry(async (retry, attempt) => {
      log.silly('PuppetPadchatManager', 'roomRawPayload(%s) retry() attempt=%d', id, attempt)

      if (!this.cacheRoomRawPayload) {
        throw new Error('no cache')
      }

      if (this.cacheRoomRawPayload.has(id)) {
        return this.cacheRoomRawPayload.get(id)
      }

      const tryRawPayload = await this.WXGetRoomPayload(id)

      // check user_name too becasue the server might return {}
      // See issue #1358 https://github.com/Chatie/wechaty/issues/1358
      if (tryRawPayload /* && tryRawPayload.user_name */) {
        this.cacheRoomRawPayload.set(id, tryRawPayload)
        return tryRawPayload
      }
      return retry(new Error('tryRawPayload empty'))
    })
开发者ID:miggame,项目名称:wechaty,代码行数:21,代码来源:padchat-manager.ts



注:本文中的flash-store.FlashStoreSync类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript flat.flatten函数代码示例发布时间:2022-05-25
下一篇:
TypeScript first-mate.GrammarRegistry类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap