Query Global Feed
Overview
The social.plus SDK provides two powerful approaches for retrieving global feed content: conventional chronological ordering and intelligent custom post ranking. This flexibility allows you to create the optimal content experience for your users based on your application’s specific needs.
Feed Query Methods
Conventional Global Feed Simple chronological ordering with the most recent posts appearing first. Perfect for real-time content streams.
Custom Post Ranking Intelligent content curation using engagement metrics, time decay, and update boosts for optimal user experience.
Conventional Global Feed Query
The getGlobalFeed method provides a straightforward way to query posts in chronological order, ensuring users see the most recent content first.
The system displays the 20 most recent posts per community in the global feed. Older posts may not be visible to optimize performance and relevance.
Implementation
iOS
Android
TypeScript
Flutter
Basic Global Feed Query
Advanced Global Feed with Pagination
import AmitySDK
class GlobalFeedManager {
private let feedRepository: AmityFeedRepository
private var feedCollection: AmityCollection<AmityPost> ?
private var feedToken: AmityNotificationToken ?
init () {
self . feedRepository = AmityFeedRepository ( client : AmityManager. shared . client ! )
}
func queryGlobalFeed () {
// Create global feed query
let query = feedRepository. getGlobalFeed ()
// Observe feed changes
feedToken = query. observe { [ weak self ] collection, _ , error in
if let error = error {
print ( "Global feed error: \( error. localizedDescription ) " )
return
}
self ? . feedCollection = collection
self ? . handleFeedUpdate ( posts : collection. allObjects ())
}
}
private func handleFeedUpdate ( posts : [AmityPost]) {
print ( "Global feed updated with \( posts. count ) posts" )
// Update UI with new posts
}
deinit {
feedToken ? . invalidate ()
}
}
Basic Global Feed Query
Advanced Global Feed with Pagination
import com.amity.socialcloud.sdk.AmityCoreClient
import com.amity.socialcloud.sdk.social.feed.AmityFeedRepository
import com.amity.socialcloud.sdk.social.post.AmityPost
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.schedulers.Schedulers
class GlobalFeedManager {
private val feedRepository: AmityFeedRepository = AmityCoreClient. newFeedRepository ()
private val compositeDisposable = CompositeDisposable ()
fun queryGlobalFeed () {
val disposable = feedRepository. getGlobalFeed ()
. build ()
. query ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. subscribe (
{ paginatedList ->
handleFeedUpdate (paginatedList. data )
},
{ error ->
handleError (error)
}
)
compositeDisposable. add (disposable)
}
private fun handleFeedUpdate (posts: List < AmityPost >) {
println ( "Global feed updated with ${ posts.size } posts" )
// Update UI with new posts
}
private fun handleError (error: Throwable ) {
println ( "Global feed error: ${ error.message } " )
}
fun dispose () {
compositeDisposable. dispose ()
}
}
Basic Global Feed Query
Advanced Global Feed with Pagination
import { FeedRepository , PostRepository , Post } from '@amityco/ts-sdk' ;
class GlobalFeedManager {
private feedRepository : FeedRepository ;
private postRepository : PostRepository ;
private unsubscribe ?: () => void ;
constructor () {
this . feedRepository = new FeedRepository ();
this . postRepository = new PostRepository ();
}
async queryGlobalFeed () : Promise < void > {
try {
// Query global feed
const { data : posts , hasNextPage , nextPage } = await this . feedRepository . getGlobalFeed ({
limit: 20 ,
includeDeleted: false
});
this . handleFeedUpdate ( posts );
// Setup real-time updates
this . unsubscribe = this . feedRepository . observeGlobalFeed (( updatedPosts ) => {
this . handleFeedUpdate ( updatedPosts );
});
} catch ( error ) {
this . handleError ( error );
}
}
private handleFeedUpdate ( posts : Post []) : void {
console . log ( `Global feed updated with ${ posts . length } posts` );
// Update UI with new posts
}
private handleError ( error : any ) : void {
console . error ( 'Global feed error:' , error . message );
}
dispose () : void {
if ( this . unsubscribe ) {
this . unsubscribe ();
}
}
}
Basic Global Feed Query
Advanced Global Feed with Pagination
import 'package:amity_sdk/amity_sdk.dart' ;
import 'dart:async' ;
class GlobalFeedManager {
late AmityFeedRepository _feedRepository;
StreamSubscription < AmityGlobalFeedPagingData > ? _feedSubscription;
GlobalFeedManager () {
_feedRepository = AmitySocialClient . newFeedRepository ();
}
void queryGlobalFeed () {
// Create global feed query
final query = _feedRepository. getGlobalFeed ()
. limit ( 20 )
. includeDeleted ( false );
// Subscribe to feed updates
_feedSubscription = query. getPagingData (). listen (
(pagingData) {
_handleFeedUpdate (pagingData.data);
},
onError : (error) {
_handleError (error);
},
);
}
void _handleFeedUpdate ( List < AmityPost > posts) {
print ( 'Global feed updated with ${ posts . length } posts' );
// Update UI with new posts
}
void _handleError ( dynamic error) {
print ( 'Global feed error: $ error ' );
}
void dispose () {
_feedSubscription ? . cancel ();
}
}
Custom Post Ranking Query
The getCustomRankingGlobalFeed method provides intelligent content curation using our advanced scoring algorithm. This approach considers engagement metrics, time decay, and content updates to surface the most relevant posts for each user.
Custom post ranking requires SDK version 5.10 or higher. Posts created with earlier versions will not participate in the ranking algorithm.
Implementation
iOS
Android
TypeScript
Flutter
Basic Custom Ranking Query
Advanced Custom Ranking with Analytics
import AmitySDK
class CustomRankingFeedManager {
private let feedRepository: AmityFeedRepository
private var feedCollection: AmityCollection<AmityPost> ?
private var feedToken: AmityNotificationToken ?
init () {
self . feedRepository = AmityFeedRepository ( client : AmityManager. shared . client ! )
}
func queryCustomRankingFeed () {
// Create custom ranking global feed query
let query = feedRepository. getCustomRankingGlobalFeed ()
feedToken = query. observe { [ weak self ] collection, _ , error in
if let error = error {
print ( "Custom ranking feed error: \( error. localizedDescription ) " )
return
}
self ? . feedCollection = collection
self ? . handleRankedFeedUpdate ( posts : collection. allObjects ())
}
}
private func handleRankedFeedUpdate ( posts : [AmityPost]) {
print ( "Custom ranking feed updated with \( posts. count ) ranked posts" )
// Posts are automatically sorted by engagement score
// Display posts in the order received for optimal user experience
}
deinit {
feedToken ? . invalidate ()
}
}
Basic Custom Ranking Query
Advanced Custom Ranking with Filtering
import com.amity.socialcloud.sdk.AmityCoreClient
import com.amity.socialcloud.sdk.social.feed.AmityFeedRepository
import com.amity.socialcloud.sdk.social.post.AmityPost
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.schedulers.Schedulers
class CustomRankingFeedManager {
private val feedRepository: AmityFeedRepository = AmityCoreClient. newFeedRepository ()
private val compositeDisposable = CompositeDisposable ()
fun queryCustomRankingFeed () {
val disposable = feedRepository. getCustomRankingGlobalFeed ()
. build ()
. query ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. subscribe (
{ paginatedList ->
handleRankedFeedUpdate (paginatedList. data )
},
{ error ->
handleError (error)
}
)
compositeDisposable. add (disposable)
}
private fun handleRankedFeedUpdate (posts: List < AmityPost >) {
println ( "Custom ranking feed updated with ${ posts.size } ranked posts" )
// Posts are automatically sorted by engagement score
// Display posts in the order received for optimal user experience
}
private fun handleError (error: Throwable ) {
println ( "Custom ranking feed error: ${ error.message } " )
}
fun dispose () {
compositeDisposable. dispose ()
}
}
Basic Custom Ranking Query
queryAllPosts Method (V6 & Beta)
import { FeedRepository , Post } from '@amityco/ts-sdk' ;
class CustomRankingFeedManager {
private feedRepository : FeedRepository ;
private unsubscribe ?: () => void ;
constructor () {
this . feedRepository = new FeedRepository ();
}
async queryCustomRankingFeed () : Promise < void > {
try {
// Query custom ranking global feed
const { data : posts , hasNextPage } = await this . feedRepository . getCustomRankingGlobalFeed ({
limit: 20 ,
includeDeleted: false
});
this . handleRankedFeedUpdate ( posts );
// Setup real-time updates for ranked content
this . unsubscribe = this . feedRepository . observeCustomRankingFeed (( updatedPosts ) => {
this . handleRankedFeedUpdate ( updatedPosts );
});
} catch ( error ) {
this . handleError ( error );
}
}
private handleRankedFeedUpdate ( posts : Post []) : void {
console . log ( `Custom ranking feed updated with ${ posts . length } ranked posts` );
// Posts are automatically sorted by engagement score
// Display posts in the order received for optimal user experience
}
private handleError ( error : any ) : void {
console . error ( 'Custom ranking feed error:' , error . message );
}
dispose () : void {
if ( this . unsubscribe ) {
this . unsubscribe ();
}
}
}
Basic Custom Ranking Query
Advanced Custom Ranking with Analytics
import 'package:amity_sdk/amity_sdk.dart' ;
import 'dart:async' ;
class CustomRankingFeedManager {
late AmityFeedRepository _feedRepository;
StreamSubscription < AmityCustomRankingFeedPagingData > ? _feedSubscription;
CustomRankingFeedManager () {
_feedRepository = AmitySocialClient . newFeedRepository ();
}
void queryCustomRankingFeed () {
// Create custom ranking global feed query
final query = _feedRepository. getCustomRankingGlobalFeed ()
. limit ( 20 )
. includeDeleted ( false );
// Subscribe to ranked feed updates
_feedSubscription = query. getPagingData (). listen (
(pagingData) {
_handleRankedFeedUpdate (pagingData.data);
},
onError : (error) {
_handleError (error);
},
);
}
void _handleRankedFeedUpdate ( List < AmityPost > posts) {
print ( 'Custom ranking feed updated with ${ posts . length } ranked posts' );
// Posts are automatically sorted by engagement score
// Display posts in the order received for optimal user experience
}
void _handleError ( dynamic error) {
print ( 'Custom ranking feed error: $ error ' );
}
void dispose () {
_feedSubscription ? . cancel ();
}
}
Key Features & Capabilities
Both conventional and custom ranking feeds support real-time updates, ensuring users see new content as it becomes available without manual refresh.
Custom ranking queries provide detailed analytics about post engagement, ranking performance, and user interaction patterns.
Configure minimum engagement scores, include/exclude deleted posts, and apply various filters to customize the feed experience.
Pagination Best Practices
Use appropriate page sizes (20-50 posts)
Implement lazy loading for optimal performance
Cache results when possible
Handle pagination state properly
Real-time Updates
Subscribe to feed updates for live content
Handle network reconnection gracefully
Implement proper memory management
Dispose of subscriptions when done
Error Handling
Common Error Scenarios
Recovery Strategies
iOS Error Handling
Android Error Handling
TypeScript Error Handling
Flutter Error Handling
func handleFeedError ( _ error : Error ) {
if let amityError = error as? AmityError {
switch amityError {
case . networkError :
showNetworkErrorMessage ()
case . permissionDenied :
showPermissionErrorMessage ()
case . rateLimitExceeded :
showRateLimitMessage ()
default :
showGenericErrorMessage ()
}
}
}
Network Errors
Implement retry logic with exponential backoff for network-related failures
Permission Errors
Guide users to proper authentication or contact support for access issues
Rate Limiting
Display appropriate messaging and implement automatic retry after cooldown period
Data Corruption
Clear local cache and reinitialize feed repository if data appears corrupted
Best Practices
Query Optimization
Choose appropriate query type based on use case
Set reasonable page limits
Use custom ranking for engagement-focused feeds
Implement proper caching strategies
User Experience
Provide loading states during queries
Handle empty states gracefully
Implement pull-to-refresh functionality
Show appropriate error messages
JavaScript/TypeScript queryAllPosts Method
For JavaScript and TypeScript applications, you can use the queryAllPosts method with custom ranking enabled:
JavaScript Implementation
TypeScript Implementation
import { PostRepository } from '@amityco/js-sdk' ;
class GlobalFeedWithRanking {
constructor () {
this . postRepository = new PostRepository ();
}
async queryGlobalFeedWithRanking () {
try {
const posts = await this . postRepository . queryAllPosts ({
customRanking: true ,
limit: 20 ,
includeDeleted: false
});
this . handleRankedPosts ( posts );
return posts ;
} catch ( error ) {
this . handleQueryError ( error );
throw error ;
}
}
handleRankedPosts ( posts ) {
console . log ( `Retrieved ${ posts . length } ranked posts` );
// Posts are sorted by engagement score
}
handleQueryError ( error ) {
console . error ( 'Query error:' , error . message );
// The queryAllPosts method will throw an error if parameters are incorrect
if ( error . message . includes ( 'parameters' )) {
console . error ( 'Please check your query parameters' );
}
}
}
The queryAllPosts method will throw an error if incorrect parameters are passed. Always validate your parameters and handle errors appropriately.