social.plus SDK provides comprehensive post-editing functionality that fosters accountability and user awareness within your application. Users can edit their own posts, and community moderators/admins can edit posts within their communities.

Text Posts

Edit and update text content in existing posts

Image Posts

Add, remove, or replace images in image posts

File Posts

Manage file attachments and add new files

Video Posts

Update video content and add new videos

Supported Post Types

social.plus SDK supports the editing of the following post types:

Permissions and Accountability

Edit Permissions: Users can only edit their own posts, except if you’re an admin or a moderator of a particular community. This functionality encourages responsible interactions and maintains accountability.

Key Features

Upon completing an edit operation, the SDK updates the editedAt property to the current time, reflecting the changes made by the user. You can leverage this timestamp to create a user interface that informs users of edited posts, fostering transparency.

Update Text Post

To edit a text post, utilize the editPost method in a post repository using AmityTextPostBuilder class to compose new text content.
func updateTextPostExample() async throws {
    // Update your post structure
    let builder = AmityTextPostBuilder()
    builder.setText("new-text")
    
    // Update a post from the builder
    do {
        let post = try await postRepository.editPost(withId: "<post-id>", builder: builder)
        print("Text post updated successfully")
    } catch {
        // Handle error here
        print("Failed to update text post: \(error)")
    }
}

Update File Post

To edit a file post, utilize the editPost method in a post repository using AmityFilePostBuilder class to compose a set of new files. The files parameter should include both the current files (if required) and any newly uploaded files you wish to append to the post.
func updateFilePostExample() async throws {
    guard let post = postRepository.getPost(withId: "postId").object else { return }
    let childrenPosts = post.childrenPosts
    
    Task { @MainActor in
        do {
            // Assume that this is file post, get the current value of files
            var filesData = childrenPosts.compactMap({ $0.getFileInfo() })

            // Upload a new file
            let fileData = try await fileRepository.uploadFile(yourFile, progress: nil)
            // Add newly uploaded file to array
            filesData.append(fileData)
            
            let filePostBuilder = AmityFilePostBuilder()
            filePostBuilder.setFiles(filesData)
            let _ = try await postRepository.editPost(withId: "postId", builder: filePostBuilder)
            
            print("File post updated successfully")
        } catch {
            print("error: \(error.localizedDescription)")
        }
    }
}

File Management Strategy

Update Image Post

To edit an image post, utilize the editPost method in a post repository using AmityImagePostBuilder class to compose a set of new images. The images parameter should include both the current images (if required) and any newly uploaded images you wish to append to the post.
func updateImagePostExample() {
    guard let post = postRepository.getPost(withId: "postId").object else { return }
    let childrenPosts = post.childrenPosts
    
    Task { @MainActor in
        do {
            // Assume that this is image post, get the current value of images
            var imagesData = childrenPosts.compactMap({ $0.getImageInfo() })

            // Upload a new image
            let imageData = try await fileRepository.uploadImage(yourImage, progress: nil)
            // Add newly uploaded image to array
            imagesData.append(imageData)
            
            let imagePostBuilder = AmityImagePostBuilder()
            imagePostBuilder.setImages(imagesData)
            let _ = try await postRepository.editPost(withId: "postId", builder: imagePostBuilder)
            
            print("Image post updated successfully")
        } catch {
            print("error: \(error.localizedDescription)")
        }
    }
}

Image Processing Features

Update Video Post

To edit a video post, utilize the editPost method in a post repository using AmityVideoPostBuilder class to compose a set of new videos. The videos parameter should include both the current videos (if required) and any newly uploaded videos you wish to append to the post.
func updateVideoPostExample() async throws {
    guard let post = postRepository.getPost(withId: "postId").object else { return }
    let childrenPosts = post.childrenPosts
    
    Task { @MainActor in
        do {
            // Assume that this is video post, we need to get the current value of videos
            var videosData = childrenPosts.compactMap({ $0.getVideoInfo() })

            // Upload a new video
            let videoData = try await fileRepository.uploadVideo(with: yourVideo, progress: nil)
            // Add newly uploaded video to array
            videosData.append(videoData)
            
            let videoPostBuilder = AmityVideoPostBuilder()
            videoPostBuilder.setVideos(videosData)
            let _ = try await postRepository.editPost(withId: "postId", builder: videoPostBuilder)
            
            print("Video post updated successfully")
        } catch {
            print("error: \(error.localizedDescription)")
        }
    }
}

Video Processing

Limitations and Best Practices

Maximum Media Limit: You can upload a maximum of 10 images/files/videos in a single post. Plan your content accordingly to stay within these limits.

Common Use Cases

Typo Corrections

Quick text corrections and spelling fixes

Content Updates

Adding new information or updating outdated content

Moderation Edits

Community moderators correcting or improving posts