private void quote_Click(object sender, RoutedEventArgs e) { Grid senderElement = (Grid)sender; Toot boundData = (Toot)senderElement.DataContext; boundData.quote_Click(sender, e); }
private void FavoriteLabel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Control senderElement = (Control)sender; Toot boundData = (Toot)senderElement.DataContext; boundData.favoritesClick(sender, e); }
private void Image4_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Image rawControl = (Image)sender; Toot boundData = (Toot)rawControl.DataContext; boundData.mediaClick4(); }
private void favoriteBtn_Click(object sender, RoutedEventArgs e) { Control senderElement = (Control)sender; Toot boundData = (Toot)senderElement.DataContext; boundData.favoriteBtn_Click(sender, e); }
protected static Inline PlainTextTransform(string text, Toot context) { // return new Run(text); var li = new Span(); int i = 0; Match match; bool mathjaxed = false; try { while ((match = latex_begin_pat.Match(text, i)).Success) { mathjaxed = true; int plain_len = match.Index - i; li.Inlines.Add(new Run(text.Substring(i, plain_len))); i = match.Index + match.Length; if (match.Value == "$") { var j = text.IndexOf("$", i); var formula = text.Substring(i, j - i); i = j + 1; li.Inlines.Add(FormulaToInline(formula)); } else if (match.Value == "$$") { var j = text.IndexOf("$$", i); var formula = text.Substring(i, j - i); i = j + 2; li.Inlines.Add(FormulaToInline(formula)); } else { var envname = match.Groups[1]; var endtag = @"\end{" + envname + "}"; var j = text.IndexOf(endtag, i); var formula = text.Substring(i, j - i); i = j + endtag.Length; li.Inlines.Add(FormulaToInline(formula)); } } li.Inlines.Add(new Run(text.Substring(i))); } catch { var x = new Run(text); x.Foreground = Brushes.Orange; x.ToolTip = "Math parse error"; return(x); } if (mathjaxed == false) { return(new Run(text)); } else { context.Style = EnumToottype.mathjaxed; context.Changed("Style"); return(li); } }
private void ClientLabel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Control senderElement = (Control)sender; Toot boundData = (Toot)senderElement.DataContext; if (boundData.clientLink.StartsWith("http://") || boundData.clientLink.StartsWith("https://")) { Process.Start(boundData.clientLink); } }
protected static Inline InlineRecursive(IElement el, Toot context) { var res = new Span(); foreach (var node in el.ChildNodes) { if (node.NodeType == NodeType.Text) { res.Inlines.Add(PlainTextTransform(node.TextContent, context)); } else if (node.NodeType == NodeType.Element) { var t = (IElement)node; var tag = t.TagName.ToLower(); switch (tag) { case "a": var link = new Hyperlink(InlineRecursive(t, context)); var href = t.GetAttribute("href"); if (href.Contains("/media/")) // image { link.IsEnabled = true; link.NavigateUri = new System.Uri(href); link.RequestNavigate += HyperLinkClick; res.Inlines.Add(Image(href)); } else { link.IsEnabled = true; link.NavigateUri = new System.Uri(href); link.RequestNavigate += HyperLinkClick; res.Inlines.Add(link); } break; case "br": res.Inlines.Add(new LineBreak()); break; case "span": res.Inlines.Add(new Span(InlineRecursive(t, context))); break; default: var x = new Run(t.OuterHtml); x.Foreground = Brushes.Red; x.ToolTip = "Unknown Tag"; res.Inlines.Add(x); break; } } } return(res); }
private void nameHandleLabel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { TextBlock nameHandleLabel = (TextBlock)sender; Toot toot = (Toot)nameHandleLabel.DataContext; ProfilePanel panel = new ProfilePanel(); panel.twitterAccountToken = twitterAccountToken; panel.profileUserID = toot.userID; panel.refreshProfile(); navController.pushControl(panel); }
private void spoilerBtn_Click(object sender, RoutedEventArgs e) { Button senderElement = (Button)sender; Toot boundData = (Toot)senderElement.DataContext; StackPanel spoilerControls = (StackPanel)senderElement.Parent; StackPanel tootContents = (StackPanel)spoilerControls.Parent; CSTextBlock textBlock = (CSTextBlock)tootContents.Children[1]; textBlock.Visibility = textBlock.Visibility == Visibility.Visible ? Visibility.Hidden : Visibility.Visible; senderElement.Content = (string)senderElement.Content == "Show" ? "Hide" : "Show"; }
private bool checkEntityOutOfBounds(int firstidx, String tagName, Toot toot) { if (firstidx == -1) { return(false); //Just give up already } if (firstidx + tagName.Length + 1 == toot.rawText.Length) { return(false); } char separatorChar = toot.rawText[firstidx + tagName.Length + 1]; return(Char.IsLetterOrDigit(separatorChar)); }
public bool Add(Toot toot) { using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); return(connection.Execute("INSERT Toots (Name,Text,CreateAt) VALUES(@name,@text,@createAt)", new { name = toot.Name, text = toot.Text, createAt = toot.CreateAt, }) == 1); } }
private void moreBtn_Click(object sender, RoutedEventArgs e) { Account twitterAccount = MastodonAPIWrapper.sharedApiWrapper.accountWithToken(twitterAccountToken); Control senderElement = (Control)sender; Toot boundData = (Toot)senderElement.DataContext; ContextMenu moreMenu = new ContextMenu(); MenuItem detailsItem = new MenuItem(); detailsItem.Header = "Post Details"; detailsItem.Click += new RoutedEventHandler(boundData.details_Click); moreMenu.Items.Add(detailsItem); moreMenu.Items.Add(new Separator()); if (boundData.userID == twitterAccount.accountID) { MenuItem deleteItem = new MenuItem(); deleteItem.Header = "Delete Post"; deleteItem.Click += new RoutedEventHandler(boundData.delete_Click); moreMenu.Items.Add(deleteItem); } else { MenuItem blockItem = new MenuItem(); blockItem.Header = "Block " + boundData.user_display_screen_name; blockItem.Click += new RoutedEventHandler(boundData.block_Click); moreMenu.Items.Add(blockItem); } moreMenu.Items.Add(new Separator()); MenuItem copyItem = new MenuItem(); copyItem.Header = "Copy Post"; copyItem.Click += new RoutedEventHandler(boundData.copy_Click); moreMenu.Items.Add(copyItem); MenuItem copyLinkItem = new MenuItem(); copyLinkItem.Header = "Copy Link to Post"; copyLinkItem.Click += new RoutedEventHandler(boundData.copyLink_Click); moreMenu.Items.Add(copyLinkItem); moreMenu.Margin = new Thickness(0); moreMenu.PlacementTarget = (UIElement)sender; moreMenu.IsOpen = true; }
protected void TootButton_Click(object sender, EventArgs e) { var toot = new Toot { Name = Page.User.Identity.Name, Text = TootText.Text, CreateAt = DateTime.Now }; if (string.IsNullOrEmpty(toot.Text)) { return; } _toots.Add(toot); TootText.Text = null; // post-redirect-get ! Response.Redirect(Page.AppRelativeVirtualPath); }
public static FlowDocument Process(string value, Toot context) { var res = new FlowDocument(); var parser = new HtmlParser(); var doc = parser.Parse(value).Body; foreach (var t in doc.Children) { if (t.TagName.ToLower() == "p") { res.Blocks.Add(new Paragraph(InlineRecursive(t, context))); } else { var x = new Run(t.OuterHtml); x.Foreground = Brushes.DarkRed; x.ToolTip = "Unknown Tag(Block Level)"; res.Blocks.Add(new Paragraph(x)); } } return(res); }
public void Add(Toot toot) { var local = new TootLocal(); local.Add(toot); }
private Toot renderToot(dynamic rawToot, int index, bool quoted) { Account twitterAccount = MastodonAPIWrapper.sharedApiWrapper.accountWithToken(twitterAccountToken); Toot toot = new Toot(); toot.twitterAccountToken = twitterAccountToken; dynamic rawOrigToot = rawToot; dynamic rawUser = rawToot["account"]; if (rawToot["reblog"] != null) { toot.isRetootedStatus = true; toot.origuser_name = rawUser["display_name"]; toot.origuser_screen_name = rawUser["acct"]; rawOrigToot = rawToot["reblog"]; rawUser = rawOrigToot["account"]; } if ("" + rawOrigToot["id"] == conversationStartToot && quoted == false) { toot.isStartToot = true; } toot.userID = "" + rawUser["id"]; toot.tootID = (String)rawOrigToot["id"]; toot.user_screen_name = (String)rawUser["acct"]; toot.tootURL = (String)rawOrigToot["url"]; //toot.clientString = (String)rawOrigToot["source"]; if (rawOrigToot["application"] != null && rawOrigToot["application"].Type != JTokenType.Null) { toot.clientString = rawOrigToot["application"]["name"]; if (toot.clientString == "website" || rawOrigToot["application"]["website"] == null || rawOrigToot["application"]["website"].Type != JTokenType.String) { toot.clientLink = "https://" + twitterAccount.endpoint; } else { toot.clientLink = rawOrigToot["application"]["website"]; } } else { toot.clientString = "web"; toot.clientLink = "https://" + twitterAccount.endpoint; } if (twitterAccount.accountID.Equals(toot.userID)) { twitterAccount.myHandle = toot.user_screen_name; } toot.user_name = (String)rawUser["display_name"]; try { toot.user_profilepicurl = new Uri((String)rawUser["avatar"], UriKind.Absolute); } catch (Exception e) { //no profile pic ;-; } toot.rawText = (String)rawOrigToot["content"]; toot.rawText = toot.rawText.Replace("<br>", "\n"); toot.rawText = toot.rawText.Replace("<br/>", "\n"); toot.rawText = toot.rawText.Replace("<br />", "\n"); toot.rawText = toot.rawText.Replace("</p><p>", "\n\n"); toot.rawText = Regex.Replace(toot.rawText, "<.*?>", String.Empty); toot.rawText = HttpUtility.HtmlDecode(toot.rawText); foreach (String keyword in MastodonAPIWrapper.sharedApiWrapper.keywords) { if (toot.rawText.ToLower().Contains(keyword.ToLower())) { return(toot); } } //toot.rawEntities = rawOrigToot["entities"]; //toot.rawExtendedEntities = rawOrigToot["extended_entities"]; toot.isRetooted = false; toot.isFavorited = false; toot.numRetoots = 0; toot.numFavorites = 0; if (rawOrigToot["reblogged"] != null && rawOrigToot["reblogged"].Type == JTokenType.Boolean) { toot.isRetooted = (bool)rawOrigToot["reblogged"]; } if (rawOrigToot["favourited"] != null && rawOrigToot["favourited"].Type == JTokenType.Boolean) { toot.isFavorited = (bool)rawOrigToot["favourited"]; } if (rawOrigToot["reblogs_count"] != null && rawOrigToot["reblogs_count"].Type == JTokenType.Integer) { toot.numRetoots = (int)rawOrigToot["reblogs_count"]; } if (rawOrigToot["favourites_count"] != null && rawOrigToot["favourites_count"].Type == JTokenType.Integer) { toot.numFavorites = (int)rawOrigToot["favourites_count"]; } if (rawOrigToot["spoiler_text"] != null && rawOrigToot["spoiler_text"].Type == JTokenType.String) { toot.rawSpoilerText = (String)rawOrigToot["spoiler_text"]; } try { const string format = "MM/dd/yyyy HH:mm:ss"; DateTime date = DateTime.ParseExact((String)rawOrigToot["created_at"], format, CultureInfo.InvariantCulture); toot.timeTooted = date.ToLocalTime(); } catch (Exception e) { Console.WriteLine(e.StackTrace); toot.timeTooted = DateTime.Now; } if (rawOrigToot["quoted_status_id_str"] != null && rawOrigToot["quoted_status"] != null) { toot.quotedToot = renderToot(rawOrigToot["quoted_status"], 0, true); toot.hasQuotedToot = true; } if (rawOrigToot["place"] != null) { toot.rawLocation = (String)rawOrigToot["place"]["full_name"]; toot.hasLocation = true; } JObject rawEntities = new JObject(); JObject extendedEntities = new JObject(); JArray userMentions = new JArray(); foreach (dynamic user in rawOrigToot["mentions"].Children()) { JObject mention = new JObject(); mention.Add("id", user["id"]); mention.Add("acct", user["acct"]); JArray indices = new JArray(); String acct = user["acct"]; if (acct.LastIndexOf("@") != -1) { acct = acct.Substring(0, acct.LastIndexOf("@")); } int firstidx = toot.rawText.IndexOf("@" + acct); foreach (JObject refMention in userMentions) { JArray indeces = (JArray)refMention["indices"]; int index0 = (int)indeces[0]; if (firstidx == index0) { firstidx = toot.rawText.IndexOf("@" + acct, firstidx + 1); } } if (firstidx == -1) { continue; } indices.Add(firstidx); indices.Add(firstidx + acct.Length + 1); mention.Add("indices", indices); userMentions.Add(mention); } rawEntities.Add("user_mentions", userMentions); JArray media = new JArray(); foreach (JToken rawMedia in rawOrigToot["media_attachments"].Children()) { if (((String)rawMedia["type"]).Equals("image")) { JObject image = new JObject(); image.Add("id", rawMedia["id"]); image.Add("preview_url", rawMedia["preview_url"]); image.Add("url", rawMedia["url"]); JArray indices = new JArray(); String mediaDisplay = (String)rawMedia["text_url"]; if (mediaDisplay == null || mediaDisplay.Length == 0) { mediaDisplay = ""; } int firstidx = toot.rawText.IndexOf(mediaDisplay); if (firstidx == -1) { mediaDisplay = ""; firstidx = toot.rawText.Length; indices.Add(firstidx); indices.Add(firstidx); } else { indices.Add(firstidx); indices.Add(firstidx + mediaDisplay.Length); } image.Add("display_url", mediaDisplay); image.Add("indices", indices); media.Add(image); } } rawEntities.Add("media", media); extendedEntities.Add("media", media); JArray hashtags = new JArray(); foreach (dynamic tag in rawOrigToot["tags"].Children()) { JObject hashtag = new JObject(); hashtag.Add("name", tag["name"]); JArray indices = new JArray(); String tagName = tag["name"]; int firstidx = toot.rawText.IndexOf("#" + tagName); while (checkEntityOutOfBounds(firstidx, tagName, toot)) { firstidx = toot.rawText.IndexOf("#" + tagName, firstidx + 1); } foreach (JObject refHashtag in hashtags) { JArray indeces = (JArray)refHashtag["indices"]; int index0 = (int)indeces[0]; if (firstidx == index0) { firstidx = toot.rawText.IndexOf("#" + tagName, firstidx + 1); } } if (firstidx == -1) { continue; } indices.Add(firstidx); indices.Add(firstidx + tagName.Length + 1); hashtag.Add("indices", indices); hashtags.Add(hashtag); } rawEntities.Add("hashtags", hashtags); JArray urls = new JArray(); String rawHtml = rawOrigToot["content"]; HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(rawHtml); HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//a[@href and (@rel=\"nofollow noopener\" or @target=\"_blank\")]"); if (collection != null) { foreach (HtmlNode link in collection) { string hrefValue = link.GetAttributeValue("href", string.Empty); String rawHTML = link.OuterHtml; if (hrefValue.StartsWith("https://") || hrefValue.StartsWith("http://")) { String rawUrl = hrefValue; String displayURL = rawUrl; displayURL = displayURL.Replace("https://", ""); displayURL = displayURL.Replace("http://", ""); JObject url = new JObject(); url.Add("url", rawUrl); url.Add("display_url", rawUrl); url.Add("expanded_url", rawUrl); JArray indices = new JArray(); String displayText = hrefValue; int idx = toot.rawText.IndexOf(displayText); if (idx == -1) { continue; } bool addItem = true; foreach (JObject image in media) { if ((int)image["indices"][0] == idx) { addItem = false; break; } } if (addItem) { indices.Add(idx); indices.Add(idx + displayText.Length); url.Add("indices", indices); urls.Add(url); } } } } rawEntities.Add("urls", urls); toot.rawEntities = rawEntities; toot.rawExtendedEntities = extendedEntities; toot.orderEntities(); toot.parseExtendedEntities(); toot.displayNavController = navController; if (!quoted) { if (index < 0) { timeline.Add(toot); } else { timeline.Insert(index, toot); } } return(toot); }
private void timelineBoxItem_Click(object sender, MouseButtonEventArgs e) { Grid listItemGrid = (Grid)sender; Toot rawToot = (Toot)listItemGrid.DataContext; if (e.ClickCount == 2) { rawToot.details_Click(sender, e); return; } Grid listItemItems = (Grid)listItemGrid.Children[0]; StackPanel tootContentsContainer = (StackPanel)listItemItems.Children[4]; StackPanel tootContents = (StackPanel)tootContentsContainer.Children[0]; Border tootPadding = (Border)tootContentsContainer.Children[2]; Border toolbarBorder = (Border)listItemItems.Children[5]; Thickness margin = toolbarBorder.Margin; Thickness padding = tootPadding.Padding; ThicknessAnimation paddingAnimation = new ThicknessAnimation(); paddingAnimation.From = padding; ThicknessAnimation marginAnimation = new ThicknessAnimation(); marginAnimation.From = margin; if (MastodonAPIWrapper.sharedApiWrapper.nightModeEnabled && !rawToot.isStartToot) { toolbarBorder.Background = new SolidColorBrush(Color.FromArgb(255, 61, 61, 61)); } else { toolbarBorder.Background = new SolidColorBrush(Color.FromArgb(255, 194, 194, 194)); } if (padding.Bottom == 0) { padding.Bottom = 35; margin.Bottom = 0; toolbarBorder.Visibility = Visibility.Visible; } else if (padding.Bottom == 35) { padding.Bottom = 0; margin.Bottom = -35; marginAnimation.Completed += (sender2, e2) => { toolbarBorder.Visibility = Visibility.Collapsed; }; } else { return; } paddingAnimation.To = padding; marginAnimation.To = margin; Storyboard.SetTarget(paddingAnimation, tootPadding); Storyboard.SetTargetProperty(paddingAnimation, new PropertyPath(Border.PaddingProperty)); Storyboard.SetTarget(marginAnimation, toolbarBorder); Storyboard.SetTargetProperty(marginAnimation, new PropertyPath(Border.MarginProperty)); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(paddingAnimation); storyboard.Children.Add(marginAnimation); storyboard.SpeedRatio *= 3.5; storyboard.Begin(); }