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
final comment = await feed.addComment(
  request: const ActivityAddCommentRequest(
    comment: 'So great!',
    custom: {'sentiment': 'positive'},
    activityId: 'activity_123',
    activityType: 'activity',
  ),
);
// Adding a reply to a comment
final reply = await feed.addComment(
  request: const ActivityAddCommentRequest(
    comment: 'I agree!',
    activityId: 'activity_123',
    activityType: 'activity',
    parentId: 'comment_456',
  ),
);

Updating Comments

// Updating a comment
final updatedComment = await feed.updateComment(
  commentId: 'comment_123',
  request: const UpdateCommentRequest(
    comment: 'Not so great',
    custom: {'edited': true},
  ),
);

Removing Comments

await feed.deleteComment(commentId: 'comment_123');

Reading Comments

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

await feed.getOrCreate();
print(feed.state.activities[0].comments);
// or
final activity = client.activity(
  fid: const FeedId(group: 'user', id: 'john'),
  activityId: 'activity_123',
);
await activity.get();
print(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
final list1 = client.commentList(
  const CommentsQuery(
    filter: Filter.query(CommentsFilterField.commentText, 'oat'),
  ),
);
final comments1 = await list1.get();

// All comments for an activity
final list2 = client.commentList(
  const CommentsQuery(
    filter: Filter.and([
      Filter.equal(CommentsFilterField.objectId, 'activity_123'),
      Filter.equal(CommentsFilterField.objectType, 'activity'),
    ]),
  ),
);
final comments2 = await list2.get();

// Replies to a parent activity
final list3 = client.commentList(
  const CommentsQuery(
    filter: Filter.equal(CommentsFilterField.parentId, 'parent_id'),
  ),
);
final comments3 = await list3.get();

// Comments from an user
final list4 = client.commentList(
  const CommentsQuery(
    filter: Filter.equal(CommentsFilterField.userId, 'jane'),
  ),
);
final comments4 = await list4.get();

Comment Reactions

// Add a reaction to a comment
await feed.addCommentReaction(
  commentId: 'comment_123',
  request: const AddCommentReactionRequest(type: 'like'),
);
// Remove a reaction from a comment
await feed.deleteCommentReaction(commentId: 'comment_123', type: 'like');

Comment Threading

final commentList = client.activityCommentList(
  const ActivityCommentsQuery(
    objectId: 'activity_123',
    objectType: 'activity',
    depth: 3,
    limit: 20,
  ),
);
final comments = await commentList.get();

// Get replies of a specific parent comment
final replyList = client.commentReplyList(
  const CommentRepliesQuery(commentId: 'parent_123'),
);
final replies = await replyList.get();
© Getstream.io, Inc. All Rights Reserved.