Activity Feeds V3 is in closed alpha — do not use it in production (just yet).

Comments

Overview

Comments support voting, ranking, threading, images, URL previews, mentions and notifications.

Adding Comments

// Adding a comment to an activity
val comment: Result<CommentData> = feed.addComment(
    request = ActivityAddCommentRequest(
        comment = "So great!",
        custom = mapOf("sentiment" to "positive"),
        activityId = "activity_123"
    )
)

// Adding a reply to a comment
val reply: Result<CommentData> = feed.addComment(
    request = ActivityAddCommentRequest(
        comment = "I agree!",
        activityId = "activity_123",
        parentId = "comment_456"
    )
)

Updating Comments

feed.updateComment(
    commentId = "comment_123",
    request = UpdateCommentRequest(
        comment = "Not so great",
        custom = mapOf("edited" to true)
    )
)

Removing Comments

feed.deleteComment(commentId = "comment_123")

Reading Comments

You’ll also want to show/return these comments. The most important is when reading the feed.

feed.getOrCreate()
feed.state.activities.collect { it.first().comments }
// or
val activity = client.activity(
    activityId = "activity_123",
    fid = FeedId(group = "user", id = "john")
)
activity.get()
activity.state.comments

Querying Comments

You can also query the comments so you can show all comments for a given activity or user:

// Search in comment texts
val list1 = client.commentList(
    query = CommentsQuery(
        filter = Filters.query("comment_text", "oat")
    )
)
val comments1: Result<List<CommentData>> = list1.get()

// All comments for an activity
val list2 = client.commentList(
    query = CommentsQuery(
        filter = Filters.and(
            Filters.equal("object_id", "activity_123"),
            Filters.equal("object_type", "activity")
        )
    )
)
val comments2: Result<List<CommentData>> = list2.get()

// Replies to a parent activity
val list3 = client.commentList(
    query = CommentsQuery(
        filter = Filters.equal("parent_id", "parent_id")
    )
)
val comments3: Result<List<CommentData>> = list3.get()

// Comments from a user
val list4 = client.commentList(
    query = CommentsQuery(
        filter = Filters.equal("user_id", "jane")
    )
)
val comments4: Result<List<CommentData>> = list4.get()

Comment Reactions

// Add a reaction to a comment
feed.addCommentReaction(
    commentId = "comment_123",
    request = AddCommentReactionRequest(type = "like")
)

// Remove a reaction from a comment
feed.deleteCommentReaction(
    commentId = "comment_123",
    type = "like"
)

Comment Threading

val commentList = client.activityCommentList(
    query = ActivityCommentsQuery(
        objectId = "activity_123",
        objectType = "activity",
        depth = 3,
        limit = 20
    )
)
val comments: Result<List<ThreadedCommentData>> = commentList.get()

// Get replies of a specific parent comment
val replyList = client.commentReplyList(
    query = CommentRepliesQuery(
        commentId = "parent_123"
    )
)
val replies: Result<List<ThreadedCommentData>> = replyList.get()
© Getstream.io, Inc. All Rights Reserved.