Пример #1
0
        /// <summary>
        /// Add the supplied time line activity to the time lien groups
        /// </summary>
        /// <param name="timelineGroupModel">timline group model updated</param>
        /// <param name="activityOnMeme"></param>
        /// <param name="maxCount"></param>
        private void AddActivitytoTimeLineGroups(ref TimelineGroupModel timelineGroupModel, ITimeLine activityOnMeme, int maxCount)
        {
            // Find a time line group has has activity on thie meme already
            TimelineGroup existingTimelineGroup =
                timelineGroupModel.TimelineGroups.FirstOrDefault(x => x.Meme.Id == activityOnMeme.TimeLineRefId);

            if (existingTimelineGroup != null)
            {
                // Don't add more than 10
                if (existingTimelineGroup.TimelineEntries.Count < maxCount)
                {
                    // Don't re-add an timeline entry that is already there
                    if (existingTimelineGroup.TimelineEntries.Any(x => x.TimelineId == activityOnMeme.Id) == false)
                    {
                        existingTimelineGroup.TimelineEntries.Add(GetTimelineEntryModel(activityOnMeme));
                    }
                }
                else
                {
                    // If more than 10 just flag as having more
                    existingTimelineGroup.HasMore = true;
                }
            }
            else
            {
                var timeLineGroup = new TimelineGroup();
                timeLineGroup.TimeStamp       = activityOnMeme.DateOfEntry;
                timeLineGroup.Meme            = new MemeLiteModel(repository, repository.GetMeme(activityOnMeme.TimeLineRefId));
                timeLineGroup.TimelineEntries = new List <TimelineEntryModel> {
                    GetTimelineEntryModel(activityOnMeme)
                };

                timelineGroupModel.TimelineGroups.Add(timeLineGroup);
            }
        }
Пример #2
0
        public IHttpActionResult GetMemeTimeline(string id, int days, int maxCount)
        {
            TimelineGroupModel timelineGroupModel = new TimelineGroupModel
            {
                User           = null,
                TimelineGroups = new List <TimelineGroup>()
            };

            // Get the specified meme
            IMeme meme = repository.GetMeme(id);

            if (meme == null)
            {
                // Meme has been removed or the ID was invlide. No need to error out, handle gracefully
                return(Ok(timelineGroupModel));
            }

            // Determine the current user
            string currentUserId = User.Identity.UserId();
            var    currentUser   = repository.GetUser(currentUserId);

            // Restrict the activity returned to the current user and those he/she follows UNLESS THE CURRENT USER CREATED THE MEME
            bool includeActivityOfAllUsers = meme.CreatedByUserId == currentUserId;

            // Get the activity of the current user and those he/she follows (grouped by meme)
            List <string> userIds = new List <string> {
                currentUserId
            };

            userIds.AddRange(currentUser.FollowingIds.Select(x => x.Id));

            // Get all activity on this meme in the last X days, buy ANY user
            List <ITimeLine> memeActivities = repository.GetMemeTimeLine(id, days).OrderByDescending(x => x.DateOfEntry).ToList();


            // Create the timeline group with all activity on this meme by the current user and those he/she follows
            foreach (ITimeLine memeActivity in memeActivities)
            {
                // Was this activity performed the current user or  those he/she follows?
                if (userIds.Contains(memeActivity.UserId) || includeActivityOfAllUsers)
                {
                    // Add to model up to a max count
                    AddActivitytoTimeLineGroups(ref timelineGroupModel, memeActivity, maxCount);
                }
            }
            Debug.Assert(timelineGroupModel.TimelineGroups.Count <= 1, "Activity on single meme should only render one time line group!!!");

            // Ensure the timeline entries in each group are ordered descending by date of entry ... there should be only 1 group
            timelineGroupModel.TimelineGroups.ForEach(x =>
            {
                x.TimelineEntries = x.TimelineEntries.OrderByDescending(y => y.DateOfEntry).ToList();
            });

            // Order by date descending
            timelineGroupModel.TimelineGroups = timelineGroupModel.TimelineGroups.OrderByDescending(x => x.TimeStamp).ToList();

            return(Ok(timelineGroupModel));
        }
Пример #3
0
        public IHttpActionResult GetComprehensive(string id, int days, int maxCount)
        {
            // Get all memes posted or reposted by the user with any activity by ANY user in the last X days
            List <ITimeLine> activityOnUserPostedMemes = repository.GetUserMemeTimeLine(id, 30000).OrderByDescending(x => x.DateOfEntry).ToList();

            TimelineGroupModel timelineGroupModel = new TimelineGroupModel
            {
                User           = repository.GetUser(id, true),
                TimelineGroups = new List <TimelineGroup>()
            };

            foreach (ITimeLine activityOnUserPostedMeme in activityOnUserPostedMemes)
            {
                AddActivitytoTimeLineGroups(ref timelineGroupModel, activityOnUserPostedMeme, maxCount);
            }

            TimelineModel model = new TimelineModel
            {
                User            = repository.GetUser(id, true),
                TimelineEntries = new List <TimelineEntryModel>()
            };

            // Get the activity of the user and all his/her followers (grouped by meme)
            List <string> userIds = new List <string> {
                id
            };

            userIds.AddRange(model.User.FollowingIds.Select(x => x.Id));

            foreach (string userId in userIds)
            {
                // Get the activity of the user for the last x number of days
                List <ITimeLine> activity = repository.GetUserTimeLine(userId, days).OrderByDescending(x => x.DateOfEntry).ToList();
                foreach (ITimeLine entry in activity)
                {
                    AddActivitytoTimeLineGroups(ref timelineGroupModel, entry, maxCount);
                }
            }

            // Ensure the timeline entries in each group are ordered descending by date of entry
            timelineGroupModel.TimelineGroups.ForEach(x =>
            {
                x.TimelineEntries = x.TimelineEntries.OrderByDescending(y => y.DateOfEntry).ToList();
            });

            // Order by date descending
            timelineGroupModel.TimelineGroups = timelineGroupModel.TimelineGroups.OrderByDescending(x => x.TimeStamp).ToList();

            return(Ok(timelineGroupModel));
        }