Understand how to properly display and render different types of posts in the social.plus SDK. Learn about the parent-child post structure and how to access various content types including images, files, videos, live streams, and polls.

Post Structure

Understand parent-child relationships in media posts

Content Access

Access post data and media information efficiently

Media Handling

Handle images, videos, and files with multiple resolutions

Interactive Content

Display polls and live streams in your application

Post Structure Overview

In social.plus’s SDK, posts with images, files, or videos follow a Parent-Child relationship, where each uploaded image/file is represented as a separate child post. When creating an image/file post, any text that is set will act as the Parent post.
The Parent post contains a childrenPosts property, which provides an array of Post instances for each child post. For more information about post structure, please refer to Post Overview.

Key Concepts

Accessing Children Posts

Each instance of a Post holds several pieces of information, including data, reactions, comments, metadata, child posts, and more. Here’s how to access parent and child post information:
var token: AmityNotificationToken?

func accessPostAndItsChildrenInfo(liveObject: AmityObject<AmityPost>) {
    token = liveObject.observe { liveObject, error in
        guard let post = liveObject.object else { return }
        
        // 1. Accessing the post itself
        let postId = post.postId
        let postData = post.data
        print("postId: \(postId), data: \(String(describing: postData))")
        
        // 2. Accessing children posts
        let childrenPosts = post.childrenPosts
        guard !childrenPosts.isEmpty else {
            print("This post has no children.")
            return
        }
        
        for (index, childPost) in childrenPosts.enumerated() {
            print("found [\(index)] child post")
            print("- type: \(childPost.dataType)")
            
            switch childPost.dataType {
            case "file":
                // This post is a file post. So we get file information
                if let fileInfo = childPost.getFileInfo() {
                    print("- fileInfo: \(fileInfo.fileId)")
                }
            case "image":
                // This post is an image post. So we get image information
                if let imageInfo = childPost.getImageInfo() {
                    print("- imageInfo: \(imageInfo.fileId)")
                }
            default:
                break
            }
        }
    }
}

Content Types

Image Posts

Posting visual content such as photos, graphics, or images is facilitated by this type of post. Images are automatically transformed into four different sizes for versatile usage.

Small

Thumbnail size for previews

Medium

Standard feed display

Large

High-quality viewing

Full

Original resolution
Maximum Size: 1 GB per image. For more information about image handling, please refer to Image Handling.
func getImageInfo(post: AmityPost) {
    let image = post.getImageInfo()
    print("FileId: \(image?.fileId)")
    print("FileURL: \(image?.fileURL)")
    
    // Use fileURL to download the image
    // You can use fileDownload API from AmityFileRepository or
    // other network clients to download the image
}

Image Size Parameters

If you are using your own implementation to download the image of appropriate size, you need to construct the download URL yourself by appending size query parameter. Example URL Construction:
Base URL: https://my-image-download-link-from-amity/123/456
Small Size: https://my-image-download-link-from-amity/123/456?size=small

File Posts

This is a post that contains a file attachment, such as a PDF, a Word document, or any other type of file. Useful for sharing documents, spreadsheets, presentations, and other file types within communities.
For more information about file handling, please refer to File Handling.
func getFileInfo(post: AmityPost) {
    let file = post.getFileInfo()
    print("FileId: \(file?.fileId)")
    print("FileURL: \(file?.fileURL)")
    
    // Use fileURL to download the file
    // You can use fileDownload API from AmityFileRepository or
    // other network clients to download the file
}

Video Posts

Share video content within feeds, such as short clips or longer videos. Videos are automatically transcoded into different resolutions for optimal playback across devices.

1080p

Full HD quality

720p

HD quality

480p

Standard quality

360p

Mobile-optimized

Original

Source resolution
Maximum Size: 1 GB per video. Transcoding: Videos undergo transcoding from their original resolution. Original size is accessible immediately, but transcoded resolutions take time to be ready.
For more information about video handling, please refer to Video Handling.
func getVideoData(fromPost post: AmityPost) {
    let childrenPosts = post.childrenPosts
    let allVideosData = childrenPosts.compactMap { childPost in
        childPost.getVideoInfo()
    }
    
    print("This post has \(allVideosData.count) videos.")
    
    for (index, videoData) in allVideosData.enumerated() {
        if let videoPath = videoData.getVideo(resolution: .original) {
            print("The video[\(index)] can be watched or downloaded at \(videoPath).")
        }
    }
}

Live Stream Posts

Live stream posts offer an effective means of creating captivating and interactive content that engages users and promotes deeper connections among them. The social.plus SDK enables developers to swiftly integrate live stream posts into social feeds.

Real-time Interaction

Live engagement with audience

Stream Integration

Easy integration into social feeds
For more information about live streaming, please refer to Video Streaming.
// Grab the stream object from the first child post
if let firstChildPost = post.childrenPosts.first,
   let _ = firstChildPost.getLiveStreamInfo() {
    // Handle `stream` data here
}

Poll Posts

Implement poll functionality in posts by leveraging the existing poll features in social.plus SDK. Polls can be created as child posts within the post thread, with poll data and options easily accessible to users.

Multiple Options

Create polls with 2-10 answer options

Time Limits

Set custom voting deadlines or keep open indefinitely
For more information about polls, please refer to Poll Management.
func getPoll(from post: AmityPost) {
    let _ = post.getPollInfo()
    // Access poll data, options, and voting results
}