Exemple #1
0
        internal static async Task <bool> OpenFeedItem(FeedItem item, IDevRantClient api, Window owner)
        {
            if (item is ViewModels.Notification)
            {
                var notif = item.AsNotification();
                var raw   = await api.GetRant(notif.RantId);

                item = new ViewModels.Rant(raw);
            }
            else if (item is ViewModels.Comment)
            {
                var raw = await api.GetRant(item.AsComment().RantId);

                item = new ViewModels.Rant(raw);
            }


            if (item is ViewModels.Rant)
            {
                var rant = item.AsRant();

                if (rant.CanAnimate == Visibility.Visible) //TODO: should be bool
                {
                    string url = GetRantUrl(rant.RantId);
                    Process.Start(url);
                }
                else
                {
                    Window dlg;
                    dlg = new RantViewerWindow((ViewModels.Rant)item, api);

                    dlg.Owner = owner;
                    dlg.ShowDialog();
                }
            }
            else if (item is ViewModels.Collab)
            {
                string url = GetRantUrl(item.AsCollab().RantId);
                Process.Start(url);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        private async Task LoadFeed(FeedType type, RantSort sort = RantSort.Algo, RantRange range = RantRange.Day, bool filter = false)
        {
            currentFeedType = type;

            Func <int, int, Task <IReadOnlyCollection <Dtos.Rant> > > getter;

            ValuesCollection otherVals = new ValuesCollection();

            switch (type)
            {
            case FeedType.General:
                getter = async(skip, limit) => await api.Feeds.GetRantsAsync(sort : sort, range : range, skip : skip, limit : limit, settings : otherVals);

                break;

            case FeedType.Stories:
                getter = async(skip, limit) => await api.Feeds.GetStoriesAsync(range : range, sort : sort, skip : skip, limit : limit);

                break;

            default:
                return;
            }

            List <Dtos.Rant> rants = new List <Dtos.Rant>();

            //Used to remove duplicates
            List <long> ids = new List <long>();

            int  maxPages  = ds.MaxPages;
            bool useOffset = true; //ds.UseOffset

            var lim      = ds.ResultsLimit;
            int minScore = ds.MinScore;


            int page = 0;

            if (useOffset)
            {
                page     = maxPages * offset;
                maxPages = (offset + 1) * maxPages;
            }


            bool shouldIncrement = true;

            while (rants.Count < lim && page < maxPages)
            {
                int skip = page * lim;

                try
                {
                    var tmp = await getter.Invoke(skip, lim);

                    if (tmp == null || tmp.Count == 0)
                    {
                        ResetOffset();
                        shouldIncrement = false;
                        break;
                    }

                    foreach (var r in tmp)
                    {
                        if (ids.Contains(r.Id) ||
                            r.Username == LoggedInUser ||
                            VoteState.None != r.Voted ||
                            r.Score < minScore ||
                            (ds.FilterOutRead && db.IsRead(r.Id)))
                        {
                            continue;
                        }

                        rants.Add(r);
                        ids.Add(r.Id);
                    }
                }
                catch (Exception e)
                {
                }

                page++;
            }

            if (useOffset && shouldIncrement)
            {
                IncrementOffset();
            }

            lock (feed_lock)
            {
                feeds.Clear();

                foreach (var rant in rants)
                {
                    ViewModels.Rant r = new ViewModels.Rant(rant);
                    feeds.Add(r);
                }
            }

            if (otherVals.Count > 0 && otherVals.ContainsKey(ValuesCollection.NumNotifs))
            {
                int count = Convert.ToInt32(otherVals[ValuesCollection.NumNotifs]);
                if (count > 0)
                {
                    //Just refresh
                    nchecker.Check();
                }


                UpdateNotifications(new NotificationsChecker.UpdateArgs(count, count));
            }

            UpdateFollowedInRants();
            feedView.SortDescriptions.Clear();

            string message = "Loaded {0} rants from {1} pages";

            UpdateStatus(string.Format(message, rants.Count, page));
        }