Optimistic Updates
Comments appear instantly with automatic rollback on failure
Threaded Replies
Support nested conversations with parent-child relationships
Rich Content
Text comments with mentions, metadata, and custom data
Optimistic Updates: Comments appear immediately in the UI while the SDK handles creation in the background, providing seamless user experience with automatic rollback on failure.
Reference Types
Comments can be created on different types of content by specifying the appropriate reference type.| Reference Type | Description | Use Cases | Character Limit |
|---|---|---|---|
post | Comments on regular posts | Text posts, media posts, shared content | 20,000 characters |
story | Comments on story content | Temporary stories, story highlights | 20,000 characters |
content | Comments on specialized content | Articles, custom content types | 20,000 characters |
A comment should not exceed 20,000 characters in length. Comments exceeding this limit will be rejected by the API.
Create Text Comment
To work with comments, you’ll need to use the CommentRepository. With the SDK’s optimistic creation feature, you don’t need to manually create a commentId. Instead, the SDK generates one automatically.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
referenceId | String | ✅ | ID of the content being commented on |
referenceType | Enum | ✅ | Type of content (post, story, content) |
text | String | ✅ | Comment text content (max 10,000 characters) |
parentId | String | ❌ | ID of parent comment for threaded replies |
metadata | Object | ❌ | Custom metadata for the comment |
attachments | Array<Object> | ❌ | Files to attach to the comment. Each item is an object: [{ type: "image", fileId: "file_id_1" }, { type: "image", fileId: "file_id_2" }] |
mentionees | Array<Object> | ❌ | Users to mention in the comment. Each item is an object: [{ type: "user", userIds: ["userId1","userId2"] }] |
Reply to a Comment
In addition to creating top-level comments, social.plus SDK enables you to reply to existing comments in addition to creating top-level comments. To reply to a comment, you must:- Specify the parent comment’s
commentIdusing theparentIdparameter. - Ensure the
referenceIdandreferenceTypematch the original comment’s content.
Best Practices
Optimistic Updates
Optimistic Updates
- Immediate Feedback: Show comments instantly in the UI for better user experience
- Rollback Strategy: Implement proper error handling to remove failed comments
- Loading States: Show appropriate indicators during comment submission
- Network Resilience: Handle offline scenarios with queued comment creation
Performance Optimization
Performance Optimization
- Text Validation: Validate comment length before API calls
- Debounce Input: Prevent rapid successive submissions
- Memory Management: Properly dispose of notification tokens
- Background Processing: Handle comment creation asynchronously
User Experience
User Experience
- Character Limits: Show remaining character count to users
- Auto-save Drafts: Save comment drafts as users type
- Keyboard Management: Handle keyboard appearance for better UX
- Visual Feedback: Provide clear success/error indicators
Content Guidelines
Content Guidelines
- Moderation: Implement client-side content filtering if needed
- Rich Text: Support basic text formatting where appropriate
- Mention Handling: Provide user-friendly mention input interfaces
- Thread Management: Display reply hierarchies clearly
Troubleshooting
Comment creation fails
Comment creation fails
- Verify user has permission to comment on the content
- Check if the reference ID exists and is accessible
- Ensure comment text doesn’t exceed 20,000 character limit
- Validate network connectivity and authentication status
Optimistic updates not working
Optimistic updates not working
- Confirm UI update logic is executed on main thread
- Check if error handling properly removes failed comments
- Test with different network conditions
Threaded replies not appearing correctly
Threaded replies not appearing correctly
- Ensure parentId is valid and references existing comment
- Check comment hierarchy depth limits
- Verify UI properly handles nested comment display
- Test reply functionality with different comment types
Performance issues
Performance issues
- Implement proper pagination for comment lists
- Optimize comment rendering for large threads
- Monitor memory usage with extensive comment trees
- Use efficient data structures for comment hierarchies
Practical Examples
Social Media Feed
Enable threaded discussions on posts with support for text comments and reactions for comprehensive social engagement.
Customer Support
Create support ticket comments with proper threading for detailed issue reporting and resolution tracking.
Educational Platform
Facilitate course discussions with threaded replies and user mentions for instructor attention and peer interaction.
Community Forums
Build forum-style discussions with nested replies and rich content for knowledge sharing and community building.