Feed & Timeline

Let your users showcase their unique personality right in their timelines

Feed is a great way for users to get relevant updates, communicate and express themselves via algorithmically ranked content.

Each feed consists of a collection of posts. Users will be able to create posts on any groups that they are a member of and any user that they can find.

There is also a global feed which is an aggregate of all the posts in a user's feed.

Feed management methods are all contained in EkoFeedRepository class.

let feedRepository = EkoFeedRepository(client: client)

Query User Feed

Querying for feed fetches your posts in your own feed or other user's feed. You can also sort the posts by lastCreated or firstCreated timestamp. EkoUserFeedSortOption enum provides both sort options which you can provide as argument while fetching feed.

EkoFeedRepository class exposes two convenient methods getMyFeedSortedBy(_:) and getUserFeed(_:) to query for your own feed and other user's feed respectively. getUserFeed(_:) method requires an additional parameter userId.

let feedToken: EkoNotificationToken?

...

let feedCollection = feedRepository.getUserFeed(userId, sortBy: .lastUpdated, includeDeleted: false)
feedToken = feedCollection.observe({ (collection, _, error) in
    // React to changes here
})

There is a quick easy method to get your own feed:

let feedCollection = feedRepository.getMyFeedSorted(by: .lastUpdated, includeDeleted: false)
feedToken = feedCollection.observe({ (collection, _, error) in
    // React to changes here
})

Live Collection for feed provides max 20 posts per each page. You can easily fetch more posts by using nextPage() method from the same live collection.

if feedCollection.hasNext { 
   // Fetches more posts from server and appends it to the same collection
   feedCollection.nextPage()
}

Query Group Feed

You can get any group's feed by calling the method below with the communityId. Fetching more posts for Group Feed is same as User Feed.

let feedCollection = feedRepository.getCommunityFeed(withCommunityId: "community-id", sortBy: .lastCreated, includeDeleted: false)

feedToken = feedCollection.observe({(collection, change, error) in
    // Observer is called once object is received
})

Query Global Feed

You can retrieve your global feed by calling the following method.

let feedCollection = feedRepo.getGlobalFeed()

feedToken = feedCollection.observe({(collection, change, error) in
    // Observer is called once object is received
})

Fetching more posts in global feed is same as User Feed.

Last updated