Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Telligent.Evolution.Api.Services;
- using Telligent.Evolution.Extensibility;
- using Telligent.Evolution.Extensibility.Api.Version1;
- using Telligent.Evolution.Extensibility.Content.Version1;
- namespace MyActivityStory
- {
- public class MyActivityStory : IActivityStoryType
- {
- public string Name
- {
- get { return "My Activity Story Plugin"; }
- }
- public string Description
- {
- get { return "This plugin will demo how the IActivityStoryType works"; }
- }
- public void Initialize()
- {
- Apis.Get<IComments>().Events.AfterCreate += EventsOnAfterCreate;
- }
- private void EventsOnAfterCreate(CommentAfterCreateEventArgs e)
- {
- // Check to make sure the comment is for content via the REST API and not a comment on content.
- if (e.Content.ContentTypeId == new Guid("68C65AF2-AA15-4E4C-9C81-155C6A3159F6"))
- {
- CommentCreateStory(e.CommentId);
- }
- }
- public Guid StoryTypeId
- {
- get { return new Guid("c0bd2266-09ba-4304-aa60-eb58e4157d72"); }
- }
- public string StoryTypeName
- {
- get { return "My Activity Stories"; }
- }
- public string StoryTypeDescription
- {
- get { return "Controls activity stories for My Activity Stories."; }
- }
- public bool CanDeleteStory(Guid storyId, int userId)
- {
- // unregistered users cannot delete stories
- var user = Apis.Get<IUsers>().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);
- }
- public Guid[] ContentTypeIds
- {
- get { return new[] { Apis.Get<IComments>().ContentTypeId }; }
- }
- 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"));
- }
- public string GetViewHtml(IActivityStory story, Target target)
- {
- var content = Apis.Get<Contents>().Get(story.ContentId.GetValueOrDefault(), story.ContentTypeId.GetValueOrDefault());
- if (content == null) return null;
- return $"<h3>A comment was created</h3><p>{content.HtmlName("Web")}</p>";
- }
- public int? GetPrimaryUser(IActivityStory story)
- {
- if (story == null || story.Actors == null || story.Actors.Count == 0)
- {
- return null;
- }
- return story.Actors.Last().UserId;
- }
- private IActivityStoryController _storyController;
- public void SetController(IActivityStoryController controller)
- {
- _storyController = controller;
- }
- public bool IsCacheable
- {
- get { return true; }
- }
- public bool VaryCacheByUser
- {
- get { return true; }
- }
- private void CommentCreateStory(Guid commentId)
- {
- var comment = Apis.Get<IComments>().Get(commentId);
- _storyController.Create(new ActivityStoryCreateOptions
- {
- ContentId = comment.ContentId,
- ContentTypeId = comment.ContentTypeId,
- LastUpdate = DateTime.UtcNow,
- Actors = new List<ActivityStoryActor>
- {
- new ActivityStoryActor
- {
- UserId = comment.UserId,
- Verb = "Add",
- Date = DateTime.UtcNow
- }
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement