UNPKG

@amityco/ts-sdk-react-native

Version:

Amity Social Cloud Typescript SDK

59 lines (49 loc) 1.84 kB
import { getActiveClient } from '~/client/api'; import { ingestInCache } from '~/cache/api/ingestInCache'; import { prepareCommunityPayload } from '../utils'; import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants'; import { LinkedObject } from '~/utils/linkedObject'; /* begin_public_function id: community.query.recommended_communities */ /** * ```js * import { CommunityRepository } from '@amityco/ts-sdk-react-native' * const communities = await CommunityRepository.getRecommendedCommunities() * ``` * * Gets a list of recommended {@link Amity.Community} objects * * @param query The query parameters * @returns A list of {@link Amity.Community} objects * * @category Community API * @async * @private */ export const getRecommendedCommunities = async ( query?: Amity.PageLimit & { includeDiscoverablePrivateCommunity?: boolean }, ): Promise<Amity.Cached<Amity.Community[]>> => { const client = getActiveClient(); client.log('community/getRecommendedCommunities', query); const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDiscoverablePrivateCommunity } = query ?? {}; // API-FIX: backend doesnt answer Amity.Response // const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>( const { data: payload } = await client.http.get<Amity.CommunityPayload>( `/api/v3/communities/recommended`, { params: { includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true, options: { limit }, }, }, ); const data = prepareCommunityPayload(payload); const { communities } = data; const cachedAt = client.cache && Date.now(); if (client.cache) { ingestInCache(data, { cachedAt }); } return { data: communities.map(community => LinkedObject.community(community)), cachedAt }; };