예제 #1
0
        private async void GetAllForUsers(IEnumerable <string> users)
        {
            List <ViewModels.Rant> added = new List <ViewModels.Rant>();

            foreach (string user in users)
            {
                try
                {
                    Profile profile = await api.GetProfileAsync(user);

                    foreach (var rant in profile.Rants)
                    {
                        ViewModels.Rant r = new ViewModels.Rant(rant);
                        r.UpdateText = MakeMessage(Enums.ProfileContentType.Rants, user);

                        added.Add(r);
                    }
                }
                catch (Exception e)
                {
                    var st = e.StackTrace;
                }
            }

            SendUpdate(UpdateType.GetAllForUser, added.Count, string.Join(", ", users));
        }
예제 #2
0
        //TODO: NEed lastTime? IsRead should be enough?
        //Check if isRead is stored even if Filter is false
        private void AddTo(long lastTime, string username, ProfileContentType type, List <Dtos.Rant> rants, List <ViewModels.Rant> added)
        {
            foreach (var rant in rants)
            {
                if (rant.CreatedTime > lastTime)
                {
                    if (!history.IsRead(rant.Id))
                    {
                        ViewModels.Rant r = new ViewModels.Rant(rant);
                        r.UpdateText = MakeMessage(type, username);

                        added.Add(r);
                    }
                }
            }
        }
예제 #3
0
        private async void RunChecker(int version)
        {
            AppManager manager = AppManager.Instance;

            try
            {
                while (true)
                {
                    if (!IsLatest(version))
                    {
                        break;
                    }
                    RemoveRead();


                    long lastTime = manager.Settings.FollowedRantsLastChecked;

                    if (lastTime == 0)
                    {
                        lastTime = Utilities.ToUnixTime(DateTime.Today);
                    }

                    DateTime start = DateTime.Now;
                    List <ViewModels.Rant> added = new List <ViewModels.Rant>();

                    List <long> rantIds = manager.DB.GetSubscribedRantIds();

                    foreach (long rantId in rantIds)
                    {
                        Dtos.Rant rant = await manager.API.GetRant(rantId);

                        long userId = rant.UserId;

                        foreach (var comment in rant.Comments)
                        {
                            if (comment.CreatedTime > lastTime)
                            {
                                var vm = new ViewModels.Rant(rant);
                                vm.UpdateText = "A new comment was added by " + rant.Username;
                                AppManager.Instance.AddUpdate(vm);
                            }
                        }
                    }

                    if (!IsLatest(version))
                    {
                        break;
                    }

                    long?newTime = null;
                    if (added.Count > 0)
                    {
                        long latest = added.Max(x => x.RawCreateTime);

                        foreach (var r in added)
                        {
                            Posts.Add(r);
                        }

                        newTime = latest;
                    }
                    else
                    {
                        manager.Settings.FollowedRantsLastChecked = Utilities.ToUnixTime(start);
                    }

                    SendUpdate(UpdateType.UpdatedRants);

                    Thread.Sleep(manager.Settings.FollowedRantsInterval);
                }
            }
            catch (Exception ex)
            {
                SendUpdate(UpdateType.Error, error: ex);
            }
        }