UNPKG

wechaty-puppet

Version:

Abstract Puppet for Wechaty

93 lines 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.friendshipMixin = void 0; const config_js_1 = require("../config.js"); const dirty_js_1 = require("../schemas/dirty.js"); const friendshipMixin = (mixinBase) => { class FriendshipMixin extends mixinBase { constructor(...args) { super(...args); config_js_1.log.verbose('PuppetFriendshipMixin', 'constructor()'); } /** * Huan(202203): `friendshipSearchWeixin()` will be removed in Puppet v2.0 * @deprecated use `friendshipSearchHandle()` instead. */ friendshipSearchWeixin(weixin) { config_js_1.log.warn('Puppet', 'friendshipSearchWeixin() is deprecated. use `friendshipSearchHandle()` instead.'); console.error(new Error().stack); return this.friendshipSearchHandle(weixin); } async friendshipSearch(searchQueryFilter) { config_js_1.log.verbose('PuppetFriendshipMixin', 'friendshipSearch("%s")', JSON.stringify(searchQueryFilter)); if (Object.keys(searchQueryFilter).length !== 1) { throw new Error('searchQueryFilter should only include one key for query!'); } if (searchQueryFilter.phone) { return this.friendshipSearchPhone(searchQueryFilter.phone); } else if (searchQueryFilter.weixin) { /** * Huan(202203): `weixin` will be removed in Puppet v2.0 * @deprecate use `handle` instead */ config_js_1.log.warn('Puppet', 'friendshipSearch() `{ weixin: ... }` is deprecated. use `{ handle: ... }` instead.'); console.error(new Error().stack); return this.friendshipSearchHandle(searchQueryFilter.weixin); } else if (searchQueryFilter.handle) { return this.friendshipSearchHandle(searchQueryFilter.handle); } throw new Error(`unknown key from searchQueryFilter: ${Object.keys(searchQueryFilter).join('')}`); } /** * Issue #155 - https://github.com/wechaty/puppet/issues/155 * * @protected */ friendshipPayloadCache(friendshipId) { config_js_1.log.silly('PuppetFriendshipMixin', 'friendshipPayloadCache(id=%s) @ %s', friendshipId, this); if (!friendshipId) { throw new Error('no id'); } const cachedPayload = this.cache.friendship.get(friendshipId); if (cachedPayload) { // log.silly('PuppetFriendshipMixin', 'friendshipPayloadCache(%s) cache HIT', friendshipId) } else { config_js_1.log.silly('PuppetFriendshipMixin', 'friendshipPayloadCache(%s) cache MISS', friendshipId); } return cachedPayload; } async friendshipPayload(friendshipId, newPayload) { config_js_1.log.verbose('PuppetFriendshipMixin', 'friendshipPayload(%s)', friendshipId, newPayload ? ',' + JSON.stringify(newPayload) : ''); if (typeof newPayload === 'object') { await this.cache.friendship.set(friendshipId, newPayload); return; } /** * 1. Try to get from cache first */ const cachedPayload = this.friendshipPayloadCache(friendshipId); if (cachedPayload) { return cachedPayload; } /** * 2. Cache not found */ const rawPayload = await this.friendshipRawPayload(friendshipId); const payload = await this.friendshipRawPayloadParser(rawPayload); this.cache.friendship.set(friendshipId, payload); return payload; } async friendshipPayloadDirty(id) { config_js_1.log.verbose('PuppetFriendshipMixin', 'friendshipPayloadDirty(%s)', id); await this.__dirtyPayloadAwait(dirty_js_1.DirtyType.Friendship, id); } } return FriendshipMixin; }; exports.friendshipMixin = friendshipMixin; //# sourceMappingURL=friendship-mixin.js.map