> ## 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.

# Feeds & Timelines

> Query user, community, global, and custom-ranking global feeds with the SDK feed repository.

Use `AmityFeedRepository` to read feed-style post collections. The SDK exposes user feeds, community feeds, global feed, and custom-ranking global feed. Global feed and custom-ranking global feed are separate SDK entry points; the backend owns ranking behavior, and the client SDK selects which feed endpoint to query.

## Feed APIs

| Feed                       | TypeScript                                    | iOS                                                  | Android                                                              | Flutter                                                              |
| -------------------------- | --------------------------------------------- | ---------------------------------------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- |
| Global feed                | `FeedRepository.getGlobalFeed()`              | `AmityFeedRepository().getGlobalFeed()`              | `AmitySocialClient.newFeedRepository().getGlobalFeed()`              | `AmitySocialClient.newFeedRepository().getGlobalFeed()`              |
| Custom-ranking global feed | `FeedRepository.getCustomRankingGlobalFeed()` | `AmityFeedRepository().getCustomRankingGlobalFeed()` | `AmitySocialClient.newFeedRepository().getCustomRankingGlobalFeed()` | `AmitySocialClient.newFeedRepository().getCustomRankingGlobalFeed()` |
| For You feed               | `FeedRepository.getForYouFeed()`              | Supported                                            | Supported                                                            | Not available                                                        |
| User feed                  | `FeedRepository.getUserFeed()`                | `AmityFeedRepository().getUserFeed()`                | `AmitySocialClient.newFeedRepository().getUserFeed()`                | `AmitySocialClient.newFeedRepository().getUserFeed()`                |
| Community feed             | `FeedRepository.getCommunityFeed()`           | `AmityFeedRepository().getCommunityFeed()`           | `AmitySocialClient.newFeedRepository().getCommunityFeed()`           | `AmitySocialClient.newFeedRepository().getCommunityFeed()`           |

<Note>
  TypeScript still exports `queryGlobalFeed()`, but the SDK source marks it deprecated. Use the live collection APIs for new integrations.
</Note>

## Parameters

| Operation                        | Parameter                            | Required | Description                                                                                              |
| -------------------------------- | ------------------------------------ | -------- | -------------------------------------------------------------------------------------------------------- |
| Query global feed                | `dataTypes`                          | No       | Filter the global feed to specific post content types where supported.                                   |
| Query global feed                | `includeMixedStructure`              | No       | Include mixed-structure posts alongside the requested data type filters.                                 |
| Query custom-ranking global feed | `includeMixedStructure`              | No       | Include mixed-structure posts in the backend-ranked global feed response.                                |
| TypeScript pagination            | `limit`, `onNextPage`, `hasNextPage` | No       | Control page size and load additional pages from the live collection callback.                           |
| Android refresh                  | `invalidateCache`                    | No       | Skip cached paging data for deliberate refresh flows.                                                    |
| Query For You feed               | None                                 | —        | `getForYouFeed()` takes no query parameters. Pagination is handled through the live collection callback. |

## Query Global Feed

