Comments

Comments are a way to create comments for a particular content without needing to join a channel or manage channel memberships.

Upstra provides support for common text in comments.

All comment methods are contained in a CommentRepository class. Before calling any comment methods, you must ensure to import it.

import { CommentRepository } from 'eko-sdk';

Sending Comments

All comment sending methods are designed to be robust enough to work under any network conditions. When you send any comment, that comment will automatically be put into a queue in case of unstable network conditions. Once the SDK reconnects to the server, it will automatically resend all queued comments.

Additionally, sent comments are always returned in comment queries, even before they have been delivered to the server. It is done to provide the user with a fluid commenting behavior: when a user sends a comment, that comment would appear in the comment list right away, instead of waiting until it has been confirmed by the server.

Content ID

Unlike messages, comments are directly tied to a specific referenceId that is managed by the client. The referenceId has to be unique but can be any string.

Text Comment

Sending a standard text comment is a simple method call with referenceId and the message text:

const commentLiveObject = CommentRepository.createTextComment({
referenceType: 'content',
referenceId: 'reference123',
text: 'Hello World!',
});

Comment Query

To query for a list of comments in a post:

import { CommentRepository } from 'eko-sdk';
const comments = CommentRepository.queryComments({
referenceType: 'content',
referenceId: 'reference123',
first: 5 // or last: 5
});
comments.on('dataUpdated', data => {
// reload comment table
});
comments.on('dataError', error => {
console.log('Comment LiveCollections can not query/get/sync data from server');
});

This method will return a LiveCollection of comments in the specified referenceId.

Threaded Comments

A comment can be a root for a thread. To query the children of a comment thread, you can add the parentId parameter in a comment query, along with the filterByParentId flag.

import { CommentRepository } from 'eko-sdk';
const comments = CommentRepository.queryComments({
referenceType: 'content',
referenceId: 'reference123',
filterByParentId: true,
});

When creating a comment, we can also pass the parentId to make it appear under the parent.

const commentLiveObject = CommentRepository.createTextComment({
referenceType: 'content',
referenceId: 'reference123',
text: 'Hello World!',
parentId: 'comment321',
});

Flag & Unflag Comments

To flag a comment, call the following method:

CommentRepository.flag('comment123')

To unflag a comment, call the following method:

CommentRepository.unflag('comment123')

The User can also check if they have previously flagged the comment before by calling the following asynchronous method:

const result = await CommentRepository.isFlaggedByMe('comment123')

Edit and Delete

You can only perform edit and delete operations on your own comments. Once the operation is complete, the comment's editedAtDate will be set to the current time. This allows you to provide UI to the user to inform the user of specific messages that has been edited, if needed. An optional completion block can be provided to notify you of operation success.

// edit comment with new text
try {
CommentRepository.editTextComment({
commentId: 'comment123',
text: 'Hello World 2',
})
} catch(error) {
...
}
// delete comment
try {
CommentRepository.deleteComment('comment123')
} catch(error) {
...
}