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",
});

Updating Comments

// Update a comment
await client.updateComment({
  comment_id: "comment_123",
  comment: "Updated comment",
  custom: {
    edited: true,
  },
});

Removing Comments

client.deleteComment({
  comment_id: "comment_123",
});

Reading Comments

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

await feed.getOrCreate();

const activity = feed.state.getLatestValue().activities?.[0]!;

// Supported values for sort: first, last, top, controversial, best
// Loads the first page
await feed.loadNextPageComments(activity, {sort: 'best'});

const comments = feed.state.getLatestValue()?.comments_by_entity_id[activityId]

// Loads the next page
await feed.loadNextPageComments(activity, {sort: 'best'});

Querying Comments

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

// 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,
});

Comment Reactions

// Add a reaction to a comment
const response = await client.addCommentReaction({
  comment_id: "comment_123",
  type: "like",
});

await client.removeCommentReaction({
  comment_id: "comment_123",
  type: "like",
});

Comment Threading

await feed.getOrCreate();

const activity = feed.state.getLatestValue().activities?.[0]!;

await feed.loadNextPageComments(activity, { depth: 3, limit: 20 });

const comments = feed.state.getLatestValue()?.comments_by_entity_id[activityId]
const parentComment = 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);
© Getstream.io, Inc. All Rights Reserved.