/// <summary> /// Initializes a new instance of the <see cref="ChannelNavigateMessage"/> class. /// </summary> /// <param name="channel">The channel to navigate to.</param> /// <param name="guild">The guild to navigate to.</param> public ChannelNavigateMessage(BindableChannel channel) { Channel = channel; }
/// <summary> /// Initializes a new instance of the <see cref="ChannelSuggestion"/> class. /// </summary> /// <param name="channel">The channel recommended for mentioning.</param> public ChannelSuggestion(BindableChannel channel) { Channel = channel; }
/// <summary> /// Adds a child to the <see cref="BindableChannelGroup"/>. /// </summary> /// <param name="child">The <see cref="BindableChannel"/> to add.</param> public void AddChild(BindableChannel child) { Children.Add(child); }
/// <summary> /// Renders a raw link element. /// </summary> /// <param name="inlineCollection"> The list to add to. </param> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> private void RenderHyperlink(InlineCollection inlineCollection, HyperlinkInline element, RenderContext context) { var link = new HyperlinkButton(); if (element.LinkType == HyperlinkType.DiscordUserMention || element.LinkType == HyperlinkType.DiscordChannelMention || element.LinkType == HyperlinkType.DiscordRoleMention || element.LinkType == HyperlinkType.DiscordNickMention || element.LinkType == HyperlinkType.QuarrelColor) { var content = element.Text; bool enabled = true; SolidColorBrush foreground = (SolidColorBrush)SimpleIoc.Default.GetInstance <IResourceService>().GetResource("Blurple"); try { if (element.LinkType == HyperlinkType.DiscordUserMention || element.LinkType == HyperlinkType.DiscordNickMention) { string mentionid = element.Text.Remove(0, element.LinkType == HyperlinkType.DiscordNickMention ? 2 : 1); if (_users != null) { foreach (var user in _users) { if (user.Id == mentionid) { link.Tag = user; if (_halfopacity) { content = user.Username; } else { content = "@" + user.Username; } if (_guildsService.CurrentGuild.Model.Name != "DM") { var member = _guildsService.GetGuildMember(mentionid, _guildsService.CurrentGuild.Model.Id); if (!string.IsNullOrWhiteSpace(member?.DisplayName)) { if (_halfopacity) { content = member.DisplayName; } else { content = "@" + member.DisplayName; } foreground = ColorExtensions.IntToBrush(member.TopRole.Color); } } break; } } } } else if (element.LinkType == HyperlinkType.DiscordChannelMention) { var key = element.Text.Remove(0, 1); BindableChannel value = _channelsService.GetChannel(key); content = "#" + (value?.Model?.Name ?? "deleted-channel"); enabled = value != null; link.Tag = value; } else if (element.LinkType == HyperlinkType.DiscordRoleMention) { var role = _guildsService.CurrentGuild.Model.Roles.FirstOrDefault(x => x.Id == element.Text.Remove(0, 2)); if (role != null) { if (_halfopacity) { content = role.Name; } else { content = "@" + role.Name; } foreground = ColorExtensions.IntToBrush(role.Color); } else { enabled = false; content = "@deleted-role"; } } else if (element.LinkType == HyperlinkType.QuarrelColor) { string intcolor = element.Text.Replace("@$QUARREL-color", string.Empty); try { var color = ColorExtensions.IntToBrush(int.Parse(intcolor)); inlineCollection.Add(new InlineUIContainer { Child = new Ellipse() { Height = FontSize, Width = FontSize, Fill = color, Margin = new Thickness(0, 0, 2, -2), }, }); inlineCollection.Add(new Run { FontWeight = FontWeights.SemiBold, Foreground = BoldForeground, Text = color.Color.ToString(), }); return; } catch { } } } catch (Exception) { content = "<Invalid Mention>"; } link.Content = CollapseWhitespace(context, content); link.Foreground = foreground; link.FontSize = FontSize; if (_halfopacity) { link.Style = (Style)Application.Current.Resources["DiscordMentionHyperlinkBold"]; } else { link.Style = (Style)Application.Current.Resources["DiscordMentionHyperlink"]; } link.IsEnabled = enabled; _linkRegister.RegisterNewHyperLink(link, element.Url); InlineUIContainer linkContainer = new InlineUIContainer { Child = link }; inlineCollection.Add(linkContainer); } else { var hLink = new Hyperlink(); _linkRegister.RegisterNewHyperLink(hLink, element.Url); Run linkText = new Run { Text = CollapseWhitespace(context, element.Text), Foreground = LinkForeground ?? context.Foreground, }; hLink.Inlines.Add(linkText); // Add it to the current inlines inlineCollection.Add(hLink); } }