November Happy Hour will be moved to Thursday December 5th.

Story attachments

Vote:
 

Hi!

When creating a NewsFeedStory I have a option to add story attachments as a collection of IEntity. 

How do I query to get stories with related attachments? Have I misunderstanded the use of story attachments?

I want to add a story related to a club with a related attachment of a Topic

 

var storyAttachments = new EntityCollection(); storyAttachments.Add(topic);  var story = NewsFeedHandler.AddStoryToActorFeed(new NewsFeedStory(NewsFeedActions.ActionClubForumTopicCreated, CurrentUser, storyAttachments, CurrentClub));

 

I want to get all stories related to the specific club with attachments:

 

var stories = NewsFeedHandler.GetTargetFeed(CurrentClub, null, DateTime.MinValue, DateTime.MinValue, 1, int.MaxValue); 

 

I cant see that "stories" in this case contains anything like attachments?

Regards,
Anton Kallenberg 

#32176
Aug 25, 2009 10:33
Vote:
 

After spending some time with Reflector i found the object "NewsFeedStoryActor"

Final code, please correct me

 

if (base.CurrentStory.Targets.Count > 0) { if (CurrentStory.Targets[0] is Club) { Club club = CurrentStory.Targets[0] as Club; var storyActor = NewsFeedHandler.GetStoryActor(CurrentStory.ID); if (storyActor.Attachments.Count > 0) { if (storyActor.Attachments[0] is Topic) { var topic = storyActor.Attachments[0] as Topic; if (topic != null) { //do stuff } } } } }     

 

 

#32193
Aug 25, 2009 14:45
Vote:
 

The reason why they hide it behind the actor property is probably because that the story could be aggregated and the each actor has its own set of attachments.

Your code seems right. We wrapped it up in this extension method, it might help you:

public static T GetAttachmentOfType<T>(this NewsFeedStory story)

where T : class, IFrameworkEntity

{

NewsFeedStoryActor actor = story.Actors.FirstOrDefault();

if (actor == null)

return default(T);

else

return actor.Attachments.SingleOrDefault(att => att.GetType() == typeof(T)) as T;

}

#32225
Aug 26, 2009 11:40
Vote:
 

Hi!

Yeah probably, nice extension!

Thanks again! 

#32226
Aug 26, 2009 11:45
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.