Reactions - GetStream/stream-swift GitHub Wiki

Add reactions

// add a like reaction to the activity with id activityId
Client.shared.add(reactionTo: activityId, kindOf: "like") { result in /* ... */ }

// adds a comment reaction to the activity with id activityId
Client.shared.add(reactionTo: activityId, kindOf: "comment", extraData: Comment(text: "awesome post!"), userTypeOf: User.self) { result in /* ... */ }

Here's a complete example:

// first let's read current user's timeline feed and pick one activity
Client.shared.flatFeed(feedSlug: "timeline", userId: "mike").get { result in
    if let response = try? result.get(), let activity = response.results.first, let activityId = activity.id {
        // then let's add a like reaction to that activity
        // note: `.like` is a shared extension for `ReactionKind` equal to "like".
        Client.shared.add(reactionTo: activityId, kindOf: .like) { result in
            print(result) // will print a reaction object in the result.
        }
    }
}

Notify other feeds

// adds a comment reaction to the activity and notifies Thierry's notification feed
Client.shared.add(reactionTo: activityId, 
                  kindOf: "comment", 
                  extraData: Comment(text: "awesome post!"),
                  userTypeOf: User.self,
                  targetsFeedIds: [FeedId(feedSlug: "notification", userId: "thierry")]) { result in /* ... */ }

Read feeds with reactions

// read bob's timeline and include most recent reactions to all activities and their total count
Client.shared.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.shared.flatFeed(feedSlug: "timeline", userId: "bob")
    .get(includeReactions: [.own, .latest, .counts]) { result in /* ... */ }

Retrieving reactions

// retrieve all kind of reactions for an activity
Client.shared.reactions(forActivityId: "ed2837a6-0a3b-4679-adc1-778a1704852d") { result in /* ... */ }

// retrieve first 10 likes for an activity
Client.shared.reactions(forActivityId: "ed2837a6-0a3b-4679-adc1-778a1704852d",
                        kindOf: "like",
                        pagination: .limit(10)) { result in /* ... */ }

// retrieve the next 10 likes using the id_lt param
Client.shared.reactions(forActivityId: "ed2837a6-0a3b-4679-adc1-778a1704852d",
                        kindOf: "like",
                        pagination: .lessThan("e561de8f-00f1-11e4-b400-0cc47a024be0")) { result in /* ... */ }

Child reactions

// add a like reaction to the previously created comment
Client.shared.add(reactionToParentReaction: commentReaction, kindOf: "like") { result in /* ... */ }

Updating Reactions

Client.shared.update(reactionId: reactionId, extraData: Comment(text: "love it!"), userTypeOf: User.self) { result in /* ... */ }

Removing Reactions

Client.shared.delete(reactionId: reactionId) { result in /* ... */ }