Пример #1
0
        public TootForm(ApiClient ac, Types.Status status)
            : this()
        {
            _ac     = ac;
            _status = status;

            // too expensive atm
            // UpdateStatusInPlace();

            SetForUI(_status);

            tabControl1.SelectedIndex = 0;
        }
Пример #2
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");
     }
 }
Пример #3
0
        public ComposeForm(ApiClient ac, Types.Status inReplyTo)
            : this(ac)
        {
            Text = "Compose Reply";

            var actual = inReplyTo.ReblogOrSelf();
            _inReplyTo = inReplyTo;
            Visibility = actual.Visibility;
            // TODO: remove ourselves as a mention
            var actualMentions = actual.Mentions
                                 .Where(x => x.AccountId != actual.Account.AccountId);
            contentBox.Text = string.Join(" ", actualMentions
                                          .Select(x => x.ToString()).ToArray());
            cwBox.Text = actual.ContentWarning;
        }
Пример #4
0
        public static string StatusContentsRenderingEmoji(Types.Status status, int size)
        {
            var content = status.Content;

            if (status.Emoji != null)
            {
                foreach (var emoji in status.Emoji)
                {
                    var tag = string.Format(EMOJI_IMAGE_TEMPLATE,
                                            emoji.StaticUrl,
                                            emoji.Shortcode,
                                            size);
                    var shortcode = string.Format(EMOJI_REGEX_TEMPLATE, emoji.Shortcode);
                    content = Regex.Replace(content, shortcode, tag);
                }
            }
            return(content);
        }
Пример #5
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;
        }