Reactions and Feeds

Last Edit: Apr 04 2020

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.

Parameters

Name Type Description Default Optional
recent boolean Include the 10 most recent reactions to activities. -
own boolean Include the current user's reaction to activities. -
counts boolean Include the total count of reaction (by kind) to activities. -

// 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(),
}
client.FlatFeed("timeline", "bob").GetEnrichedActivities(opts...)

// read bob's timeline and include most recent reactions to all activities and her own reactions
opts := []stream.GetActivitiesOption{
	stream.WithEnrichOwnReactions(),
	stream.WithEnrichRecentReactions(),
	stream.WithEnrichReactionCounts(),
}
client.FlatFeed("timeline", "bob").GetEnrichedActivities(opts...)
                    

// 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
await client.Feed("timeline", "bob").GetEnrichedFlatActivities(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").GetEnrichedFlatActivities(GetOptions.Default.WithReaction(ReactionOption.With().Recent().Own()));
                    

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
client.reactions.add("comment", activityId, 
  { text: "@thierry great post!" },
  { 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, 
    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",
    ["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]interface{}{
		"text": "@thierry great post!",
	},
	TargetFeeds: []string{"notification:thierry"},
}
result, err := client.Reactions().Add(r)
                    

// 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
var reactionData = new Dictionary<string, object="">()
{
    { "text", "@thierry great post!"},
};
var feedsToNotify = new string[] { "notification:thierry" };
await client.Reactions.Add("comment", activityId, "bob", reactionData, feedsToNotify);</string,>