# Comments

## Overview

Comments support voting, ranking, threading, images, URL previews, mentions and notifications.

### Adding Comments

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// 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"
    )
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Updating Comments

<codetabs>

<codetabs-item value="swift" label="Swift">

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

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Removing Comments

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
try await feed.deleteComment(
    commentId: "comment_123"
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Reading Comments

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

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
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)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Querying Comments

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

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// 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()
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Comment Reactions

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
// 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"
)
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

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

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

<codetabs-item value="go-golang" label="Go">

```go
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)
}
```

</codetabs-item>

</codetabs>

### Comment Threading

<codetabs>

<codetabs-item value="swift" label="Swift">

```swift
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()
```

</codetabs-item>

<codetabs-item value="javascript" label="JavaScript">

```js
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>',
});
```

</codetabs-item>

<codetabs-item value="nodejs" label="Node">

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

</codetabs-item>

</codetabs>

---

This page was last updated at 2025-08-15T14:14:10.535Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/react-native/comments/](https://getstream.io/activity-feeds/docs/react-native/comments/).