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
comment_request = GetStream::Generated::Models::AddCommentRequest.new(
  comment: 'So great!',
  object_id: 'activity_123',
  object_type: 'activity',
  user_id: 'user123',
  custom: {
    sentiment: 'positive'
  }
)

response = client.feeds.add_comment(comment_request)

# Adding a reply to a comment
reply_request = GetStream::Generated::Models::AddCommentRequest.new(
  comment: 'I agree!',
  object_id: 'activity_123',
  object_type: 'activity',
  parent_id: 'comment_456',
  user_id: 'user123'
)

response = client.feeds.add_comment(reply_request)

# Adding a comment without triggering push notifications
silent_comment_request = GetStream::Generated::Models::AddCommentRequest.new(
  comment: 'Silent comment',
  object_id: 'activity_123',
  object_type: 'activity',
  user_id: 'user123',
  skip_push: true
)

response = client.feeds.add_comment(silent_comment_request)

Updating Comments

try await feed.updateComment(
    commentId: "comment_123",
    request: .init(
        comment: "Not so great",
        custom: ["edited": true]
    )
)

Removing Comments

# Update a comment
update_request = GetStream::Generated::Models::UpdateCommentRequest.new(
  comment: 'Updated comment text from Ruby SDK',
  custom: {
    edited: true
  }
)

response = client.feeds.update_comment(comment_id, update_request)

Reading Comments

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

# Delete a comment (soft delete)
response = client.feeds.delete_comment(comment_id, hard_delete: false)

Querying Comments

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

# Query comments for an activity
query_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    object_id: activity_id
  },
  limit: 10
)

response = client.feeds.query_comments(query_request)

# Search in comment texts
search_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    comment_text: { '$q' => 'oat' }
  }
)

response = client.feeds.query_comments(search_request)

# Comments from a specific user
user_comments_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    user_id: 'user123'
  },
  limit: 20
)

response = client.feeds.query_comments(user_comments_request)

Comment Queryable Built-In Fields

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the comment$in, $eq{ id: { $in: [ 'comment_123', 'comment_456' ] } }
user_idstring or list of stringsThe ID of the user who created the comment$in, $eq{ user_id: { $eq: 'user_123' } }
object_typestring or list of stringsThe type of object being commented on$eq, $ne, $in, $nin{ object_type: { $in: [ 'activity', 'post' ] } }
object_idstring or list of stringsThe ID of the object being commented on$in, $eq{ object_id: { $eq: 'activity_123' } }
parent_idstring or list of stringsThe parent comment ID for replies$in, $eq{ parent_id: { $eq: 'comment_parent_123' } }
comment_textstringThe text content of the comment$q{ comment_text: { $q: 'search terms' } }
statusstring or list of stringsThe status of the comment$eq, $ne, $in{ status: { $in: [ 'approved', 'pending' ] } }
reply_countnumberThe number of replies to this comment$gt, $gte, $lt, $lte{ reply_count: { $gte: 5 } }
upvote_countnumberThe number of upvotes on the comment$gt, $gte, $lt, $lte{ upvote_count: { $gte: 10 } }
downvote_countnumberThe number of downvotes on the comment$gt, $gte, $lt, $lte{ downvote_count: { $lt: 5 } }
scorenumberThe overall score of the comment$gt, $gte, $lt, $lte{ score: { $gte: 0 } }
confidence_scorenumberThe confidence score of the comment$gt, $gte, $lt, $lte{ confidence_score: { $gte: 0.5 } }
controversy_scorenumberThe controversy score of the comment$gt, $gte, $lt, $lte{ controversy_score: { $lt: 0.8 } }
created_atstring, must be formatted as an RFC3339 timestampThe time the comment was created$eq, $gt, $gte, $lt, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }

Comment Reactions

When adding reactions and the enforce_unique flag is set to true, the existing reaction of a user will be overridden with the new reaction. Use this flag if you want to ensure users have a single reaction per each comment/activity. The default value is false, in which case users can have multiple reactions.

# Query comments for an activity
query_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    object_id: activity_id
  },
  limit: 10
)

response = client.feeds.query_comments(query_request)

# Search in comment texts
search_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    comment_text: { '$q' => 'oat' }
  }
)

response = client.feeds.query_comments(search_request)

# Comments from a specific user
user_comments_request = GetStream::Generated::Models::QueryCommentsRequest.new(
  filter: {
    user_id: 'user123'
  },
  limit: 20
)

response = client.feeds.query_comments(user_comments_request)

Comment Threading

# Delete a comment (soft delete)
response = client.feeds.delete_comment(comment_id, hard_delete: false)
© Getstream.io, Inc. All Rights Reserved.