Esempio n. 1
0
        private Task <IEnumerable <PocketItem> > GetLastArticlesSinceLastProcessingDate(User user, int articlesAmount)
        {
            _pocketClient.AccessCode = user.AccessCode;

            return(_pocketClient.Get(
                       state: State.unread,
                       contentType: ContentType.article,
                       sort: Sort.newest,
                       since: user.LastProcessingDate,
                       count: articlesAmount));
        }
        /// <summary>
        /// Moves Article from pocket to list
        /// </summary>
        /// <returns></returns>
        public Article MoveArticleFromPocketByTag(string tag)
        {
            logger.LogDebug($"Starting downloading article for tag:{tag}");
            var items = pocketClient.Get(state: State.unread, tag: tag, sort: Sort.newest);

            items.Wait();

            var item = items.Result.FirstOrDefault();

            if (item == null)
            {
                logger.LogWarning($"Tag {tag} has no more articles");
                return(null);
            }
            var id = item.ID;

            logger.LogInformation($"Article ID :{id}");
            var article = PocketMapper.Map(item);

#if !TEST
            pocketClient.Archive(id);
#endif
            return(article);
        }
Esempio n. 3
0
        private async Task GoToWeb()
        {
            var dateSince = CacheService.GetSinceDate(SourceProvider.Pocket);
            var theItems  = await _pocketClient.Get(since : dateSince, count : Constants.MaxArticleCount);

            var items = theItems.Where(x => !x.IsVideo && !x.IsVideo).Select(x => x.Extend()).ToList();

            if (items.IsNullOrEmpty())
            {
                return;
            }

            var noPocketItems = Items.IsNullOrEmpty();

            // Handle deleted/archived Items
            foreach (var item in items.Where(x => x.IsDeleted || x.IsArchive).ToList())
            {
                if (noPocketItems)
                {
                    break;
                }

                foreach (var r in Items.ToList())
                {
                    if (r.Id == item.ID)
                    {
                        Items.Remove(r);
                    }
                }

                items.Remove(item);
            }

            // Make sure articles aren't already in the list
            foreach (var a in items.ToList())
            {
                if (noPocketItems)
                {
                    break;
                }

                var existingItem = Items.FirstOrDefault(x => x.Id == a.ResolvedId);
                if (existingItem != null)
                {
                    var updatedItem = a.ToReaderItem();
                    updatedItem.CopyItem(existingItem);
                    items.Remove(a);
                }
            }

            var list = items.Select(x => x.ToReaderItem()).ToList();

            // Now we actually add any new items
            if (noPocketItems)
            {
                Items = new ObservableCollection <ReaderItem>(list.Take(Constants.MaxArticleCount));
            }
            else
            {
                var i = 0;
                foreach (var item in list)
                {
                    Items.Insert(i, item);
                    if (Items.Count > Constants.MaxArticleCount - 1)
                    {
                        Items.RemoveAt(Constants.MaxArticleCount);
                    }

                    i++;
                }
            }

            await CacheService.SavePocketItems(Items).ConfigureAwait(false);

            DataLoaded = true;
        }