Example #1
0
        string ConstructTopic(ChanPost post, string url)
        {
            // Prefer subject as topic, if the post has one and if it isn't too similar to the URL. This is now an
            // issue because 4chan puts the subject into the URL.
            if (!string.IsNullOrEmpty(post.Subject))
            {
                double similarity = WebToIrc.UrlTitle.Similarity(url, post.Subject);
                if (similarity < 0.9d)
                {
                    return(post.Subject);
                }
            }

            // Else reform the message into a topic.
            if (!string.IsNullOrEmpty(post.Comment))
            {
                string topic = ChanTools.RemoveSpoilerTags(post.Comment);
                topic = ChanTools.RemovePostQuotations(topic);
                return(ShortenPost(topic));
            }

            return(null);
        }
Example #2
0
        private void ThreadPanel_MouseUp(object sender, RoutedEventArgs e)
        {
            if (((FrameworkElement)sender).DataContext != null)
            {
                ChanPost chanPost = ((ChanPost)((FrameworkElement)sender).DataContext);

                StackPanel stackPanel = new StackPanel();
                stackPanel.Orientation = Orientation.Vertical;
                stackPanel.Margin      = new Thickness(2);
                stackPanel.Background  = Brushes.DarkGreen;

                Button threadButton = new Button();
                threadButton.MinWidth    = 100;
                threadButton.Margin      = new Thickness(2);
                threadButton.Content     = chanPost.no.ToString() + "\n" + chanPost.semantic_url;
                threadButton.DataContext = ((FrameworkElement)sender).DataContext;
                threadButton.Click      += ThreadButton_Click;
                stackPanel.Children.Add(threadButton);

                CheckBox checkBox = new CheckBox();
                checkBox.Content   = "Auto-Refresh";
                checkBox.IsChecked = false;
                checkBox.Margin    = new Thickness(2);
                stackPanel.Children.Add(checkBox);

                Button removeThreadButton = new Button();
                removeThreadButton.Content = "Remove";
                removeThreadButton.Margin  = new Thickness(2);
                removeThreadButton.Click  += (cs, ce) => { ThreadList.Children.Remove(stackPanel); };
                stackPanel.Children.Add(removeThreadButton);

                ThreadList.Children.Add(stackPanel);

                ThreadButton_Click(threadButton, null);
            }
        }
Example #3
0
        private async void ThreadButton_Click(object sender, RoutedEventArgs e)
        {
            ChanPost op = ((ChanPost)((FrameworkElement)sender).DataContext);

            ThreadStackPanel.Children.Clear();
            ((ScrollViewer)ThreadStackPanel.Parent).ScrollToTop();

            Task loadThread = Global.loadThread(op, tokenSource.Token);
            await loadThread.ContinueWith(t =>
            {
                switch (t.Status)
                {
                case TaskStatus.RanToCompletion:
                    foreach (ChanPost reply in op.replyList)
                    {
                        StackPanel postStackPanel          = new StackPanel();
                        postStackPanel.Orientation         = Orientation.Horizontal;
                        postStackPanel.HorizontalAlignment = HorizontalAlignment.Left;
                        postStackPanel.Margin     = new Thickness(2);
                        postStackPanel.Background = Brushes.MidnightBlue;

                        Image image = new Image();

                        if (reply.ext != "")
                        {
                            image.Source            = new BitmapImage(new Uri(reply.imageUrl));
                            image.Stretch           = Stretch.None;
                            image.VerticalAlignment = VerticalAlignment.Top;
                            image.Margin            = new Thickness(2);
                            postStackPanel.Children.Add(image);

                            ToolTip imageToolTip         = new ToolTip();
                            StackPanel toolTipStackPanel = new StackPanel();
                            TextBlock toolTipTextBlock   = new TextBlock();
                            Image toolTipImage           = new Image();

                            imageToolTip.Background = Brushes.Black;
                            imageToolTip.Loaded    += (ls, le) =>
                            {
                                toolTipImage.Source    = new BitmapImage(new Uri((string)toolTipImage.DataContext));
                                toolTipImage.MaxHeight = SystemParameters.PrimaryScreenHeight;
                                toolTipImage.MaxWidth  = SystemParameters.PrimaryScreenHeight;
                            };

                            toolTipStackPanel.Orientation = Orientation.Vertical;

                            toolTipTextBlock.Text = reply.w + "x" + reply.h + " - " + reply.filename + reply.ext;
                            toolTipStackPanel.Children.Add(toolTipTextBlock);

                            toolTipImage.DataContext = Global.BASE_IMAGE_URL + reply.board + "/" + reply.tim + reply.ext;
                            toolTipStackPanel.Children.Add(toolTipImage);

                            imageToolTip.Content = toolTipStackPanel;
                            ToolTipService.SetShowDuration(image, int.MaxValue);
                            //ToolTipService.SetInitialShowDelay(image, 0);
                            ToolTipService.SetPlacement(image, System.Windows.Controls.Primitives.PlacementMode.Absolute);

                            ToolTipService.SetToolTip(image, imageToolTip);
                        }

                        StackPanel textStackPanel        = new StackPanel();
                        textStackPanel.Orientation       = Orientation.Vertical;
                        textStackPanel.VerticalAlignment = VerticalAlignment.Top;

                        {
                            TextBlock textBlock = new TextBlock();
                            Global.htmlToTextBlockText(textBlock,
                                                       (reply.no != 0 ? reply.no + " - " : "") +
                                                       (reply.name != "" ? reply.name : "Anonymous") + " @ " +
                                                       (reply.now != "" ? reply.now : "UNKNOWN TIME"));
                            textBlock.Foreground   = Brushes.White;
                            textBlock.TextWrapping = TextWrapping.Wrap;
                            textBlock.Loaded      += (ls, le) =>
                            {
                                textBlock.Width = ThreadStackPanel.ActualWidth - image.ActualWidth;
                            };
                            textStackPanel.Children.Add(textBlock);
                        }

                        {
                            TextBlock textBlock = new TextBlock();
                            Global.htmlToTextBlockText(textBlock, "<strong>" + reply.sub + "</strong>");
                            textBlock.Foreground   = Brushes.White;
                            textBlock.TextWrapping = TextWrapping.Wrap;
                            textBlock.Loaded      += (ls, le) =>
                            {
                                textBlock.Width = ThreadStackPanel.ActualWidth - image.ActualWidth - SystemParameters.VerticalScrollBarWidth;
                            };
                            textStackPanel.Children.Add(textBlock);
                        }

                        {
                            TextBlock textBlock = new TextBlock();
                            Global.htmlToTextBlockText(textBlock, reply.com);
                            textBlock.Foreground   = Brushes.White;
                            textBlock.TextWrapping = TextWrapping.Wrap;
                            textBlock.Loaded      += (ls, le) =>
                            {
                                textBlock.Width = ThreadStackPanel.ActualWidth - image.ActualWidth - SystemParameters.VerticalScrollBarWidth;
                            };
                            textStackPanel.Children.Add(textBlock);
                        }

                        postStackPanel.Children.Add(textStackPanel);

                        ThreadStackPanel.Children.Add(postStackPanel);
                    }

                    break;

                case TaskStatus.Canceled:
                    MessageBox.Show("loadThread was canceled!", "CANCELED");
                    break;

                case TaskStatus.Faulted:
                    MessageBox.Show("loadThread was faulted!", "EXCEPTION");
                    break;

                default:
                    break;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }