Skip to content

Share Content

Sharing an activity

Create invite content from the activity

val activity: GetSocialActivity // activity to share

val inviteContent = InviteContent()
// set text
inviteContent.text = activity.text
// set image 
inviteContent.mediaAttachment = activity.attachments.first()
// set activity id
val activityData = HashMap<String, Any>();
activityData["ACTIVITY_ID"] = activity.id
inviteContent.linkParams = activityData
let activity: Activity //  activity to share

let inviteContent = InviteContent()
// set text
inviteContent.text = activity.text
// set image
inviteContent.mediaAttachment = activity?.mediaAttachments.first
// set activity id
inviteContent.linkParams = ["ACTIVITY_ID": (activity!.id as NSString)]

Send the invite

// send the invite via email
Invites.send(inviteContent, InviteChannelIds.EMAIL, {
    Log.d("Communities", "Invite sent")
}, {
    Log.d("Communities", "Sending invite cancelled")
}, { error ->
    Log.d("Communities", "Failed to send invite: $error")
})
// send the invite via email
Invites.send(inviteContent, onChannel: InviteChannelIds.email, success: {
    print("Invite sent")
}, cancel: {
    print("Sending invite cancelled")
}, failure: { error in
    print("Failed to send invite: \(error)")
})

Receive the invite

Invites.setReferralDataListener({ data ->
    // get activity data
    val activityId = data.linkParams["ACTIVITY_ID"]
})
Invites.setOnReferralDataReceivedListener({ data in
    let activityId = data.linkParams["ACTIVITY_ID"]
})

Repost an activity

Create a new activity and store the original activity’s id

val activity: GetSocialActivity // activity to repost
val newActivity = ActivityContent()
newActivity.withText("Check this out")
newActivity.addProperty("activity_id", activity.id)

Communities.postActivity(newActivity, target, { activity -> 
    Log.d("Communities", "Activity posted")
}, { error ->
    Log.d("Communities", "Failed to post activity, error: $error")
})
let activity: Activity  //  activity to repost
let newActivity = ActivityContent()
newActivity.text = 'Check this out'
newActivity.properties['activity_id'] = activity.id

Communities.postActivity(newActivity, target: target, success: { activity in
    print("Activity posted")
}, failure: { error in
    print("Failed to post activity, error: \(error)")
})

Check and load the original activity

val activity: GetSocialActivity // activity in a feed
val originalActivityId: String? = activity.properties.get("activity_id")
if (originalActivityId != null) {
    // fetch the original activity
    Communities.getActivity(originalActivityId, { originalActivity -> 
        Log.d("Communities", "Original activity: $originalActivity")
    }, { error ->
        Log.d("Communities", "Failed to load original activity, error: $error")
    })
}
let activity: Activity  //  activity in a feed
if let originalActivityId = activity.properties['activity_id'] {
    // fetch the original activity
    Communities.activity(originalActivityId, success: { originalActivity in
        print("Original activity: \(originalActivity)")
    }, failure: { error in
        print("Failed to load original activity, error: \(error)")
    })
}

Give us your feedback! Was this article helpful?

😀 🙁