Editing and changing post details and content
Amity SDK supports the editing of the following post types:
Text post
Image post
File post
Video post
Amity Social SDK provides a post editing functionality that fosters accountability and user awareness within your application. This feature enables users to edit their own posts exclusively. Users can only edit their own posts, except that you're an admin or a moderator of a particular community. The functionality encourages responsible interactions and maintains accountability. Upon completing an edit operation, the SDK updates the editedAt
property to the current time, reflecting the changes made by the user. You can then leverage the updated editedAt
timestamp to create a user interface that informs users of edited posts, fostering transparency. You can edit a post by follow this sample code.
You can edit a post using a pattern similar to creating a post. Follow these steps:
Choose the appropriate post builder type and structure your post.
Make the API call for post editing.
Note: If you intend to update files, images, or videos in a post, you must upload them first. Once you have the data, you can use it with the corresponding post type. Ensure that the builder type matches the original post type.
For further details on uploading, refer to #upload-images #upload-files#upload-videos.
To edit a text post, utilize the editPost
method in a post repository using AmityTextPostBuilder
class to compose a new text as demonstrated in the provided code snippet.
To edit a file post, utilize the editPost
method in a post repository using AmityFilePostBuilder
class to compose a set of new files as demonstrated in the provided code snippet. The files
parameter should include both the current files (if required) and any newly uploaded files you wish to append to the post.
To edit an image post, utilize the editPost
method in a post repository using AmityImagePostBuilder
class to compose a set of new images as demonstrated in the provided code snippet. The images
parameter should include both the current images (if required) and any newly uploaded images you wish to append to the post.
To edit a video post, utilize the editPost
method in a post repository using AmityVideoPostBuilder
class to compose a set of new videos as demonstrated in the provided code snippet. The videos
parameter should include both the current videos (if required) and any newly uploaded videos you wish to append to the post.
If you want to edit a file/image/video post to add more files, the files/images to be added must be uploaded first. The AmityFileRepository
class handles the uploading and downloading of files. The repository has an uploadFile
method which takes the file's Uri
and returns an array of AmityUploadResult
for successful or failed uploads.
AmityUploadResult
will return four possible types of data:
AmityUploadResult.PROGRESS
- uploading is in progress. It returns AmityUploadInfo
which can be used to track the progress of the upload.
AmityUploadResult.COMPLETE
- the upload completed successfully. It returns AmityFile
that can then be attached to the post.
AmityUploadResult.ERROR(exception)
- the upload failed. It returns an Exception
.
AmityUploadResult.CANCELLED
- uploading is canceled.
For further details on uploading, refer to #upload-images #upload-files#upload-videos.
To edit a file post, use the edit
method as shown in the sample code below. The attachments
should contain the uploaded files that you want to add to the post which are stored in existingFiles
and newFiles
respectively.
To edit an image post, use the edit
method as shown in the sample code below. The attachments
should contain the existing images and the uploaded images that you want to add to the post which are stored in existingImages
and newImages
respectively.
You can remove existing images from the post by excluding them from the attachments
list. You can also change the order of the images in the list.
To edit a video post, use the edit
method as shown in the sample code below. The attachments
should contain the existing videos and the uploaded videos that you want to add to the post which are stored in existingVideos
and newVideos
respectively.
This method requires the following parameters:
postId (String)
- ID of the post to update
data (Object)
- data object of the post
Other optional parameters are:
metadata (Object)
- the metadata object of the post
tags (Array.<String>)
- strings used to query the post. Up to five tags can be added and each tag can be up to 24 characters long.
In JavaScript SDK, the following are not yet supported:
Adding videos to a non-video post (e.g. text post, image post)
Adding different media types (e.g. image, custom files) in a single post
The updatePost
method returns a Promise<boolean>
- true
if the post is successfully updated. Otherwise, it will throw an error.
You can add new videos or remove existing ones from a video post. In adding new videos, you must first upload the videos that you will add to the post. Refer to Upload Video for the details on how to upload a video.
When updating a video post, provide the file ID of the video and the type FileType.Video
in the attachments
parameter. Modifying attachments
array will overwrite the existing videos so it’s recommended to include original attachments if you want to retain the original videos in the post. Leave the attachments
array empty to remove all videos.
Version 6
Beta (v0.0.1)
When updating a post, you can update its text content. However, you cannot add or remove the post's attachments (i.e. image, video, and file).
You can update the post using the update
method. This method requires the following parameters:
postId (String)
- ID of the post to update
text (String)
- text data of the post
You can upload a maximum of ten images/files in a single post.