// Follow a user
let timeline = client.feed(group: "timeline", id: "john")
_ = try await timeline.follow(FeedId(group: "user", id: "tom"))
// Follow a stock
_ = try await timeline.follow(FeedId(group: "stock", id: "apple"))
// Follow with more fields
_ = try await timeline.follow(
FeedId(group: "stock", id: "apple"),
custom: ["reason": "investment"]
)
Activity Feeds V3 is in closed alpha — do not use it in production (just yet).
Follows
Follow & Unfollow
const timeline = client.feed("timeline", "john");
await timeline.getOrCreate();
// Follow a user
await timeline.follow("user:tom");
// Follow a stock
await timeline.follow("stock:apple");
// Follow with more fields
await timeline.follow("stock:apple", {
push_preference: "all",
custom: {
reason: "investment",
},
});
const timeline = client.feeds.feed("timeline", "john");
await timeline.getOrCreate({
user_id: "john",
});
// Follow a user
await client.feeds.follow({
source: timeline.fid,
target: "user:tom",
});
// Follow a stock
await client.feeds.follow({
source: timeline.fid,
target: "stock:apple",
});
// Follow with more fields
await client.feeds.follow({
source: timeline.fid,
target: "stock:apple",
push_preference: "all",
custom: {
reason: "investment",
},
});
Querying Follows
// All my follows
let allQuery = FollowsQuery(
filter: .equal(.userId, "me"),
limit: 20
)
let allFollowList = client.followList(for: allQuery)
let allFollowsPage1 = try await allFollowList.get()
// Do I follow a list of feeds
// My feed is timeline:john
let followQuery = FollowsQuery(
filter: .and([
.equal(.sourceFeed, "timeline:john"),
.in(.targetFeed, ["user:sara", "user:adam"])
])
)
let followList = client.followList(for: followQuery)
let page1 = try await followList.get()
let page2 = try await followList.queryMoreFollows()
let page1And2 = followList.state.follows
// Paginating through followers for a feed
// My feed is timeline:john
let followerQuery = FollowsQuery(
filter: .equal(.targetFeed, "timeline:john")
)
let followerList = client.followList(for: followerQuery)
let followerPage1 = try await followerList.get()
const myTimeline = client.feed("timeline", "john");
await myTimeline.getOrCreate();
// Do I follow a list of feeds
const response = await client.queryFollows({
filter: {
source_feed: myTimeline.fid,
target_feed: { $in: ["user:sara", "user:adam"] },
},
});
console.log(response.follows);
const userFeed = client.feeds.feed("user", "john");
await userFeed.getOrCreate();
// Paginating through followers for a feed
const firstPage = await userFeed.queryFollowers({
limit: 20,
});
// Next page
const secondPage = await userFeed.queryFollowers({
limit: 20,
next: firstPage.next,
});
// or load when reading feed
await feed.getOrCreate({
follower_pagination: {
limit: 10,
},
});
// and then load next pages
await feed.loadNextPageFollowers();
console.log(feed.state.getLatestValue().followers);
// Filter by source - feeds that I follow
await myTimeline.queryFollowing();
// or load when reading feed
await feed.getOrCreate({
following_pagination: {
limit: 10,
},
});
// and then load next pages
await feed.loadNextPageFollowing();
console.log(feed.state.getLatestValue().following);
const myTimeline = client.feeds.feed("timeline", "john");
await myTimeline.getOrCreate({
user_id: "john",
});
// Do I follow a list of feeds
const response = await client.feeds.queryFollows({
filter: {
source_feed: myTimeline.fid,
target_feed: { $in: ["user:sara", "user:adam"] },
},
});
console.log(response.follows);
const userFeed = client.feeds.feed("user", "john");
await userFeed.getOrCreate({
user_id: "john",
});
// Paginating through followers for a feed
const firstPage = await client.feeds.queryFollows({
filter: { target_feed: userFeed.fid },
limit: 20,
});
// Next page
const secondPage = await client.feeds.queryFollows({
filter: { target_feed: userFeed.fid },
limit: 20,
next: firstPage.next,
});
// Filter by source - feeds that I follow
await client.feeds.queryFollows({
filter: { source_feed: myTimeline.fid },
limit: 20,
});
Follow Requests
Some apps require the user’s approval for following them.
// See if a feed needs a request for follow
let feed = client.feed(group: "user", id: "amber")
let feedData = try await feed.getOrCreate()
if feedData.visibility == "followers" {
// We need to request a follow
}
// Request to follow this feed
let timeline = client.feed(group: "timeline", id: "john")
try await timeline.follow(FeedId(group: "user", id: "amber"))
// Accept
try await feed.acceptFollow(.init(group: "timeline", id: "john"))
// or reject the follow
try await feed.rejectFollow(.init(group: "timeline", id: "john"))
const saraFeed = saraClient.feed("user", uuidv4());
await saraFeed.getOrCreate({
// You need to set followers visibility to have follow requests
data: { visibility: "followers" },
});
const adamTimeline = adamClient.feed("timeline", uuidv4());
await adamTimeline.getOrCreate();
const followRequest = await adamTimeline.follow(saraFeed.fid);
console.log(followRequest.follow.status); // pending
await saraClient.acceptFollow({
source_fid: adamTimeline.fid,
target_fid: saraFeed.fid,
// Optionally provide role
follower_role: "feed_member",
});
await saraClient.rejectFollow({
source_fid: adamTimeline.fid,
target_fid: saraFeed.fid,
});
const saraFeed = client.feeds.feed("user", uuidv4());
await saraFeed.getOrCreate({
// You need to set followers visibility to have follow requests
data: { visibility: "followers" },
user_id: 'sara'
});
const adamTimeline = client.feeds.feed("timeline", uuidv4());
await adamTimeline.getOrCreate({
user_id:
});
const followRequest = await client.feeds.follow({
source: adamTimeline.fid,
target: saraFeed.fid,
});
console.log(followRequest.follow.status); // pending
await client.feeds.acceptFollow({
source_fid: adamTimeline.fid,
target_fid: saraFeed.fid,
// Optionally provide role
follower_role: "feed_member",
});
await client.feeds.rejectFollow({
source_fid: adamTimeline.fid,
target_fid: saraFeed.fid,
});
On this page: