Skip to main content

Create a Post

The addPost() function is used to create a new post in the LikeMinds feed. It allows users to share content, including text, attachments, topics, and more, facilitating content creation and user-generated interactions.

Steps to Add a Post

  1. Create an instance of AddPostRequest with the required parameters: text for post content, attachments for any attachments, feedroomId for the feed room ID, topics for related topics, and isRepost for repost status.
  2. Call the addPost() function using the instance of the LMFeedClient class, passing the request as a parameter.
  3. Use the response as per your requirement.
// Create an instance of AddPostRequest
final AddPostRequest request = (AddPostRequestBuilder()
..attachments([/* List of Attachment objects */])
..text('Test post from SDK')
..topicIds([/* List of Topic IDs */])
..isRepost(false))
.build();

// Get the response from calling the function
final AddPostResponse addPostResponse = await lmFeedClient.addPost(addPostRequest);

// Process the response, as per requirement
if (addPostResponse.success) {
// your function to handle successful post addition
handleAddPostSuccess(addPostResponse.post, addPostResponse.user, addPostResponse.topics, addPostResponse.widgets, addPostResponse.repostedPosts);
} else {
// your function to handle error message
handleAddPostError(addPostResponse.errorMessage);
}

Additional Features

Tag a User

To tag a user, use the getTaggingList() function to fetch the list of users that can be tagged, and use the format <<[user.name]|route://user_profile/[user.sdkClientInfo.uuid]>> to embed it inside the text of the post.

Decode a URL

To decode a URL, use the decodeUrl() function to decode a URL and get its OGTags. Use those to add an attachment of type 4.

Create a repost

In AddPostRequest, add an attachment of type 8, and in the attachment_meta add entityId which will be the post ID of the originial post. And finally, set the isRepost boolean as true.

Add a Topic

Topics are keywords related to a post, they can be considered having the same use case as hashtags. You can add a topic to the post by sending the topicIds list in the AddPostRequest with the topics you have fetched using the getTopics().

Models

AddPostRequest

List of parameters for the AddPostRequest class

VariableTypeDescriptionOptional
textStringPost content
feedroomIdintFeed room ID
attachmentsList<Attachment>List of attachments
topicIdsList<String>List of related topics' IDs
isRepostboolRepost status

AddPostResponse

List of parameters for the AddPostResponse class

VariableTypeDescriptionOptional
successboolAPI success status
errorMessageStringError message in case of failure
postPostAdded post details
userMap<String, User>Map of user UUIDs to User entities
topicsMap<String, Topic>Map of topic IDs to Topic entities
widgetsMap<String, WidgetModel>Map of widget IDs to WidgetModel entities
repostedPostsMap<String, Post>Map of reposted post IDs to Post entities