// 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
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"
)
)
// 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>",
});
response, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: "This is a test comment from Go SDK",
ObjectID: activityID,
ObjectType: "activity",
UserID: &testUserID,
})
AddCommentRequest commentRequest =
AddCommentRequest.builder()
.comment("This is a test comment from Java SDK")
.objectID(activityId)
.objectType("activity")
.userID(testUserId)
.build();
AddCommentResponse response = feeds.addComment(commentRequest).execute().getData();
$response = $this->feedsV3Client->addComment(
new GeneratedModels\AddCommentRequest(
comment: 'This is a test comment from PHP SDK',
objectID: $activityId,
objectType: 'activity',
userID: $this->testUserId
)
);
var response = await _feedsV3Client.AddCommentAsync(
new AddCommentRequest
{
Comment = "This is a test comment from .NET SDK",
ObjectID = activityId,
ObjectType = "activity",
UserID = _testUserId
}
);
response = self.client.feeds.add_comment(
comment="This is a test comment from Python SDK",
object_id=activity_id,
object_type="activity",
user_id=self.test_user_id,
)
Updating Comments
try await feed.updateComment(
commentId: "comment_123",
request: .init(
comment: "Not so great",
custom: ["edited": true]
)
)
feed.updateComment(
commentId = "comment_123",
request = UpdateCommentRequest(
comment = "Not so great",
custom = mapOf("edited" to true)
)
)
// Update a comment
await client.updateComment({
id: "comment_123",
comment: "Updated comment",
custom: {
edited: true,
},
});
// Update a comment
await client.feeds.updateComment({
id: "comment_123",
comment: "Updated comment",
custom: {
edited: true,
},
});
response, err := feedsClient.AddComment(ctx, &getstream.AddCommentRequest{
Comment: "This is a test comment from Go SDK",
ObjectID: activityID,
ObjectType: "activity",
UserID: &testUserID,
})
AddCommentRequest commentRequest =
AddCommentRequest.builder()
.comment("This is a test comment from Java SDK")
.objectID(activityId)
.objectType("activity")
.userID(testUserId)
.build();
AddCommentResponse response = feeds.addComment(commentRequest).execute().getData();
$response = $this->feedsV3Client->addComment(
new GeneratedModels\AddCommentRequest(
comment: 'This is a test comment from PHP SDK',
objectID: $activityId,
objectType: 'activity',
userID: $this->testUserId
)
);
var response = await _feedsV3Client.AddCommentAsync(
new AddCommentRequest
{
Comment = "This is a test comment from .NET SDK",
ObjectID = activityId,
ObjectType = "activity",
UserID = _testUserId
}
);
response = self.client.feeds.add_comment(
comment="This is a test comment from Python SDK",
object_id=activity_id,
object_type="activity",
user_id=self.test_user_id,
)
Removing Comments
try await feed.deleteComment(
commentId: "comment_123"
)
feed.deleteComment(commentId = "comment_123")
client.deleteComment({
id: "comment_123",
});
client.feeds.deleteComment({
id: "comment_123",
});
response, err := feedsClient.UpdateComment(ctx, commentID, &getstream.UpdateCommentRequest{
Comment: getstream.PtrTo("Updated comment text from Go SDK"),
})
UpdateCommentRequest updateRequest =
UpdateCommentRequest.builder().comment("Updated comment text from Java SDK").build();
UpdateCommentResponse response =
feeds.updateComment(commentId, updateRequest).execute().getData();
$response = $this->feedsV3Client->updateComment(
$commentId,
new GeneratedModels\UpdateCommentRequest(
comment: 'Updated comment text from PHP SDK'
)
);
var response = await _feedsV3Client.UpdateCommentAsync(
commentId,
new UpdateCommentRequest
{
Comment = "Updated comment text from .NET SDK"
}
);
response = self.client.feeds.update_comment(
comment_id, comment="Updated comment text from Python SDK"
)
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)
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
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",
});
response, err := feedsClient.DeleteComment(ctx, commentID, &getstream.DeleteCommentRequest{
HardDelete: getstream.PtrTo(false), // soft delete
})
DeleteCommentRequest deleteRequest = DeleteCommentRequest.builder().build();
DeleteCommentResponse response =
feeds.deleteComment(commentId, deleteRequest).execute().getData();
$response = $this->feedsV3Client->deleteComment($commentId, false); // soft delete
var response = await _feedsV3Client.DeleteCommentAsync(
commentId,
new { user_id = _testUserId }
);
response = self.client.feeds.delete_comment(
comment_id, hard_delete=False
) # soft delete
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
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()
// 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,
});
response, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"object_id": activityID,
},
Limit: getstream.PtrTo(10),
})
Map<String, Object> filter = new HashMap<>();
filter.put("object_id", activityId);
QueryCommentsRequest queryRequest =
QueryCommentsRequest.builder().filter(filter).limit(10).build();
QueryCommentsResponse response = feeds.queryComments(queryRequest).execute().getData();
$response = $this->feedsV3Client->queryComments(
new GeneratedModels\QueryCommentsRequest(
filter: (object)['object_id' => $activityId],
limit: 10
)
);
var response = await _feedsV3Client.QueryCommentsAsync(
new QueryCommentsRequest
{
Filter = new Dictionary<string, object> { ["object_id"] = activityId },
Limit = 10
}
);
response = self.client.feeds.query_comments(
filter={"object_id": activity_id}, limit=10
)
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
feed.addCommentReaction(
commentId = "comment_123",
request = AddCommentReactionRequest(type = "like")
)
// Remove a reaction from a comment
feed.deleteCommentReaction(
commentId = "comment_123",
type = "like"
)
// Add a reaction to a comment
const response = await client.addCommentReaction({
id: "comment_123",
type: "like",
});
await client.deleteCommentReaction({
id: "comment_123",
type: "like",
});
// Add a reaction to a comment
const response = await client.feeds.addCommentReaction({
id: "comment_123",
type: "like",
user_id: "<user id>",
});
await client.feeds.deleteCommentReaction({
id: "comment_123",
type: "like",
user_id: "<user id>",
});
response, err := feedsClient.QueryComments(ctx, &getstream.QueryCommentsRequest{
Filter: map[string]interface{}{
"object_id": activityID,
},
Limit: getstream.PtrTo(10),
})
Map<String, Object> filter = new HashMap<>();
filter.put("object_id", activityId);
QueryCommentsRequest queryRequest =
QueryCommentsRequest.builder().filter(filter).limit(10).build();
QueryCommentsResponse response = feeds.queryComments(queryRequest).execute().getData();
$response = $this->feedsV3Client->queryComments(
new GeneratedModels\QueryCommentsRequest(
filter: (object)['object_id' => $activityId],
limit: 10
)
);
var response = await _feedsV3Client.QueryCommentsAsync(
new QueryCommentsRequest
{
Filter = new Dictionary<string, object> { ["object_id"] = activityId },
Limit = 10
}
);
response = self.client.feeds.query_comments(
filter={"object_id": activity_id}, limit=10
)
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()
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()
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({
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({
id: "<parent id>",
});
response, err := feedsClient.DeleteComment(ctx, commentID, &getstream.DeleteCommentRequest{
HardDelete: getstream.PtrTo(false), // soft delete
})
DeleteCommentRequest deleteRequest = DeleteCommentRequest.builder().build();
DeleteCommentResponse response =
feeds.deleteComment(commentId, deleteRequest).execute().getData();
$response = $this->feedsV3Client->deleteComment($commentId, false); // soft delete
var response = await _feedsV3Client.DeleteCommentAsync(
commentId,
new { user_id = _testUserId }
);
response = self.client.feeds.delete_comment(
comment_id, hard_delete=False
) # soft delete