An IActivityStoryType allows the user to push story items to the activity stream in a group or main page.
[toc]
Why should I create Activity Stories?
When performing actions upon a community providing a stream of events will allow the user's to view the activity at a glance. A good example is when a user adds an event to the calendar an activity story can provide users the information they need. Telligent Community provides support for posting stories in the activity stream via the IActivityStoryType Plugin Type.
Creating an ActivityStoryType Plugin
To add support for creating stories, implement the IActivityStoryType plugin (which requires a reference to Telligent.Evolution.Api.dll, Telligent.Evolution.Components.dll and Telligent.Evolution.Core.dll). The IActivityStoryType interface extends IPlugin to add support for activity stories.
To begin you'll need to generate a Guid and return it as the StoryTypeId
.
public Guid StoryTypeId { get { return new Guid("247A9821-75F0-4E57-81E2-15B9D0578491"); } }
After setting up the Id the story type requires a StoryTypeName
and StoryTypeDescription
. They are used in the administration panel under the Activity Stream > Options tab. Here you can select new activity default settings.
public string StoryTypeName { get { return "My Activity Stories"; } } public string StoryTypeDescription { get { return "Controls activity stories for My Activity Stories."; } }
Activity stories can allow the user to delete an individual story. The CanDeleteStory
method accepts a storyId
and a userId
. These id's can be used to find a particular story as well as a user. Then depending on your requirements return a boolean value that will allow a user to remove an item. In this sample we verify the user is logged in and not an anonymous user then we determine if the user is one of the actors of the story. An actor can be defined as a user or users that took part in a particular activity.
public bool CanDeleteStory(Guid storyId, int userId) { Apis.Get<EventLog>().Write("", new EventLogEntryWriteOptions()); // unregistered users cannot delete stories var user = Apis.Get<Users>().Get(new UsersGetOptions { Id = userId }); var userIsRegistered = user != null && !user.IsSystemAccount.GetValueOrDefault(false); if (!userIsRegistered) { return false; } // actors can delete var story = Apis.Get<ActivityStories>().Get(storyId); return story != null && story.Actors != null && story.Actors.ToList().Exists(actor => actor.UserId == userId); }
The ContentTypeIds
property returns a list of id's related to the content that the stories belong to. Typically it is related to one type but can be set to multiple types.
public Guid[] ContentTypeIds { get { return new[] { Apis.Get<Users>().ContentTypeId }; } }
In some cases the story must present a summary of the activity. Usually it is recommended to limit the summary to a single sentence. This is done in the GetPreviewHtml
method.
public string GetPreviewHtml(IActivityStory story, Target target) { var content = Apis.Get<Contents>().Get(story.ContentId.GetValueOrDefault(), story.ContentTypeId.GetValueOrDefault()); if (content == null) return null; return string.Format("<h3>{0}</h3>", content.HtmlName("Web")); }
The full detail
Here's the complete source of our sample activity story type plugin: