Beispiel #1
0
        private async Task <UserLatestUpdateTime> GetUserLatestUpdateTime(string userId)
        {
            var zero = new UserLatestUpdateTime
            {
                UserId           = userId,
                LatestUpdateTime = DateTime.MinValue
            };

            return(await _userLatestUpdateTimesRepository.GetAsync(userId) ?? zero);
        }
Beispiel #2
0
        private IAsyncEnumerable <Update> GetNewUpdates(
            IEnumerable <Update> updates,
            UserLatestUpdateTime userLatestUpdateTime)
        {
            var newUpdates = updates
                             .Where(IsNew(userLatestUpdateTime))
                             .OrderBy(update => update.CreationDate)
                             .ToAsyncEnumerable();

            if (_config.StoreSentUpdates)
            {
                return(newUpdates.WhereAwait(NotSent));
            }

            return(newUpdates);
        }
        public async Task AddOrUpdateAsync(string userId, DateTime latestUpdateTime)
        {
            var updateTime = new UserLatestUpdateTime
            {
                UserId           = userId,
                LatestUpdateTime = latestUpdateTime
            };

            UserLatestUpdateTime newEntity = await _collection
                                             .FindOneAndReplaceAsync(
                userLatestUpdateTime => userLatestUpdateTime.UserId == userId,
                updateTime);

            if (newEntity == null)
            {
                await _collection.InsertOneAsync(updateTime);
            }
        }
Beispiel #4
0
        private async IAsyncEnumerable <Update> GetUpdates(
            string userId,
            [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            IEnumerable <Update> updates = await _updatesProvider.GetUpdatesAsync(userId);

            List <Update> sortedUpdates = updates
                                          .Reverse()
                                          .OrderBy(update => update.CreationDate).ToList();

            UserLatestUpdateTime userLatestUpdateTime = await GetUserLatestUpdateTime(userId);

            ConfiguredCancelableAsyncEnumerable <Update> newUpdates = GetNewUpdates(sortedUpdates, userLatestUpdateTime)
                                                                      .WithCancellation(cancellationToken);

            await foreach (Update update in newUpdates)
            {
                yield return(update.Media?.Any() == true
                    ? await WithExtractedVideo(update, cancellationToken)
                    : update);
            }
        }
Beispiel #5
0
 private static Func <Update, bool> IsNew(UserLatestUpdateTime userLatestUpdateTime)
 {
     return(update => update.CreationDate != null &&
            update.CreationDate > userLatestUpdateTime.LatestUpdateTime);
 }