// Adding a comment to an activity
let comment = try await feed.addComment(
request: .init(
comment: "So great!",
custom: ["sentiment": "positive"],
objectId: "activity_123",
objectType: "activity",
)
)
// Adding a reply to a comment
let reply = try await feed.addComment(
request: .init(
comment: "I agree!",
objectId: "activity_123",
objectType: "activity",
parentId: "comment_456"
)
)
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
await client.addComment({
comment: "So great!",
object_id: "activity_123",
object_type: "activity",
custom: {
sentiment: "positive",
},
});
// Adding a reply to a comment
await client.addComment({
comment: "I agree!",
object_id: "activity_123",
object_type: "activity",
parent_id: "comment_456",
});
// Adding a comment to an activity
await serverClient.feeds.addComment({
comment: "So great!",
object_id: "activity_123",
object_type: "activity",
user_id: "<user_id>",
custom: {
sentiment: "positive",
},
});
// Adding a reply to a comment
await serverClient.feeds.addComment({
comment: "I agree!",
object_id: "activity_123",
object_type: "activity",
parent_id: "comment_456",
user_id: "<user_id>",
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Adding a comment to an activity
comment, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: "So great!",
ObjectID: getstream.PtrTo("activity_123"),
ObjectType: "activity",
Custom: map[string]interface{}{
"sentiment": "positive",
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comment added: %+v", comment.Data)
// Adding a reply to a comment
reply, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: "I agree!",
ObjectID: getstream.PtrTo("activity_123"),
ObjectType: "activity",
ParentID: getstream.PtrTo("comment_456"),
})
if err != nil {
log.Fatal(err)
}
log.Printf("Reply added: %+v", reply.Data)
}
Updating Comments
try await feed.updateComment(
commentId: "comment_123",
request: .init(
comment: "Not so great",
custom: ["edited": true]
)
)
// Update a comment
await client.updateComment({
comment_id: "comment_123",
comment: "Updated comment",
custom: {
edited: true,
},
});
// Update a comment
await client.feeds.updateComment({
comment_id: "comment_123",
comment: "Updated comment",
custom: {
edited: true,
},
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Update a comment
updateResponse, err := feedsClient.UpdateComment(ctx, "comment_123", &getstream.UpdateCommentRequest{
Comment: getstream.PtrTo("Updated comment"),
Custom: map[string]interface{}{
"edited": true,
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comment updated: %+v", updateResponse.Data)
}
Removing Comments
try await feed.deleteComment(
commentId: "comment_123"
)
client.deleteComment({
comment_id: "comment_123",
});
client.feeds.deleteComment({
comment_id: "comment_123",
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Delete a comment
deleteResponse, err := feedsClient.DeleteComment(ctx, "comment_123")
if err != nil {
log.Fatal(err)
}
log.Printf("Comment deleted: %+v", deleteResponse)
}
Reading Comments
You’ll also want to show/return these comments. The most important is when reading the feed.
try await feed.getOrCreate()
print(feed.state.activities[0].comments)
// or
let activity = client.activity(
for: "activity_123",
in: FeedId(group: "user", id: "john")
)
try await activity.get()
print(activity.state.comments)
await feed.getOrCreate();
const activity = feed.state.getLatestValue().activities?.[0]!;
// Supported values for sort: first, last, top, controversial, best
// Loads the activity comments (first or next page) and stores them in feed state
await feed.loadNextPageActivityComments(activity, { sort: 'best' });
// To read comments without storing them in feed state
const response = client.getComments({
object_type: "activity",
object_id: "123",
limit: 10,
sort: "best",
});
const response = feed.getOrCreate({
user_id: "<user id>",
});
console.log(response.activities[0].comments);
// Or using the getComments endpoint
const comments = await client.feeds.getComments({
object_type: "activity",
object_id: "123",
limit: 10,
sort: "best",
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Get feed with comments included
feed := feedsClient.Feed("user", "john")
feedResponse, err := feed.GetOrCreate(ctx, &getstream.GetOrCreateFeedRequest{
UserID: getstream.PtrTo("<user id>"),
})
if err != nil {
log.Fatal(err)
}
// Access comments from activities
if len(feedResponse.Data.Activities) > 0 {
activity := feedResponse.Data.Activities[0]
log.Printf("Activity comments: %+v", activity.Comments)
}
// Or using the getComments endpoint directly
comments, err := feedsClient.GetComments(ctx, &getstream.GetCommentsRequest{
ObjectType: "activity",
ObjectID: "123",
Limit: getstream.PtrTo(10),
Sort: getstream.PtrTo("best"), // first, last, top, controversial, best
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comments: %+v", comments.Data.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
let list1 = client.commentList(
for: .init(
filter: .query(.commentText, "oat")
)
)
let comments1 = try await list1.get()
// All comments for an activity
let list2 = client.commentList(
for: .init(
filter: .and([
.equal(.objectId, "activity_123"),
.equal(.objectType, "activity")
])
)
)
let comments2 = try await list2.get()
// Replies to a parent activity
let list3 = client.commentList(
for: .init(
filter: .equal(.parentId, "parent_id")
)
)
let comments3 = try await list3.get()
// Comments from an user
let list4 = client.commentList(
for: .init(
filter: .equal(.userId, "jane")
)
)
let comments4 = try await list4.get()
// Search in comment texts
await client.queryComments({
filter: { comment_text: { $q: "oat" } },
});
// All comments for an activity
await client.queryComments({
filter: { object_id: "activity_123", object_type: "activity" },
});
// Replies to a parent acitivity
await client.queryComments({
filter: { parent_id: "<parent id>" },
});
await client.queryComments({
filter: {
user_id: jane.id,
},
limit: 20,
});
// Search in comment texts
await client.feeds.queryComments({
filter: { comment_text: { $q: "oat" } },
});
// All comments for an activity
await client.feeds.queryComments({
filter: { object_id: "activity_123", object_type: "activity" },
});
// Replies to a parent acitivity
await client.feeds.queryComments({
filter: { parent_id: "<parent id>" },
});
await client.feeds.queryComments({
filter: {
user_id: jane.id,
},
limit: 20,
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Search in comment texts
searchResponse, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"comment_text": map[string]interface{}{"$q": "oat"},
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Search results: %+v", searchResponse.Data.Comments)
// All comments for an activity
activityCommentsResponse, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"object_id": "activity_123",
"object_type": "activity",
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Activity comments: %+v", activityCommentsResponse.Data.Comments)
// Replies to a parent activity
repliesResponse, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"parent_id": "<parent id>",
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comment replies: %+v", repliesResponse.Data.Comments)
// Comments from a specific user
userCommentsResponse, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"user_id": "jane",
},
Limit: getstream.PtrTo(20),
})
if err != nil {
log.Fatal(err)
}
log.Printf("User comments: %+v", userCommentsResponse.Data.Comments)
}
Comment Reactions
// Add a reaction to a comment
try await feed.addCommentReaction(
commentId: "comment_123",
request: .init(type: "like")
)
// Remove a reaction from a comment
try await feed.deleteCommentReaction(
commentId: "comment_123",
type: "like"
)
// Add a reaction to a comment
const response = await client.addCommentReaction({
comment_id: "comment_123",
type: "like",
});
await client.deleteCommentReaction({
comment_id: "comment_123",
type: "like",
});
// Add a reaction to a comment
const response = await client.feeds.addCommentReaction({
comment_id: "comment_123",
type: "like",
user_id: "<user id>",
});
await client.feeds.deleteCommentReaction({
comment_id: "comment_123",
type: "like",
user_id: "<user id>",
});
package main
import (
"context"
"log"
"github.com/GetStream/getstream-go/v3"
)
func main() {
client, err := getstream.NewClient("<your_api_key>", "<your_api_secret>")
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
feedsClient := client.Feeds()
// Add a reaction to a comment
addReactionResponse, err := feedsClient.AddCommentReaction(ctx, "comment_123", &getstream.AddCommentReactionRequest{
Type: "like",
UserID: getstream.PtrTo("<user id>"),
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comment reaction added: %+v", addReactionResponse.Data)
// Delete a reaction from a comment
deleteReactionResponse, err := feedsClient.DeleteCommentReaction(ctx, "comment_123", &getstream.DeleteCommentReactionRequest{
Type: "like",
UserID: getstream.PtrTo("<user id>"),
})
if err != nil {
log.Fatal(err)
}
log.Printf("Comment reaction deleted: %+v", deleteReactionResponse)
}
Comment Threading
let commentList = client.activityCommentList(
for: .init(
objectId: "activity_123",
objectType: "activity",
depth: 3,
limit: 20
)
)
let comments = try await commentList.get()
// Get replies of a specific parent comment
let replyList = client.commentReplyList(
for: .init(
commentId: "parent_123"
)
)
let replies = try await replyList.get()
await feed.getOrCreate();
// To store comments in feed state you can use the loadNextPageActivityComments and loadNextPageCommentReplies
const activity = feed.state.getLatestValue().activities?.[0]!;
await feed.loadNextPageActivityComments(activity, { limit: 20 });
const commentState =
feed.state.getLatestValue()?.comments_by_entity_id[activity.id];
const parentComment = commentState?.comments?.[0]!;
const firstPageOfReplies =
feed.state.getLatestValue()?.comments_by_entity_id[parentComment?.id];
// Load next page of replies (or first, if replies aren't yet initialized)
feed.loadNextPageCommentReplies(parentComment);
// To read comments without storing them in state use getComments and getCommentReplies
const response = client.getComments({
object_id: 'activity_123',
object_type: 'activity',
// Depth of the threaded comments
depth: 3,
limit: 20,
});
// Get replies of a specific parent comment
const response = client.getCommentReplies({
comment_id: '<parent id>',
});
const response = client.feeds.getComments({
object_id: "activity_123",
object_type: "activity",
// Depth of the threaded comments
depth: 3,
limit: 20,
});
// Get replies of a specific parent comment
const response = client.feeds.getCommentReplies({
comment_id: "<parent id>",
});
- I'm working with the Stream Feeds React Native SDK and would like to ask questions about this documentation page: https://getstream.io/activity-feeds/docs/react-native/comments.md
- View as markdown
- Open in ChatGPT
- Open in Claude