// read bob's timeline and include most recent reactions to all activities and their total count
await client.Feed("timeline", "bob").GetEnrichedFlatActivitiesAsync(GetOptions.Default.WithReaction(ReactionOption.With().Recent().Counts()));
// read bob's timeline and include most recent reactions to all activities and her own reactions
await client.Feed("timeline", "bob").GetEnrichedFlatActivitiesAsync(GetOptions.Default.WithReaction(ReactionOption.With().Recent().Own()));
Reactions and Feeds
Read Feeds with Reactions
When using reactions, it is possible to request enriched activities that include both attached reactions by type and reaction counters.
Listed below are the parameters for retrieving reactions.
The “recent” parameter includes up to 5 of the most recent reactions per type
Parameters
name | type | description | default | optional |
---|---|---|---|---|
recent | boolean | Include the 5 most recent reactions to activities per type. | - | ✓ |
own | boolean | Include the current user’s reaction to activities. | - | ✓ |
counts | boolean | Include the total count of reaction (by kind) to activities. | - | ✓ |
user_id | string | Filter reactions to specific user. | - | ✓ |
// read bob's timeline and include most recent reactions to all activities and their total count
client.feed('timeline', 'bob').get({
reactions: { recent: true, counts: true }
});
// read bob's timeline and include most recent reactions to all activities and her own reactions
client.feed('timeline', 'bob').get({
reactions: { own: true, recent: true, counts: true }
});
# read bob's timeline and include most recent reactions to all activities and their total count
client.feed("timeline", "bob").get(reactions={"recent": True, "counts": True})
# read bob's timeline and include most recent reactions to all activities and her own reactions
client.feed("timeline", "bob").get(
reactions={"own": True, "recent": True, "counts": True}, user_id="bob"
)
# read bob's timeline and include most recent reactions to all activities and their total count
client.feed("timeline", "bob").get(reactions: {recent: true, counts: true})
# read bob's timeline and include most recent reactions to all activities and her own reactions
client.feed("timeline", "bob").get(
reactions: {own: true, recent: true, counts: true},
user_id: "bob"
)
// read bob's timeline and include most recent reactions to all activities and their total count
$client->feed("timeline", "bob")->getActivities(0, 5, null, true, ["recent"=>true, "counts"=>true]);
// read bob's timeline and include most recent reactions to all activities and her own reactions by passing the user_id in the `options` array
$client->feed("timeline", "bob")->getActivities(0, 5, ["user_id" => "bob"], true, ["recent"=>true, "counts"=>true]);
// read bob's timeline and include most recent reactions to all activities and their total count
client.flatFeed("timeline", "bob")
.getEnrichedActivities(new EnrichmentFlags()
.withRecentReactions()
.withReactionCounts()).get();
// read bob's timeline and include most recent reactions to all activities and her own reactions
client.flatFeed("timeline", "bob")
.getEnrichedActivities(new EnrichmentFlags()
.withOwnReactions()
.withRecentReactions()
.withReactionCounts()).get();
// read bob's timeline and include most recent reactions to all activities and their total count
opts := []stream.GetActivitiesOption{
stream.WithEnrichRecentReactions(),
stream.WithEnrichReactionCounts(),
}
resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
if err != nil {
panic(err)
}
// read bob's timeline and include most recent reactions to all activities and his own reactions
opts = []stream.GetActivitiesOption{
stream.WithEnrichOwnReactions(),
stream.WithEnrichRecentReactions(),
stream.WithEnrichReactionCounts(),
}
resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
if err != nil {
panic(err)
}
// read bob's timeline and include reactions from john
opts = []stream.GetActivitiesOption{
stream.WithEnrichOwnReactions(),
stream.WithEnrichUserReactions("john"),
}
resp, err := feed.GetEnrichedActivities(context.TODO(), opts...)
if err != nil {
panic(err)
}
// read bob's timeline and include most recent reactions to all activities and their total count
client.flatFeed(feedSlug: "timeline", userId: "bob")
.get(includeReactions: [.latest, .counts]) { result in /* ... */ }
// read bob's timeline and include most recent reactions to all activities and her own reactions
client.flatFeed(feedSlug: "timeline", userId: "bob")
.get(includeReactions: [.own, .latest, .counts]) { result in /* ... */ }
// read bob's timeline and include most recent reactions to all activities and their total count
client.flatFeed('timeline', 'bob').getEnrichedActivities(
flags: EnrichmentFlags().withRecentReactions().withReactionCounts(),
);
// read bob's timeline and include most recent reactions to all activities and her own reactions
client.flatFeed('timeline', 'bob').getEnrichedActivities(
flags: EnrichmentFlags().withRecentReactions().withReactionCounts(),
);
Notify Other Feeds
When adding a reaction, you can use the target_feeds
parameter to notify a list of users about the new reaction. When specified, all targeted feeds will receive an activity containing a reference to the reaction.
// adds a comment reaction to the activity and notifies Thierry's notification feed
var reactionData = new Dictionary<string, object="">()
{
{ "text", "@thierry great post!"},
};
var feedsToNotify = new[] { "notification:thierry" };
await client.Reactions.AddAsync("comment", activityId, "bob", reactionData, feedsToNotify);
// adds a comment reaction to the activity and notifies Thierry's notification feed
client.reactions.add("comment", activityId,
{ text: "@thierry great post!" },
{ targetFeeds: ["notification:thierry"] }
);
//adds a like reaction to the activity and notifies Thierry's notification feed
client.reactions.add("like", activityId,
{ },
{ targetFeeds: ["notification:thierry"] }
);
# adds a comment reaction to the activity and notifies Thierry's notification feed
client.reactions.add(
"comment",
activity_id,
user_id="mike",
data={"text": "@thierry great post!"},
target_feeds=["notification:thierry"],
)
# adds a comment reaction to the activity and notifies Thierry's notification feed
client.reactions.add(
"comment",
activity_id,
"mike",
data: {text: "@thierry great post!"},
target_feeds: ["notification:thierry"],
)
// adds a comment reaction to the activity and notifies Thierry's notification feed
$client->reactions()->add(
"comment",
$activity_id,
"mike",
["text" => "@thierry great post!"],
["notification:thierry"],
);
Reaction comment = new Reaction.Builder()
.kind("comment")
.activityID(activity.getID())
.extraField("text", "@thierry great post!")
.build();
// adds a comment reaction to the activity and notifies Thierry's notification feed
client.reactions().add("john-doe", comment, new FeedID("notification:thierry")).join();
// adds a comment reaction to the activity and notifies Thierry's notification feed
r := stream.AddReactionRequestObject{
Kind: "comment",
ActivityID: activityID,
UserID: "bob",
Data: map[string]any{
"text": "@thierry great post!",
},
TargetFeeds: []string{"notification:thierry"},
}
resp, err := client.Reactions().Add(context.TODO(), r)
if err != nil {
panic(err)
}
// adds a comment reaction to the activity and notifies Thierry's notification feed
client.add(reactionTo: activityId,
kindOf: "comment",
extraData: Comment(text: "@thierry great post!"),
targetsFeedIds: [FeedId(feedSlug: "notification", userId: "thierry")]) { result in /* ... */ }
// adds a comment reaction to the activity and notifies Thierry's notification feed
client.reactions.add(
'comment', '5de5e4ba-add2-11eb-8529-0242ac130003',
data: {'text': "@thierry great post!"},
targetFeeds: [FeedId.id('notification:thierry')]);
The targetFeeds
field is limited to a maximum of 20 targets per API request.