Beispiel #1
0
        private async Task ProcessNewStories(NewsFeed localFeed, StoriesResponse result)
        {
            var addedNewStory = false;

            _dataCacheService.BeginWrite();

            foreach (var story in result.Stories)
            {
                var storyId     = story.Id;
                var storyExists = (await _dataCacheService.GetStories(fe => fe.Id == storyId)).FirstOrDefault();
                if (storyExists == null)
                {
                    string summary = "";
                    if (!string.IsNullOrEmpty(story.Content))
                    {
                        summary = Regex.Replace(story.Content, "<.*?>", string.Empty);
                        if (summary.Length > 150)
                        {
                            summary = summary.Substring(0, 150);
                        }
                    }

                    Story s = new Story
                    {
                        Id         = storyId,
                        Title      = story.Title,
                        FeedId     = story.FeedId,
                        ReadStatus = story.ReadStatus,
                        //story.story_timestamp
                        Author    = story.Authors,
                        TimeStamp = story.Timestamp,
                        ListImage = story.ImageUrls.Any() ? story.ImageUrls[0] : "",
                        Content   = story.Content,
                        Summary   = summary,
                        Feed      = localFeed
                    };

                    _dataCacheService.AddStory(s);
                    addedNewStory = true;
                }
            }
            if (addedNewStory)
            {
                localFeed.UnreadCount = (await _dataCacheService.GetStories(st => st.ReadStatus == 0 && st.Feed == localFeed)).Count;
            }

            // no need to do a story pass until this changes
            localFeed.DownloadedLastStoryDate = localFeed.LastStoryDateFromService;
            _dataCacheService.Commit();
        }
Beispiel #2
0
 public async Task SelectFeed(NewsFeed newsFeed)
 {
     StoryItemSource.Clear();
     StoryItemSource.AddRange(await _dataCacheService.GetStories(x => x.FeedId == newsFeed.Id && x.ReadStatus == 0));
 }