public async Task GetActivityView()

in code/Server/Common/Managers/ViewsManager.cs [760:922]


        public async Task<ActivityView> GetActivityView(
            string activityHandle,
            ActivityType activityType,
            string actorUserHandle,
            string actedOnUserHandle,
            ContentType actedOnContentType,
            string actedOnContentHandle,
            string appHandle,
            DateTime createdTime,
            string readActivityHandle,
            string queryingUserHandle)
        {
            // check key input values
            if (string.IsNullOrWhiteSpace(activityHandle))
            {
                this.log.LogException("activityHandle is required");
            }

            // form the activity view
            ActivityView view = new ActivityView()
            {
                ActivityHandle = activityHandle,
                CreatedTime = createdTime,
                ActivityType = activityType,
                ActorUsers = new List<UserCompactView>(),
                ActedOnUser = null, // may be filled in below
                ActedOnContent = null, // may be filled in below
                TotalActions = 1,
                Unread = readActivityHandle == null ? true : string.CompareOrdinal(readActivityHandle, activityHandle) > 0,
                App = null // may be filled in below
            };

            // get the actor user; this can be null for "my activity"
            Task<UserCompactView> taskActorUser = null;
            if (!string.IsNullOrWhiteSpace(actorUserHandle))
            {
                taskActorUser = this.GetUserCompactView(actorUserHandle, appHandle, queryingUserHandle);
            }

            // get the acted on user; this can be null sometimes to save on a table lookup
            Task<UserCompactView> taskActedOnUser = null;
            if (!string.IsNullOrWhiteSpace(actedOnUserHandle))
            {
                taskActedOnUser = this.GetUserCompactView(actedOnUserHandle, appHandle, queryingUserHandle);
            }

            // get the acted on content; this can be null for follower/following activities
            Task<ContentCompactView> taskActedOnContent = null;
            if (actedOnContentHandle != null)
            {
                taskActedOnContent = this.GetContentCompactView(actedOnContentType, actedOnContentHandle, queryingUserHandle);
            }

            Task<ContentCompactView> taskContent = null;
            if (activityType == ActivityType.Comment)
            {
                taskContent = this.GetContentCompactView(ContentType.Comment, activityHandle, queryingUserHandle);
            }
            else if (activityType == ActivityType.Reply)
            {
                taskContent = this.GetContentCompactView(ContentType.Reply, activityHandle, queryingUserHandle);
            }

            Task<AppCompactView> taskApp = null;
            if (appHandle != null)
            {
                taskApp = this.GetAppCompactView(appHandle);
            }

            Task<ILikeLookupEntity> taskLikeLookup = null;
            if (activityType == ActivityType.Like)
            {
                taskLikeLookup = this.likesStore.QueryLike(actedOnContentHandle, actorUserHandle);
            }

            Task<IUserRelationshipLookupEntity> taskFollowerLookup = null;
            if (actedOnUserHandle != null && (activityType == ActivityType.Following || activityType == ActivityType.FollowRequest))
            {
                taskFollowerLookup = this.userRelationshipsStore.QueryFollowerRelationship(actedOnUserHandle, actorUserHandle, appHandle);
            }

            if (taskActorUser != null)
            {
                var actorUser = await taskActorUser;
                if (actorUser == null)
                {
                    // this can happen when the user has been deleted. Don't generate an activity in this situation.
                    return null;
                }

                view.ActorUsers.Add(actorUser);
            }

            if (taskActedOnContent != null)
            {
                var actedOnContent = await taskActedOnContent;
                if (actedOnContent == null)
                {
                    return null;
                }

                view.ActedOnContent = actedOnContent;
            }

            if (taskContent != null)
            {
                var content = await taskContent;
                if (content == null)
                {
                    return null;
                }
            }

            if (taskActedOnUser != null)
            {
                view.ActedOnUser = await taskActedOnUser;
                if (view.ActedOnUser == null)
                {
                    // this can happen when the user has been deleted. Don't generate an activity in this situation.
                    return null;
                }
            }

            if (taskApp != null)
            {
                view.App = await taskApp;
                if (view.App == null)
                {
                    return null;
                }
            }

            if (taskLikeLookup != null)
            {
                var likeLookupEntity = await taskLikeLookup;
                if (likeLookupEntity == null || !likeLookupEntity.Liked || likeLookupEntity.LikeHandle != activityHandle)
                {
                    return null;
                }
            }

            if (taskFollowerLookup != null)
            {
                var followerLookupEntity = await taskFollowerLookup;
                if (activityType == ActivityType.Following)
                {
                    if (followerLookupEntity == null || followerLookupEntity.UserRelationshipStatus != UserRelationshipStatus.Follow)
                    {
                        return null;
                    }
                }

                if (activityType == ActivityType.FollowRequest)
                {
                    if (followerLookupEntity == null || followerLookupEntity.UserRelationshipStatus != UserRelationshipStatus.Pending)
                    {
                        return null;
                    }
                }
            }

            return view;
        }