public async Task <IHttpActionResult> PostFollowingTopic([FromBody] PostFollowingTopicRequest request) { string className = "MyFollowingController"; string methodName = "PostFollowingTopic"; string logEntry = $"FollowingTopicHandle = {request?.TopicHandle}"; this.LogControllerStart(this.log, className, methodName, logEntry); // Call the RelationshipControllerBase's method for updating the relationship. This method of the base class takes care of tracing also. return(await this.UpdateRelationshipToTopic(className, methodName, RelationshipOperation.FollowTopic, request.TopicHandle)); }
/// <summary> /// Follow a topic /// </summary> /// When I follow a topic, that topic will appear on my following topics feed. /// When users /// perform actions on the topic (such as posting comments or /// replies), those actions will /// appear on my following activites feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post following topic request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> PostFollowingTopicAsync(this IMyFollowing operations, PostFollowingTopicRequest request, string authorization, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostFollowingTopicWithHttpMessagesAsync(request, authorization, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Follow a topic /// </summary> /// When I follow a topic, that topic will appear on my following topics feed. /// When users /// perform actions on the topic (such as posting comments or /// replies), those actions will /// appear on my following activites feed. /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='request'> /// Post following topic request /// </param> /// <param name='authorization'> /// Format is: "Scheme CredentialsList". Possible values are: /// /// - Anon AK=AppKey /// /// - SocialPlus TK=SessionToken /// /// - Facebook AK=AppKey|TK=AccessToken /// /// - Google AK=AppKey|TK=AccessToken /// /// - Twitter AK=AppKey|RT=RequestToken|TK=AccessToken /// /// - Microsoft AK=AppKey|TK=AccessToken /// /// - AADS2S AK=AppKey|[UH=UserHandle]|TK=AADToken /// </param> public static object PostFollowingTopic(this IMyFollowing operations, PostFollowingTopicRequest request, string authorization) { return(Task.Factory.StartNew(s => ((IMyFollowing)s).PostFollowingTopicAsync(request, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public async Task FollowingTopicLikeActivityTest() { // Setup three users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var user3 = await TestUtilities.PostGenericUser(client3); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); var auth3 = AuthHelper.CreateSocialPlusAuth(user3.SessionToken); // user1 creates a topic var postTopicResponse = await TestUtilities.PostGenericTopic(client1, auth1); string topicHandle = postTopicResponse.TopicHandle; // user2 requests to follow user1's topic PostFollowingTopicRequest followingTopicReq = new PostFollowingTopicRequest() { TopicHandle = topicHandle }; HttpOperationResponse postFollowingResponse = await client2.MyFollowing.PostFollowingTopicWithHttpMessagesAsync(followingTopicReq, authorization : auth2); // user3 posts a like on user1's topic -- this causes a Like activity to be sent to users following the topic var postLikeOperationResponse = await client3.TopicLikes.PostLikeWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth3); HttpOperationResponse <FeedResponseActivityView> activitiesResponse = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // because user2 follows the topic, user2 should receive an activity indicating that user3 liked a topic activitiesResponse = await client2.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth2); }, () => { // verify that user2 sees 1 activity, whose type is Like Assert.AreEqual(1, activitiesResponse.Body.Data.Count); Assert.AreEqual(ActivityType.Like, activitiesResponse.Body.Data[0].ActivityType); }); // clean up the topic HttpOperationResponse deleteTopic = await client1.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth1); // clean up the two users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); HttpOperationResponse deleteUserOperationResponse3 = await client3.Users.DeleteUserWithHttpMessagesAsync(authorization : auth3); IList <ActivityView> activityList = activitiesResponse.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Like, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user3.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(user1.UserHandle, activityList[0].ActedOnUser.UserHandle); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); }
public async Task FollowingTopicActivityTest() { // Setup three users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var user3 = await TestUtilities.PostGenericUser(client3); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); var auth3 = AuthHelper.CreateSocialPlusAuth(user3.SessionToken); // user2 requests to follow user1 PostFollowingUserRequest followingUserReq = new PostFollowingUserRequest() { UserHandle = user1.UserHandle }; HttpOperationResponse postFollowingResponse = await client2.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq, authorization : auth2); // user3 requests to follow user1 PostFollowingUserRequest followingUserReq2 = new PostFollowingUserRequest() { UserHandle = user1.UserHandle }; HttpOperationResponse postFollowingResponse2 = await client3.MyFollowing.PostFollowingUserWithHttpMessagesAsync(followingUserReq2, authorization : auth3); // user2 creates a topic var postTopicResponse = await TestUtilities.PostGenericTopic(client2, auth2); string topicHandle = postTopicResponse.TopicHandle; // user1 follows the topic created by user2 PostFollowingTopicRequest followingTopicReq = new PostFollowingTopicRequest() { TopicHandle = topicHandle }; HttpOperationResponse postFollowingResponse3 = await client1.MyFollowing.PostFollowingTopicWithHttpMessagesAsync(followingTopicReq, authorization : auth1); // fetch user1's combined following topics feed HttpOperationResponse <FeedResponseTopicView> combinedFollowingTopics = await client1.MyFollowing.GetTopicsWithHttpMessagesAsync(authorization : auth1); // check that both user2 and user3 receive the activity generated when user1 follows the topic HttpOperationResponse <FeedResponseActivityView> activitiesResponse1 = null; HttpOperationResponse <FeedResponseActivityView> activitiesResponse2 = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { activitiesResponse1 = await client2.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth2); activitiesResponse2 = await client3.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth3); }, () => { // verify that user2 and user3 both see 1 activity, whose type is Following Assert.AreEqual(1, activitiesResponse1.Body.Data.Count); Assert.AreEqual(ActivityType.Following, activitiesResponse1.Body.Data[0].ActivityType); Assert.AreEqual(1, activitiesResponse2.Body.Data.Count); Assert.AreEqual(ActivityType.Following, activitiesResponse2.Body.Data[0].ActivityType); }); // clean up the topic HttpOperationResponse deleteTopic = await client2.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth2); // clean up the three users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); HttpOperationResponse deleteUserOperationResponse3 = await client3.Users.DeleteUserWithHttpMessagesAsync(authorization : auth3); // check the result of the combined following topics feed Assert.AreEqual(1, combinedFollowingTopics.Body.Data.Count); Assert.AreEqual(topicHandle, combinedFollowingTopics.Body.Data[0].TopicHandle); // check the activity results IList <ActivityView> activityList = activitiesResponse1.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Following, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user1.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(null, activityList[0].ActedOnUser); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); activityList = activitiesResponse2.Body.Data; Assert.AreEqual(1, activityList.Count); Assert.AreEqual(ActivityType.Following, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user1.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(null, activityList[0].ActedOnUser); Assert.AreEqual(topicHandle, activityList[0].ActedOnContent.ContentHandle); Assert.AreEqual(ContentType.Topic, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); }
public async Task FollowingTopicReplyActivityTest() { // Setup three users SocialPlusClient client1 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client2 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); SocialPlusClient client3 = new SocialPlusClient(TestConstants.ServerApiBaseUrl); var user1 = await TestUtilities.PostGenericUser(client1); var user2 = await TestUtilities.PostGenericUser(client2); var user3 = await TestUtilities.PostGenericUser(client3); var auth1 = AuthHelper.CreateSocialPlusAuth(user1.SessionToken); var auth2 = AuthHelper.CreateSocialPlusAuth(user2.SessionToken); var auth3 = AuthHelper.CreateSocialPlusAuth(user3.SessionToken); // user3 creates a topic var postTopicResponse = await TestUtilities.PostGenericTopic(client3, auth3); string topicHandle = postTopicResponse.TopicHandle; // user1 follows the topic created by user3 PostFollowingTopicRequest followingTopicReq = new PostFollowingTopicRequest() { TopicHandle = topicHandle }; HttpOperationResponse postFollowingResponse = await client1.MyFollowing.PostFollowingTopicWithHttpMessagesAsync(followingTopicReq, authorization : auth1); // user2 posts a comment on the topic -- this causes a Comment activity to be sent to the topic followers var postCommentResponse = await TestUtilities.PostGenericComment(client2, auth2, topicHandle); string commentHandle = postCommentResponse.CommentHandle; // user3 replies to user2's comment -- this causes a Reply activity to be sent to the topic followers var postReplyResponse = await TestUtilities.PostGenericReply(client3, auth3, commentHandle); string replyHandle = postReplyResponse.ReplyHandle; HttpOperationResponse <FeedResponseActivityView> activitiesResponse = null; await TestUtilities.AutoRetryServiceBusHelper( async() => { // because user1 follows the topic, user1 should receive an activity indicating that user3 replied to user2's comment activitiesResponse = await client1.MyFollowing.GetActivitiesWithHttpMessagesAsync(authorization: auth1); }, () => { // verify that user1 sees 2 activities, the first (newest) activity type is Reply Assert.AreEqual(2, activitiesResponse.Body.Data.Count); Assert.AreEqual(ActivityType.Reply, activitiesResponse.Body.Data[0].ActivityType); }); // clean up the reply, the comment and the topic HttpOperationResponse deleteReply = await client3.Replies.DeleteReplyWithHttpMessagesAsync(replyHandle : replyHandle, authorization : auth3); HttpOperationResponse deleteComment = await client2.Comments.DeleteCommentWithHttpMessagesAsync(commentHandle : commentHandle, authorization : auth2); HttpOperationResponse deleteTopic = await client3.Topics.DeleteTopicWithHttpMessagesAsync(topicHandle : topicHandle, authorization : auth3); // clean up the three users we created HttpOperationResponse deleteUserOperationResponse1 = await client1.Users.DeleteUserWithHttpMessagesAsync(authorization : auth1); HttpOperationResponse deleteUserOperationResponse2 = await client2.Users.DeleteUserWithHttpMessagesAsync(authorization : auth2); HttpOperationResponse deleteUserOperationResponse3 = await client3.Users.DeleteUserWithHttpMessagesAsync(authorization : auth3); IList <ActivityView> activityList = activitiesResponse.Body.Data; Assert.AreEqual(2, activityList.Count); Assert.AreEqual(ActivityType.Reply, activityList[0].ActivityType); Assert.AreEqual(1, activityList[0].ActorUsers.Count); Assert.AreEqual(user3.UserHandle, activityList[0].ActorUsers[0].UserHandle); Assert.AreEqual(user2.UserHandle, activityList[0].ActedOnUser.UserHandle); Assert.AreEqual(1, activityList[0].TotalActions); Assert.AreEqual(true, activityList[0].Unread); Assert.AreEqual(ContentType.Comment, activityList[0].ActedOnContent.ContentType); Assert.AreEqual(commentHandle, activityList[0].ActedOnContent.ContentHandle); }