Exemplo n.º 1
0
 public void UpdateStatusInPlace()
 {
     // TODO: do this async
     // try to fetch refreshed status or fall back on given param
     try
     {
         var newStatusJson = _ac.Get(string.Format("/api/v1/statuses/{0}", _status.Id));
         var newStatus     = JsonUtility.MaybeDeserialize <Types.Status>(newStatusJson);
         _status = newStatus;
     }
     catch (Exception e)
     {
         ErrorDispatcher.ShowError(e, "Checking Status");
     }
 }
Exemplo n.º 2
0
        public void SendStatus()
        {
            try
            {
                var res = _ac.SendUrlencoded("/api/v1/statuses", "POST", ToQueryString());

                // we don't actually need it
                JsonUtility.MaybeDeserialize <Types.Status>(res);

                Close();
            }
            catch (Exception e)
            {
                ErrorDispatcher.ShowError(e, "Sending Status");
            }
        }
Exemplo n.º 3
0
 public void UpdateAccountInPlace()
 {
     try
     {
         var accountJson = _ac.Get(FormatRoute());
         _account = JsonUtility.MaybeDeserialize <Types.Account>(accountJson);
         var statusesJson = _ac.Get(FormatRoute("statuses"));
         _statuses = JsonUtility.MaybeDeserialize <List <Types.Status> >(statusesJson);
         var followersJson = _ac.Get(FormatRoute("followers"));
         _followers = JsonUtility.MaybeDeserialize <List <Types.Account> >(followersJson);
         var followingJson = _ac.Get(FormatRoute("following"));
         _following = JsonUtility.MaybeDeserialize <List <Types.Account> >(followingJson);
     }
     catch (Exception e)
     {
         ErrorDispatcher.ShowError(e, "Fetching Account Info");
     }
 }
Exemplo n.º 4
0
        public void RefreshTimeline(string route, bool clear, bool insertAbove)
        {
            // TODO: some smart algorithm where we can splice in new statuses

            statusListView.BeginUpdate();

            try
            {
                var s  = _ac.Get(route);
                var sl = JsonUtility.MaybeDeserialize <List <Types.Status> >(s);

                if (clear)
                {
                    statusListView.Items.Clear();
                }

                var posWhenAbove = 0;
                foreach (var status in sl)
                {
                    if (insertAbove)
                    {
                        statusListView.Items.Insert(posWhenAbove++, status);
                    }
                    else
                    {
                        statusListView.Items.Add(status);
                    }
                }
            }
            catch (Exception e)
            {
                // let dispatch handle it
                ErrorDispatcher.ShowError(e, "Refreshing Timeline");
            }
            finally
            {
                statusListView.EndUpdate();
                ResizeColumn();
            }
        }
Exemplo n.º 5
0
 private void favMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         var toUse = _status.ReblogOrSelf();
         if (toUse.HasFavourited.HasValue && toUse.HasFavourited.Value)
         {
             var s = _ac.SendUrlencoded(FormatStatusRoute("unfavourite"), "POST", null);
             JsonUtility.MaybeDeserialize <Types.Status>(s);
         }
         else
         {
             var s = _ac.SendUrlencoded(FormatStatusRoute("favourite"), "POST", null);
             JsonUtility.MaybeDeserialize <Types.Status>(s);
         }
         favMenuItem.Checked = !boostMenuItem.Checked;
     }
     catch (Exception ex)
     {
         ErrorDispatcher.ShowError(ex, "Favouriting");
     }
 }
Exemplo n.º 6
0
        public void SetForUI(Types.Status status)
        {
            var toUse = status.ReblogOrSelf();

            metaListView.Items.Clear();
            if (status.Reblog != null)
            {
                AddMeta("Boost from", status.Account);
                AddMeta("Boost date", status.CreatedAt);
            }
            if (toUse.ReblogCount > 0)
            {
                AddMeta("Boosts", toUse.ReblogCount);
            }

            AddMeta("From", toUse.Account);
            AddMeta("Date", toUse.CreatedAt);

            AddMeta("Visibility", toUse.Visibility);

            if (toUse.FavouriteCount > 0)
            {
                AddMeta("Favourites", toUse.FavouriteCount);
            }
            if (!string.IsNullOrEmpty(toUse.ContentWarning))
            {
                AddMeta("Spoiler", toUse.ContentWarning);
            }
            if (toUse.Application != null)
            {
                AddMeta("Application", toUse.Application);
            }
            if (toUse.Pinned.HasValue && toUse.Pinned.Value)
            {
                AddMeta("Pinned", "Yes");
            }
            if (!string.IsNullOrEmpty(toUse.Language))
            {
                AddMeta("Language", toUse.Language);
            }

            favMenuItem.Checked   = toUse.HasFavourited.HasValue ? toUse.HasFavourited.Value : false;
            boostMenuItem.Checked = toUse.HasReblogged.HasValue ? toUse.HasReblogged.Value : false;

            foreach (var mention in toUse.Mentions)
            {
                AddMeta("Mentions", mention);
            }
            foreach (var tag in toUse.Tags)
            {
                AddMeta("Hashtag", tag);
            }

            // Attachments
            if (toUse.Attachments.Count > 0)
            {
                attachmentsBox.BeginUpdate();
                attachmentsBox.Items.Clear();
                foreach (var attachment in toUse.Attachments)
                {
                    attachmentsBox.Items.Add(attachment);
                }
                attachmentsBox.EndUpdate();
                attachmentsBox.ItemWidth = -1;
            }
            attachmentsPage.Text = string.Format("Attachments ({0})", toUse.Attachments.Count);

            // Thread
            try
            {
                threadBox.BeginUpdate();

                var contextJson = _ac.Get(FormatStatusRoute("context"));
                var context     = JsonUtility.MaybeDeserialize <Types.Context>(contextJson);

                threadBox.Items.Clear();
                foreach (var s in context.Ancestors.Concat(context.Descendants))
                {
                    threadBox.Items.Add(s);
                }
            }
            catch (Exception e)
            {
                ErrorDispatcher.ShowError(e, "Reconstructing Thread");
            }
            finally
            {
                threadBox.EndUpdate();
                threadBox.ItemWidth = -1;
                threadPage.Text     = string.Format("Thread ({0})", threadBox.Items.Count);
            }

            keyHeader.Width   = -1;
            valueHeader.Width = -1;

            // include emojis and cap their size (otherwise they render full
            // size and we definitely are NOT hidpi
            var content = HtmlUtility.StatusContentsRenderingEmoji(toUse, 16);

            webBrowser1.DocumentText = content;
        }