当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript FlashStoreSync.set方法代码示例

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


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

示例1: 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

示例2: retry

    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

示例3: syncContactsAndRooms

  public async syncContactsAndRooms(): Promise<void> {
    log.verbose('PuppetPadchatManager', `syncContactsAndRooms()`)

    let cont = true
    while (cont && this.state.on() && this.userId) {
      log.silly('PuppetPadchatManager', `syncContactsAndRooms() while() syncing WXSyncContact ...`)

      const syncContactList = await this.WXSyncContact()

      await new Promise(r => setTimeout(r, 10 * 1000))

      if (!Array.isArray(syncContactList) || syncContactList.length <= 0) {
        log.warn('PuppetPadchatManager', 'syncContactsAndRooms() cannot get array result: %s', JSON.stringify(syncContactList))
        continue
      }

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

      log.silly('PuppetPadchatManager', 'syncContactsAndRooms() syncing %d out of Contact(%d) & Room(%d) ...',
                                          syncContactList.length,
                                          this.cacheContactRawPayload.size,
                                          this.cacheRoomRawPayload.size,
                  )

      for (const syncContact of syncContactList) {

        if (syncContact.continue !== PadchatContinue.Go) {
          log.verbose('PuppetPadchatManager', 'syncContactsAndRooms() sync contact done!')
          cont = false
          break
        }

        if (syncContact.msg_type === PadchatContactMsgType.Contact) {
          if (isRoomId(syncContact.user_name)) {
            /**
             * Room
             */
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() updating Room %s(%s)',
                        syncContact.nick_name,
                        syncContact.user_name,
            )
            const roomId = syncContact.user_name
            const roomPayload = syncContact as PadchatRoomPayload

            this.cacheRoomRawPayload.set(roomId, roomPayload)

            /**
             * Use delay queue executor to sync room:
             *  add syncRoomMember task to the queue
             */
            await this.delayQueueExecutor.execute(
              () => this.syncRoomMember(roomId),
              `syncRoomMember(${roomId})`,
            )
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() added sync room(%s) task to delayQueueExecutor', roomId)

          } else if (isContactId(syncContact.user_name)) {
            /**
             * Contact
             */
            log.silly('PuppetPadchatManager', 'syncContactsAndRooms() updating Contact %s(%s)',
                        syncContact.nick_name,
                        syncContact.user_name,
            )
            const contactPayload = syncContact as PadchatContactPayload
            const contactId = contactPayload.user_name

            this.cacheContactRawPayload.set(contactId, contactPayload)

          } else {
            throw new Error('id is neither room nor contact')
          }
        } else {
          // {"continue":1,"msg_type":2048,"status":1,"uin":4763975}
          if (   syncContact.continue === PadchatContinue.Go
              && syncContact.msg_type === PadchatContactMsgType.N11_2048
              && typeof syncContact.uin !== 'undefined'
          ) {
            // HeartBeat??? discard it in silent
          } else {
            log.silly('PuppetPadchatManager', `syncContactsAndRooms() skip for syncContact.msg_type=%s(%s) %s`,
              syncContact.msg_type && PadchatContactMsgType[syncContact.msg_type],
              syncContact.msg_type,
              JSON.stringify(syncContact),
            )
          }
        }
      }
    }
  }
开发者ID:miggame,项目名称:wechaty,代码行数:94,代码来源:padchat-manager.ts


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