To get a list of posts on the Activity Feed, you have to create a query and call API to get the results:
1
2
3
4
5
6
7
8
9
valquery:ActivitiesQuery=...// Create queryvalpagingQuery=PagingQuery(query)Communities.getActivities(pagingQuery,{result:PagingResult<GetSocialActivity>->valactivities=result.entriesLog.d("Communities","Activities: $activities")},{error:GetSocialError->Log.d("Communities","Failed to get activities: $error")})
1
2
3
4
5
6
7
8
letquery:ActivitiesQuery=...// Create queryletpagingQuery=ActivitiesPagingQuery(query)Communities.activities(pagingQuery,success:{resultinprint("Activities: \(result.activities)")},failure:{errorinprint("Failed to get activities: \(error)")})
1
2
3
4
5
6
7
8
9
ActivitiesQueryquery=...// Create queryvarpagingQuery=newPagingQuery<ActivitiesQuery>(query);Communities.GetActivities(pagingQuery,(result)=>{Debug.Log("Activities: "+result.Entries);},(error)=>{Debug.Log("Failed to get activities: "+error);});
1
2
3
4
5
6
7
varquery= ... ; // Create queryvarpagingQuery=PagingQuery(query);Communities.getActivities(pagingQuery)
.then((result) {
varactivities=result.entries;print('Activities: $activities');
}).catchError((error)=> { print('Failed to get activities, error: $error') });
1
2
3
4
5
6
7
8
9
varquery=...;// Create queryvarpagingQuery=newPagingQuery(query);Communities.getActivities(pagingQuery).then((result){varactivities=result.entries;console.log('Activities: '+activities);},(error)=>{console.log('Failed to get activities, error: '+error.message);});
This method uses the PagingQuery concept that is used across our SDK. Read more about this.
To get a list of announcements that are active now:
1
2
3
4
5
6
7
8
9
10
// To get announcements for topicvalquery=AnnouncementsQuery.topic("cats")// Or to get announcements only posted to all feedsvalquery=AnnouncementsQuery.timeline()Communities.getAnnouncements(query,{announcements:List<GetSocialActivity>->Log.d("Communities","Announcements: $announcements")},{error:GetSocialError->Log.d("Communities","Failed to get announcements: $error")})
1
2
3
4
5
6
7
8
9
10
// To get announcements for topicletquery=AnnouncementsQuery.inTopic("cats")// Or to get announcements only posted to all feedsletquery=AnnouncementsQuery.timeline()Communities.announcements(query,success:{announcementsinprint("Announcements: \(announcements)")},failure:{errorinprint("Failed to get announcements: \(error)")})
1
2
3
4
5
6
7
8
9
10
11
12
// To get announcements for topicvarquery=AnnouncementsQuery.InTopic("cats");// Or to get announcements only posted to all feedsvarquery=AnnouncementsQuery.Timeline();Communities.GetAnnouncements(query,(result)=>{Debug.Log("Announcements: "+result);},(error)=>{Debug.Log("Failed to get announcements: "+error);});
1
2
3
4
5
6
7
8
9
//Togetannouncementsfortopicvarquery=AnnouncementsQuery.inTopic('cats');//Ortogetannouncementsonlypostedtoallfeedsvarquery=AnnouncementsQuery.timeline();Communities.getAnnouncements(query)
.then((value)=>print('Announcements: $value'))
.catchError((error)=>print('Failed to get announcements, error: $error'));
1
2
3
4
5
6
7
8
9
10
11
12
// To get announcements for topicconstquery=AnnouncementsQuery.inTopic('cats');// Or to get announcements only posted to all feedsconstquery=AnnouncementsQuery.timeline();Communities.getAnnouncements(query).then((value)=>{console.log('Announcements: '+value);},(error)=>{console.log('Failed to get announcements, error: '+error);});
For each activity post, announcement and comment you can check the reactions count, reactions of the current user and get the list of users who reacted to the activity:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
valactivityPost:GetSocialActivity=...// your activity// to check a particular reaction, e.g. "like"valisLikedByMe=activityPost.myReactions.contains(Reactions.LIKE)vallikesCount=activityPost.reactionsCount[Reactions.LIKE]valquery=ReactionsQuery.forActivity(activityPost.id)valpagingQuery=PagingQuery(query)Communities.getReactions(pagingQuery,{result:PagingResult<UserReaction>->valreactions=result.entriesLog.d("Communities","Reactions: $reactions")},{error:GetSocialError->Log.d("Communities","Failed to get reactions: $error")})
1
2
3
4
5
6
7
8
9
10
11
12
13
letactivity:Activity=...// your activity// to check a particular reaction, e.g. "like"letisLikedByMe=activity.myReactions.contains(Reactions.like)letlikesCount=activity.reactionsCount[Reactions.like]letquery=ReactionsQuery.forActivity(activity.id)letpagingQuery=ReactionsPagingQuery(query)Communities.reactions(pagingQuery,success:{resultinprint("Reactions: \(result.reactions)")},failure:{errorinprint("Failed to get reactions: \(error)")})
1
2
3
4
5
6
7
8
9
10
11
12
13
Activityactivity=...// your activityvarisLikedByMe=activity.MyReactions.Contains(Reactions.Like);varlikesCount=activity.GetReactionsCount(Reactions.Like);varquery=ReactionsQuery.ForActivity(activity.Id);varpagingQuery=newPagingQuery<ReactionsQuery>(query);Communities.GetReactions(pagingQuery,(result)=>{Debug.Log("Reactions: "+result.Entries);},(error)=>{Debug.Log("Failed to get reactions: "+error);});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Activityactivity= ...; // your activity//checkaparticularreaction, e.g. 'like'varisLikedByMe=activity.myReactions.contains('like');varlikesCount=activity.reactionsCount['like'];varquery=ReactionsQuery.forActivity(activity.id);varpagingQuery=PagingQuery(query);Communities.getReactions(pagingQuery)
.then((result) {
varreactions=result.entries;print('Reactions: $reactions');
})
.catchError((error)=>print('Failed to get reactions, error: $error'));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
constactivity=...;// your activity// check a particular reaction, e.g. 'like'constisLikedByMe=activity.myReactions.contains('like');constlikesCount=activity.reactionsCount['like'];constquery=ReactionsQuery.forActivity(activity.id);constpagingQuery=newPagingQuery(query);Communities.getReactions(pagingQuery).then((result)=>{varreactions=result.entries;console.log('Reactions: '+reactions);},(error)=>{console.log('Failed to get reactions, error: '+error);});
This method uses the PagingQuery concept that is used across our SDK. Read more about this.
The section below explains how you can display Activity after loading it from GetSocial API.
Learn what can you do with activity object in Android and iOS.
Text content can contain text itself, mentions, tags, and URLs.
User ids from mentions in the text are replaced by API to user display names. If you posted text like Hello@0128309218! where @0128309218 is user id, API returns text like HelloBen!.
Optionally you can make URLs on your UI clickable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
valcontentText:TextView=...// Get instance of text viewvalpost:GetSocialActivity=...// Instance of activity post, announcement or commentif(post.text!=null{valtextContent=post.textcontentText.text=textContent// Don't forget to make text views accessiblecontentText.contentDescription=textContent// Optionally, make links clickable if post was made from Dashboardif(post.author.isVerified){Linkify.addLinks(contentText,Linkify.WEB_URLS)}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
letcontentText:UITextView=...// Get the instance of text viewletactivity:Activity=...// Instance of activity post, announcement or commentguardletactivityText=activity.textelse{return}contentText.text=activityText.text// Don't forget to make text views accessiblecontentText.accessibilityValue=activityText// Optionally, make links clickable if post was made from Dashboardifactivity.author.isVerified{contentText.dataDetectorTypes=.link}
1
2
Activityactivity=...// your activityvaractivityText=activity.Text;
Activity Post can contain images and videos. GIFs are converted to videos for optimization. All videos are encoded in MP4.
Check Media Attachments guide for more details.
You can get a list of media attachments, which is empty if you haven’t attached any media to the post. Attachments have the same order as they were posted with.
The code below shows how to display the button and implement a combination of custom action handling with the one provided by GetSocial.
Check GetSocial Actions guide for Android, iOS or Unity for more information.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
valbutton:Button=...// An instance of button for the activity postvalactionButton=post.buttonif(actionButton!=null){button.text=actionButton.title// Don't forget to make view accessiblebutton.setContentDescription(actionButton.title)button.setOnClickListener{view->valaction=actionButton.actionif("my-custom-type".equals(action.getType())){// Do the custom action handling}else{GetSocial.handle(action)// Let GetSocial handle the action}}}
letactionButton:UIButton=...// An instance of button for the activity postifletbuttonTitle=activity.button?.title{actionButton.setTitle(buttonTitle,for:.normal)// Don't forget to make view accessibleactionButton.accessibilityValue=buttonTitleactionButton.tag=activities.index(of:activity)letactionButtonTap=UITapGestureRecognizer(target:self,action:#selector(self.didClickActionButton(_:)))actionButtonTap.numberOfTapsRequired=1actionButton.addGestureRecognizer(actionButtonTap)}@objcfuncdidClickActionButton(_sender:UITapGestureRecognizer?){guardletindex=sender?.view?.tagelse{return}letactivity:Activity=activities[index]ifactivity.button?.action.type=="my-custom-type"{// Do the custom action handling}else{GetSocial.handle(activity.button?.action)}}
1
2
3
4
5
6
7
8
Activityactivity=...;if(activity.Button.Action.Type.Equals("my-custom-type")){// do the custom action handling}else{GetSocial.Handle(activity.Button.Action);}
1
2
3
4
Activityactivity= ...; // your activityif(activity.button.action.type=='my-custom-type') {
//handlecustomaction
}
1
2
3
4
constactivity=...;// your activityif(activity.button.action.type=='my-custom-type'){// handle custom action}
You can check where the activity was posted by checking their source property:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
valactivity:GetSocialActivityvalsource=activity.sourcewhen(source.type){CommunitiesEntityType.TOPIC->{// posted to topic with id `source.id`}CommunitiesEntityType.ACTIVITY->{// activity is a comment to another activity with id `source.id`}CommunitiesEntityType.USER->{// activity is posted into user's feed og the user with id `source.id.}}
1
2
3
4
5
6
7
8
9
10
11
letactivity:GetSocialActivityletsource=activity.sourceswitchsource.type{case.topic:// posted to topic with id `source.id`case.activity:// activity is a comment to another activity with id `source.id`case.user:// activity is posted into feed of the user with id `source.id`}
1
2
3
4
5
6
7
8
9
10
11
12
13
varsource=activity.Source;switch(source.Type){caseCommunitiesEntityType.Topic:// posted to topic with id `source.id`break;caseCommunitiesEntityType.Activity:// activity is a comment posted to activity with id `source.id`break;caseCommunitiesEntityType.User:// activity is posted to feed of user with id `source.id`break;}
constactivity=...;// your activityconstsource=activity.source;switch(source.type){caseCommunitiesEntityType.Topic:// posted to topic with id `source.id`break;caseCommunitiesEntityType.Activity:// activity is a comment to another activity with id `source.id`break;caseCommunitiesEntityType.User:// activity is posted into feed of the user with id `source.id`break;}