Global feed returns a paginated collection of posts for the current user's global feed surface. Use data type filters when your UI only needs a subset of post types, such as an image or video feed.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { FeedRepository } from '@amityco/ts-sdk';

  let loadNextPage: (() => void) | undefined;
  let canLoadMore = false;

  const unsubscribe = FeedRepository.getGlobalFeed(
    {
      dataTypes: ['image', 'video'],
      includeMixedStructure: true,
      limit: 20,
    },
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextPage = onNextPage;
      canLoadMore = hasNextPage;
    },
  );

  function loadMoreGlobalFeed() {
    if (canLoadMore) {
      loadNextPage?.();
    }
  }

  unsubscribe();
  ```

  ```swift iOS theme={null}
  token = feedRepository
      .getGlobalFeed(dataTypes: Set(["image", "video"]), includeMixedStructure: true)
      .observe { collection, error in
          if let error {
              handleError(error)
              return
          }

          showSuccessMessage(collection.snapshots.count)
      }
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newFeedRepository()
      .getGlobalFeed()
      .dataTypes(listOf(AmityPost.DataType.IMAGE, AmityPost.DataType.VIDEO))
      .includeMixedStructure(includeMixedStructure = true)
      .build()
      .query()
      .subscribe(
          { pagingData: PagingData<AmityPost> -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final page = await AmitySocialClient.newFeedRepository()
      .getGlobalFeed()
      .types([AmityDataType.IMAGE, AmityDataType.VIDEO])
      .getPagingData(limit: 20);

  final posts = page.data;
  showError(posts.length);
  ```
</CodeGroup>

## Query Custom-Ranking Global Feed

Use custom-ranking global feed when your app has enabled the backend-ranked global feed experience. The SDK does not expose ranking weights or formulas; it only requests the custom-ranking feed and returns the posts provided by the backend.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { FeedRepository } from '@amityco/ts-sdk';

  let loadNextPage: (() => void) | undefined;
  let canLoadMore = false;

  const unsubscribe = FeedRepository.getCustomRankingGlobalFeed(
    {
      includeMixedStructure: true,
      limit: 20,
    },
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextPage = onNextPage;
      canLoadMore = hasNextPage;
    },
  );

  function loadMoreCustomRankingFeed() {
    if (canLoadMore) {
      loadNextPage?.();
    }
  }

  unsubscribe();
  ```

  ```swift iOS theme={null}
  token = feedRepository
      .getCustomRankingGlobalFeed(includeMixedStructure: true)
      .observe { collection, error in
          if let error {
              handleError(error)
              return
          }

          showSuccessMessage(collection.snapshots.count)
      }
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newFeedRepository()
      .getCustomRankingGlobalFeed()
      .includeMixedStructure(includeMixedStructure = true)
      .build()
      .query()
      .subscribe(
          { pagingData: PagingData<AmityPost> -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```

  ```dart Flutter theme={null}
  final page = await AmitySocialClient.newFeedRepository()
      .getCustomRankingGlobalFeed()
      .getPagingData(limit: 20);

  final posts = page.data;
  showError(posts.length);
  ```
</CodeGroup>

## Query For You Feed

For You feed is a backend-personalized global feed for the current user. Ranking is owned by the backend; the SDK only requests the feed and returns the posts the backend provides. It is a network-level feature that must be enabled for your network before the feed returns content.

<Info>
  For You feed is a network setting. Read `getForYouFeedSetting()` on the client and only render the surface when the feed is enabled. If the feed is not enabled, the collection reports a feed-disabled error rather than an empty list — `AmityForYouFeedDisabledError` on TypeScript and Android, or the `.forYouFeedDisabled` error code on iOS (see below).
</Info>

`getForYouFeed()` is a live collection that takes **no query parameters**. Page through results with the `onNextPage` / `hasNextPage` values from the callback; the default page size is 20 posts.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client, FeedRepository } from '@amityco/ts-sdk';

  // 1. Gate the surface on the network setting.
  const { forYouFeed } = await Client.getForYouFeedSetting();
  if (!forYouFeed.enabled) {
    hideForYouSurface();
    return;
  }

  // 2. Observe the personalized feed.
  let loadNextPage: (() => void) | undefined;
  let canLoadMore = false;

  const unsubscribe = FeedRepository.getForYouFeed(
    ({ data: posts, onNextPage, hasNextPage, loading, error }) => {
      if (loading) return;
      if (error) {
        if (error instanceof FeedRepository.AmityForYouFeedDisabledError) {
          // For You feed is not enabled for this network — hide the tab.
          hideForYouSurface();
          return;
        }
        handleError(error);
        return;
      }

      renderResults(posts);
      loadNextPage = onNextPage;
      canLoadMore = hasNextPage;
    },
  );

  function loadMoreForYouFeed() {
    if (canLoadMore) {
      loadNextPage?.();
    }
  }

  unsubscribe();
  ```

  ```swift iOS theme={null}
  let forYouFeed = feedRepository.getForYouFeed()

  token = forYouFeed.observe { collection, error in
      if let error {
          if error.isAmityErrorCode(.forYouFeedDisabled) {
              // For You feed is not enabled for this network — hide the tab.
              hideForYouSurface()
              return
          }
          handleError(error)
          return
      }

      showSuccessMessage(collection.snapshots.count)
  }

  forYouFeed.nextPage()
  ```

  ```kotlin Android theme={null}
  AmitySocialClient.newFeedRepository()
      .getForYouFeed()
      .subscribe(
          { pagingData: PagingData<AmityPost> ->
              showSuccessMessage(pagingData)
          },
          { error ->
              if (error is AmityForYouFeedDisabledError) {
                  // For You feed is not enabled for this network — hide the tab.
                  hideForYouSurface()
              } else {
                  handleGeneralError(error)
              }
          },
      )
  ```
</CodeGroup>

<Note>
  For You feed is available on TypeScript, iOS, and Android. It is not available in the current Flutter SDK.
</Note>

### Read the For You feed setting

`getForYouFeedSetting()` is a method on the client that reports whether the network has For You feed enabled. Use it to decide whether to render a For You tab or entry point at all.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from '@amityco/ts-sdk';

  const setting = await Client.getForYouFeedSetting();
  // setting: { forYouFeed: { enabled: boolean } }

  if (setting.forYouFeed.enabled) {
    showForYouTab();
  }
  ```

  ```swift iOS theme={null}
  let setting = try await client.getForYouFeedSetting()
  if setting.enabled {
      showForYouTab()
  }
  ```

  ```kotlin Android theme={null}
  AmityCoreClient.getForYouFeedSetting()
      .doOnSuccess { setting: AmityForYouFeedSetting ->
          if (setting.enabled) {
              showForYouTab()
          }
      }
      .doOnError { error ->
          handleGeneralError(error)
      }
      .subscribe()
  ```
</CodeGroup>

## Android Cache Invalidation

Android feed builders expose `invalidateCache(true)`. Use it for deliberate refresh flows, such as pull-to-refresh, when the first page should not reuse the existing paging cache.

<CodeGroup>
  ```kotlin Android theme={null}
  AmitySocialClient.newFeedRepository()
      .getGlobalFeed()
      .invalidateCache(invalidateCache = true)
      .build()
      .query()
      .subscribe(
          { pagingData: PagingData<AmityPost> -> showSuccessMessage(pagingData) },
          { error -> handleGeneralError(error) }
      )
  ```
</CodeGroup>

<Note>
  `invalidateCache` is an Android feed-query option in the current SDK surface reviewed for this page.
</Note>

## Notes

* Use post query APIs when you need a specific user or community feed with richer filters such as tags, review status, or deletion state.
* Dispose live collection subscriptions, notification tokens, and stream subscriptions when the screen is destroyed.
* Treat custom-ranking behavior as backend-owned. Do not hardcode ranking assumptions in client UI logic.

## Related Topics

<CardGroup cols={2}>
  <Card title="Query Posts" icon="newspaper" href="/social-plus-sdk/social/content-management/posts/retrieval/query-posts">
    Query user and community post collections with more filters.
  </Card>

  <Card title="Search Posts" icon="magnifying-glass" href="/social-plus-sdk/social/discovery-engagement/search/intelligent-search-post">
    Search posts semantically or by hashtag.
  </Card>
</CardGroup>
