Exemplo n.º 1
0
        /// <summary>
        /// Comment on a specific rant using the RantSelector
        /// </summary>
        private async void ViewSpecificRant()
        {
            var rantSelector = new IDInputWindow(IDInputWindowViewModel.Type.Rant);

            rantSelector.Owner = window;

            rantSelector.ShowDialog();

            if (!string.IsNullOrEmpty(rantSelector.InputValue))
            {
                try
                {
                    Dtos.Rant rant = await api.GetRant(Convert.ToInt64(rantSelector.InputValue));

                    var dlg = new RantViewerWindow(new ViewModels.Rant(rant), api);
                    dlg.Owner = window;

                    dlg.ShowDialog();
                }
                catch (Exception e)
                {
                    MessageBoxFactory.ShowError(e);
                }
            }
        }
Exemplo n.º 2
0
        private async void SurpriseMe()
        {
            window.SetIsEnabled(false);

            try
            {
                UpdateStatus("Finding random rant...");

                acceptorTries = 0; //Reset counter
                Dtos.Rant rant = await api.SurpriseMe(acceptRant);

                UpdateStatus("Done, after " + acceptorTries + " tries.");

                var dlg = new RantViewerWindow(new ViewModels.Rant(rant), api);
                dlg.Owner = window;

                dlg.ShowDialog();

                if (db != null)
                {
                    db.MarkRead(rant.Id);
                }
            }
            catch (Exception e)
            {
                //MessageBoxFactory.ShowError(e);
                UpdateStatus("Error: " + e.Message);
            }
            finally
            {
                window.SetIsEnabled(true);
            }
        }
Exemplo n.º 3
0
        /*
         * public string PictureUrl
         * {
         *  get
         *  {
         *      var result = Get<string>();
         *      return result == null ? "" : result;
         *  }
         *  set
         *  {
         *      Set(value);
         *      RaisePropertyChanged();
         *  }
         * }
         */

        internal void Update(Dtos.Rant updated)
        {
            rant = updated;
            RaisePropertyChanged("Text");
            RaisePropertyChanged("Votes");
            RaisePropertyChanged("VotesString");
            RaisePropertyChanged("UserScore");
            RaisePropertyChanged("UserScoreString");
            RaisePropertyChanged("CommentsCount");
            RaisePropertyChanged("Voted");
            RaisePropertyChanged("FavoriteText");
        }
Exemplo n.º 4
0
        private bool acceptRant(Dtos.Rant rant)
        {
            acceptorTries++;

            if (db != null && db.IsRead(rant.Id))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        private async void GetComments()
        {
            Dtos.Rant rant = await api.GetRant(this.Rant.ID);

            if (rant.Comments != null)
            {
                Comments.Clear();

                foreach (var c in rant.Comments)
                {
                    Comments.Add(new Comment(c));
                }
            }
        }
Exemplo n.º 6
0
        public Rant(Dtos.Rant rant) : base(FeedItemType.Post, rant.CreatedTime)
        {
            this.rant = rant;
            DateTime dt = Utilities.FromUnixTime(rant.CreatedTime);

            CreateTime = dt.ToLocalTime().ToString("M/d/yyyy h:mm tt");
            CanAnimate = Visibility.Collapsed;

            if (rant.Image != null)
            {
                Action <ImageSource, Visibility> cb = (img, vis) =>
                {
                    Picture    = img;
                    CanAnimate = vis;
                };

                Thread th = new Thread(() => LoadImage(rant.Image, cb));
                th.Start();
            }
        }
Exemplo n.º 7
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);
            }
        }