Flutter: Unable to get post for different communities

As per my use case, user can join multiple communities. I need to fetch all the posts from different community and show it at one screen. Is it possible to pass list of community ids and get all the posts available in those community using Amity? I have not find any documentation for this. Please help.

Hi @maddy0028 , are you referring to the global feed: https://docs.amity.co/social/feed/query-global-feed ? This feed consolidates all posts from the communities that a user has joined.

Hi @amitysupport I have tried global feed, but I am not able to fetch posts added for different community. I am using below code:

_globalController = PagingController(
pageFuture: (token) {
return AmitySocialClient.newFeedRepository()
.getGlobalFeed()
.getPagingData(token: token, limit: 20);
},
pageSize: 20,
);

_globalController.addListener(
  () {
    if (_globalController.error == null) {
      _globalPosts ??= [];
      _globalController.loadedItems.forEach((element) {
        int index = _globalPosts!
            .indexWhere((post) => post.postId == element.postId);
        if (index < 0) {
          _globalPosts!.insert(0, element);
        } else {
          _globalPosts!.removeAt(index);
          _globalPosts!.insert(0, element);
        }
      });

      _globalPosts?.sort((a, b) => b.createdAt!.compareTo(a.createdAt!));
      Future.delayed(Duration(milliseconds: 500), () {
        notifyListeners();
      });
    } else {
      _globalController.retry();
    }
  },
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  _globalController.fetchNextPage();
});

Let me know if I am missing something. Thanks

Understood. Just to clarify, are you specifically looking to fetch the posts from communities that a user has joined? Please note that this will not include the posts from other communities that the user is not a member of. Can you please confirm if this is the requirement you are referring to?

Yes @amitysupport you got my problem. I need to fetch posts from joined community by any user. I am not looking for posts which are available on other community which user has not joined.

Thank you for your clarification, may I know your sdk version as well?

Hi @amitysupport I am using amity_sdk: ^0.21.0.

I have made some improvement, now I can fetch the global post from different communities(which user has joined), but it is not sorted. I don’t see any option to sort it while fetching from amity server. Is it sorted with some other field?

Hello, unfortunately, our SDK does not currently offer an option to sort the global feed. Currently, our global feed is sorted based on engagement. For more information on how the custom post ranking works, please refer to this section in our documentation: Custom Post Ranking - Amity Docs

If you would like to have the feed sorted by chronological order, please reach out to our support team by sending an email to: support.asc@amity.co