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
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"
    )
)

Updating Comments

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

Removing Comments

try 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.

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)

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

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"
)

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()
© Getstream.io, Inc. All Rights Reserved.