> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Trending & Recommended Communities

> Fetch trending and recommended communities with the SDK discovery APIs.

Use the SDK discovery APIs to fetch trending and recommended community lists. These methods call the social.plus backend discovery endpoints and return community collections or lists, depending on platform.

<CardGroup cols={2}>
  <Card title="Trending Communities" icon="arrow-trend-up">
    Fetch communities from the trending endpoint
  </Card>

  <Card title="Recommended Communities" icon="sparkles">
    Fetch communities from the recommended endpoint
  </Card>
</CardGroup>

<Info>
  The ranking logic is owned by the backend service. The client SDK exposes methods to request and render the returned communities.
</Info>

## Parameters

| Operation               | Parameter                             | Required | Platforms                | Description                                               |
| ----------------------- | ------------------------------------- | -------- | ------------------------ | --------------------------------------------------------- |
| Trending communities    | `includeDiscoverablePrivateCommunity` | No       | TypeScript, iOS, Android | Include discoverable private communities where supported. |
| Trending communities    | `limit`                               | No       | TypeScript               | Limit the returned collection size.                       |
| Recommended communities | `includeDiscoverablePrivateCommunity` | No       | TypeScript, iOS, Android | Include discoverable private communities where supported. |
| Recommended communities | `limit`                               | No       | TypeScript               | Limit the returned collection size.                       |

## Trending Communities

The `getTrendingCommunities()` method fetches communities from the trending endpoint. TypeScript exposes a Live Collection with pagination options, iOS exposes a Live Collection, Android returns a `Flowable<List<AmityCommunity>>`, and Flutter returns a `Future<List<AmityCommunity>>`.

<CodeGroup>
  ```swift iOS theme={null}
  var token: AmityNotificationToken?

  func observeTrendingCommunities() {
      token = communityRepository.getTrendingCommunities(
          includeDiscoverablePrivateCommunity: true
      ).observe { collection, error in
          for community in collection.snapshots {
              // For example, to handle each community in the list.
          }
      }
  }
  ```

  ```kotlin Android theme={null}
  fun queryTrendingCommunities() {
      AmitySocialClient.newCommunityRepository()
          .getTrendingCommunities(includeDiscoverablePrivateCommunity = true)
          .doOnNext { communities: List<AmityCommunity> ->
              // Render trending communities.
          }
          .doOnError { error ->
              // Handle error.
          }
          .subscribe()
  }
  ```

  ```typescript TypeScript theme={null}
  import { CommunityRepository } from '@amityco/ts-sdk';

  const unsubscriber = CommunityRepository.getTrendingCommunities(
    { limit: 5, includeDiscoverablePrivateCommunity: true },
    ({ data: communities, loading, error }) => {
      if (error) {
        // Handle error.
      }
      if (loading) {
        // Show loading state.
      }
      if (communities) {
        // Render trending communities.
      }
    },
  );
  ```

  ```dart Flutter theme={null}
  void getTrendingCommunities() {
    AmitySocialClient.newCommunityRepository()
        .getTrendingCommunities()
        .then((List<AmityCommunity> communities) {
          // Render trending communities.
        })
        .onError((error, stackTrace) {
          // Handle error.
        });
  }
  ```
</CodeGroup>

## Recommended Communities

The `getRecommendedCommunities()` method fetches communities from the recommended endpoint. Use it when your discovery UI needs a backend-curated list instead of a filter-based query.

<CodeGroup>
  ```swift iOS theme={null}
  var token: AmityNotificationToken?

  func observeRecommendedCommunities() {
      token = communityRepository.getRecommendedCommunities(
          includeDiscoverablePrivateCommunity: true
      ).observe { collection, error in
          for community in collection.snapshots {
              // For example, to handle each community in the list.
          }
      }
  }
  ```

  ```kotlin Android theme={null}
  fun queryRecommendedCommunities() {
      AmitySocialClient.newCommunityRepository()
          .getRecommendedCommunities(includeDiscoverablePrivateCommunity = true)
          .doOnNext { communities: List<AmityCommunity> ->
              // Render recommended communities.
          }
          .doOnError { error ->
              // Handle error.
          }
          .subscribe()
  }
  ```

  ```typescript TypeScript theme={null}
  import { CommunityRepository } from '@amityco/ts-sdk';

  const unsubscriber = CommunityRepository.getRecommendedCommunities(
    { limit: 5, includeDiscoverablePrivateCommunity: true },
    ({ data: communities, loading, error }) => {
      if (error) {
        // Handle error.
      }
      if (loading) {
        // Show loading state.
      }
      if (communities) {
        // Render recommended communities.
      }
    },
  );
  ```

  ```dart Flutter theme={null}
  void getRecommendedCommunities() {
    AmitySocialClient.newCommunityRepository()
        .getRecommendedCommunities()
        .then((List<AmityCommunity> communities) {
          // Render recommended communities.
        })
        .onError((error, stackTrace) {
          // Handle error.
        });
  }
  ```
</CodeGroup>

## Best Practices

<Tip>
  **Recommendation Refresh**: Refresh trending and recommended communities intentionally, such as when the user opens the discovery surface or pulls to refresh.
</Tip>

### User Experience Guidelines

1. **Loading States**: Show skeleton screens during discovery data fetching
2. **Empty States**: Provide fallback content when no recommendations are available
3. **Action Feedback**: Give immediate feedback when users join discovered communities

### Performance Optimization

1. **Pagination**: Use TypeScript pagination options when building longer discovery feeds
2. **Image Optimization**: Preload community avatars for smooth scrolling
3. **Background Updates**: Refresh discovery data in the background

## Related Topics

<CardGroup cols={2}>
  <Card title="Query Communities" href="./query-communities" icon="magnifying-glass">
    Advanced community search and filtering capabilities
  </Card>

  <Card title="Join Community" href="../membership/join-leave-community" icon="user-plus">
    Implement community membership actions from discovery
  </Card>

  <Card title="Community Categories" href="../organization/community-categories" icon="folder">
    Learn about community organization for better recommendations
  </Card>

  <Card title="Get Community Details" href="./get-community" icon="circle-info">
    Display detailed community information before joining
  </Card>
</CardGroup>
