private async Task <bool> ProcessDeleteTweetEvent(TweetEvent tweetEvent)
        {
            var tweet = await _tweetRepository.Get(tweetEvent.TweetId);

            if (tweet == null)
            {
                Console.WriteLine("No tweet found");
                return(true);
            }
            var homeTimeLineEntry = new HomeTimeLineEntry
            {
                TweetId = tweetEvent.TweetId
            };

            var deletedItems = await _timeLineRepository.DeleteTweetFromHomeTimeLine(tweet.AuthorId, homeTimeLineEntry);

            return(deletedItems > 0);
        }
示例#2
0
        // TODO: need to test the NewsFeedTimeLine functionality
        public async Task <Result <bool> > ProcessTweetEvent(TweetEvent tweetEvent)
        {
            if (tweetEvent is null)
            {
                throw new System.ArgumentNullException(nameof(tweetEvent));
            }
            var result = new Result <bool>();
            var tweet  = await _tweetRepository.Get(tweetEvent.TweetId);

            if (tweet == null || tweet.Id < 1)
            {
                Console.WriteLine("Could not find any tweet");
                result.SuccessResult = true;
                return(result);
            }

            var userId = tweet.AuthorId;

            var followersTask = _followsLogic.GetFollowers(userId);

            var followersResult = followersTask.Result;


            var userIds = new List <long>();

            userIds.Add(userId);

            if (followersResult.SuccessResult.IsNotEmpty())
            {
                userIds.AddRange(followersResult.SuccessResult.Select(follows => follows.FollowerId));
            }
            if (tweetEvent.Type == TweetEventType.Created)
            {
                await ProcessCreateTweetEvent(userIds, tweetEvent);
            }
            else if (tweetEvent.Type == TweetEventType.Deleted)
            {
                await ProcessDeleteTweetEvent(userIds, tweetEvent);
            }
            else
            {
                throw new BusinessException("Unhandled Tweet Event Type");
            }

            result.SuccessResult = true;

            return(result);
        }