/// <summary> /// Update the opacities of elements in the ChannelControl /// </summary> private void UpdateOpacity() { if ((IsUnread && !IsMuted && HavePermission) || Type == 4) { // Show the text at 100% because there's an unread message ChannelName.Fade(1, 200).Start(); } else { if (!HavePermission) { // Show at 15% because the user can't enter the channel ChannelName.Fade(0.15f, 200).Start(); HashtagIcon.Fade(0.15f, 200).Start(); VoiceIcon.Fade(0.15f, 200).Start(); } else if (IsMuted) { // Show at 35% because the channel is muted ChannelName.Fade(0.35f, 200).Start(); HashtagIcon.Fade(0.35f, 200).Start(); VoiceIcon.Fade(0.35f, 200).Start(); } else { // Show at 55%, standard opacity ChannelName.Fade(0.55f, 200).Start(); HashtagIcon.Fade(0.55f, 200).Start(); VoiceIcon.Fade(0.55f, 200).Start(); } } }
private async void OnPropertyChanged(DependencyObject d, DependencyProperty prop) { //if (!App.CurrentGuildIsDM && Id != "") //{ // if (!Storage.Cache.Guilds[App.CurrentGuildId].Channels[Id].chnPerms.EffectivePerms.Administrator && !Storage.Cache.Guilds[App.CurrentGuildId].Channels[Id].chnPerms.EffectivePerms.ReadMessages) // { // this.Visibility = Visibility.Collapsed; // } //} if (prop == IsSelectedProperty) { if (Type == 2) { if (IsSelected) { ChannelName.Fade(1, 200).Start(); VoiceIcon.Fade(1, 200).Start(); SelectIndicator.Fade(0.6f, 200).Start(); } else { ChannelName.Fade(0.6f, 200).Start(); VoiceIcon.Fade(0.6f, 200).Start(); SelectIndicator.Fade(0.6f, 200).Start(); } } else { if (IsSelected) { SelectIndicator.Fade(1, 200).Start(); } else { SelectIndicator.Fade(0, 200).Start(); } } UpdateHidden(); } if (prop == UserStatusProperty) { if (UserStatus != "" && UserStatus != null) { Status.Fill = (SolidColorBrush)App.Current.Resources[UserStatus]; } } if (prop == SubtitleProperty) { if (Subtitle != "") { SubTitle.Visibility = Visibility.Visible; SubTitle.Text = Subtitle; } else { SubTitle.Visibility = Visibility.Collapsed; } } if (prop == PlayingProperty) { if (Playing.HasValue) { PlayingBlock.Visibility = Visibility.Visible; switch (Playing.Value.Type) { case 0: PlayingType.Text = App.GetString("/Controls/Playing"); break; case 1: PlayingType.Text = App.GetString("/Controls/Streaming"); break; } PlayingText.Text = Playing.Value.Name; } else { PlayingBlock.Visibility = Visibility.Collapsed; } } if (prop == IsUnreadProperty) { if (IsUnread && !IsMuted) { ChannelName.Fade(1, 200).Start(); UnreadIndicator.Visibility = Visibility.Visible; if (IsHidden) { //await this.Fade(0, 200, 0).StartAsync(); this.Visibility = Visibility.Collapsed; } } else { ChannelName.Fade(0.6f, 200).Start(); UnreadIndicator.Visibility = Visibility.Collapsed; if (IsHidden) { this.Visibility = Visibility.Visible; this.Fade(1, 200, 0).Start(); } } UpdateHidden(); } if (prop == IsMutedProperty) { if (IsMuted) { ChannelName.Opacity = 0.5; MuteIcon.Visibility = Visibility.Visible; ChannelName.Fade(0.75f, 200).Start(); UnreadIndicator.Visibility = Visibility.Collapsed; } else { MuteIcon.Visibility = Visibility.Collapsed; } UpdateHidden(); } if (prop == IsTypingProperty) { if (IsTyping) { TypingIndic.Visibility = Visibility.Visible; TypingIndic.Fade(1, 200).Start(); } else { await TypingIndic.Fade(0, 200).StartAsync(); TypingIndic.Visibility = Visibility.Collapsed; } } if (prop == NotificationCountProperty) { if (NotificationCount > 0) { NotificationCounter.Text = NotificationCount.ToString(); ShowBadge.Begin(); } else { HideBadge.Begin(); } UpdateHidden(); } if (prop == ChnNameProperty) { ChannelName.Text = CName; } if (prop == ImageUrlProperty) { if (ImageUrl != "") { ChannelImageBrush.ImageSource = new BitmapImage(new Uri(ImageUrl)); } } if (prop == TypeProperty) { ChannelName.FontWeight = FontWeights.Normal; ChannelName.Opacity = 0.75; ChannelName.Foreground = (SolidColorBrush)App.Current.Resources["Foreground"]; Chevron.Visibility = Visibility.Collapsed; HoverCache.Visibility = Visibility.Collapsed; this.Margin = new Thickness(0); if (Type == 0) { //TEXT HashtagIcon.Visibility = Visibility.Visible; VoiceIcon.Visibility = Visibility.Collapsed; MemberList.Visibility = Visibility.Collapsed; Tapped -= JoinVoiceChannel; } else if (Type == 2) { //VOICE HashtagIcon.Visibility = Visibility.Collapsed; VoiceIcon.Visibility = Visibility.Visible; VoiceMembers = new Dictionary <string, VoiceMemberContainer>(); GatewayManager.Gateway.VoiceStateUpdated += Gateway_VoiceStateUpdated; foreach (var user in LocalState.VoiceDict.Values) { if (user.ChannelId == Id) { VoiceMembers.Add(user.UserId, new VoiceMemberContainer() { VoiceState = LocalState.VoiceDict[user.UserId] }); } } if (VoiceMembers != null) { foreach (VoiceMemberContainer member in VoiceMembers.Values) { if (LocalState.Guilds[App.CurrentGuildId].members.ContainsKey(member.VoiceState.UserId)) { MemberList.Items.Add(member); } } //Debug MemberList.Items.Add(new VoiceMemberControl.SimpleMember() { Member = Storage.Cache.Guilds[App.CurrentGuildId].Members[Storage.Cache.CurrentUser.Raw.Id] }); } Tapped += JoinVoiceChannel; } else if (Type == 1) { //DM HashtagIcon.Visibility = Visibility.Collapsed; if (LocalState.DMs[Id].Users.FirstOrDefault().Avatar == null) { ChannelImageBackdrop.Visibility = Visibility.Visible; } ChannelImage.Visibility = Visibility.Visible; Status.Visibility = Visibility.Visible; grid.Height = 48; ChannelImage.Margin = new Thickness(0, 6, 6, 6); ChannelImageBackdrop.Fill = Common.DiscriminatorColor(LocalState.DMs[Id].Users.FirstOrDefault().Discriminator); ChannelImageBrush.ImageSource = new BitmapImage(Common.AvatarUri(LocalState.DMs[Id].Users.FirstOrDefault().Avatar, LocalState.DMs[Id].Users.FirstOrDefault().Id, "?size=64")); MemberList.Visibility = Visibility.Collapsed; Tapped -= JoinVoiceChannel; } else if (Type == 3) { //GROUP DM HashtagIcon.Visibility = Visibility.Collapsed; ChannelImageBackdrop.Visibility = Visibility.Visible; ChannelImage.Visibility = Visibility.Visible; Status.Visibility = Visibility.Collapsed; grid.Height = 48; //ChannelImageBrush.ImageSource = new SvgImageSource(new Uri("ms-appx:///Assets/DiscordAssets/groupchat.svg")); if (App.Current.RequestedTheme == ApplicationTheme.Dark) { ChannelImageBrush.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/DiscordAssets/Friends_dark.png")); } else { ChannelImageBrush.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/DiscordAssets/Friends_light.png")); } ChannelImage.Margin = new Thickness(0, 6, 6, 6); MemberList.Visibility = Visibility.Collapsed; Tapped -= JoinVoiceChannel; } else if (Type == 4) { //CHANNEL CATEGORY HashtagIcon.Visibility = Visibility.Collapsed; VoiceIcon.Visibility = Visibility.Collapsed; ChannelImageBackdrop.Visibility = Visibility.Collapsed; ChannelImage.Visibility = Visibility.Collapsed; Status.Visibility = Visibility.Collapsed; ChannelName.FontWeight = FontWeights.Light; ChannelName.Opacity = 1; ChannelName.Foreground = (SolidColorBrush)App.Current.Resources["Blurple"]; Chevron.Visibility = Visibility.Visible; HoverCache.Visibility = Visibility.Visible; this.Margin = new Thickness(0, 18, 0, 0); MemberList.Visibility = Visibility.Collapsed; Tapped -= JoinVoiceChannel; } if (Type != 2) { GatewayManager.Gateway.VoiceStateUpdated -= Gateway_VoiceStateUpdated; } } if (prop == IsHiddenProperty) { UpdateHidden(); } if (prop == NSFWProperty) { if (NSFW) { HashtagIcon.Foreground = ChannelName.Foreground = (SolidColorBrush)App.Current.Resources["dnd"]; } else { HashtagIcon.Foreground = ChannelName.Foreground = (SolidColorBrush)App.Current.Resources["Foreground"]; } } }
private async void LoadInvite(bool ForceJoin) { InviteCode = InviteCode.Replace(">\n", ""); InviteCode = InviteCode.Replace("http://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.gg/", ""); InviteCode = InviteCode.Replace("http://discord.gg/", ""); InviteCode = InviteCode.Replace("https://discordapp.com/invite/", ""); InviteCode = InviteCode.Replace("http://discordapp.com/invite/", ""); GreenIcon.Opacity = 0; RedIcon.Opacity = 0; JoinIcon.Opacity = 0; ChannelName.Opacity = 0; GuildName.Opacity = 0; Loading.Opacity = 1; try { DisplayedInvite = await RESTCalls.GetInvite(InviteCode); Loading.Fade(0, 200).Start(); GuildName.Visibility = Visibility.Visible; TimeSpan timeDiff = TimeSpan.FromSeconds(1); if (DisplayedInvite.CreatedAt != null && DisplayedInvite.MaxAge != 0) { var creationTime = DateTime.Parse(DisplayedInvite.CreatedAt); timeDiff = TimeSpan.FromSeconds(DisplayedInvite.MaxAge - DateTime.Now.Subtract(creationTime).TotalSeconds); } GuildName.Text = DisplayedInvite.Guild.Name; GuildName.Fade(1, 350).Start(); ChannelName.Fade(1, 200).Start(); if (LocalState.Guilds.ContainsKey(DisplayedInvite.Guild.Id) || ForceJoin) { GreenIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteJoined") + " " + DisplayedInvite.Channel.Name; return; } if (DisplayedInvite.MaxUses != 0 && DisplayedInvite.MaxUses <= DisplayedInvite.Uses) { ChannelName.Text = App.GetString("/Controls/InviteMaxUses"); RedIcon.Fade(1, 200).Start(); return; } if (timeDiff.TotalSeconds > 0) { JoinIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteJoin") + " " + DisplayedInvite.Channel.Name; } else { RedIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteExpired"); } } catch { Loading.Fade(0, 200).Start(); GuildName.Fade(1, 350).Start(); ChannelName.Fade(1, 200).Start(); RedIcon.Fade(1, 200).Start(); ChannelName.Text = App.GetString("/Controls/InviteInvalid"); GuildName.Visibility = Visibility.Collapsed; } }
/// <summary> /// /// </summary> /// <param name="Join">False if just rendering the embed</param> private async void LoadInvite(bool Join) { GuildName.Foreground = (SolidColorBrush)Application.Current.Resources["InvertedBG"]; // Trim link prefix InviteCode = InviteCode.Replace(">\n", ""); InviteCode = InviteCode.Replace("http://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.me/", ""); InviteCode = InviteCode.Replace("https://discord.gg/", ""); InviteCode = InviteCode.Replace("http://discord.gg/", ""); InviteCode = InviteCode.Replace("https://discordapp.com/invite/", ""); InviteCode = InviteCode.Replace("http://discordapp.com/invite/", ""); // Show loading GuildName.Opacity = 0; Loading.Opacity = 1; try { // Get invite DisplayedInvite = await RESTCalls.GetInvite(InviteCode); if (DisplayedInvite == null) { InvalidInvite(InvalidReason.Default); return; } // Show invite Loading.Fade(0, 200).Start(); GuildName.Visibility = Visibility.Visible; // Get expiration time TimeSpan timeDiff = TimeSpan.FromSeconds(1); if (DisplayedInvite.CreatedAt != null && DisplayedInvite.MaxAge != 0) { var creationTime = DateTime.Parse(DisplayedInvite.CreatedAt); timeDiff = TimeSpan.FromSeconds(DisplayedInvite.MaxAge - DateTime.Now.Subtract(creationTime).TotalSeconds); } // Return an error if the guild is null if (DisplayedInvite.Guild == null) { InvalidInvite(InvalidReason.Default); return; } // Display the guild image if (DisplayedInvite.Guild?.Icon != null) { GuildImage.Visibility = Visibility.Visible; GuildImageBrush.ImageSource = new BitmapImage(new Uri("https://cdn.discordapp.com/icons/" + DisplayedInvite.Guild.Id + "/" + DisplayedInvite.Guild.Icon + ".png")); } else { GuildImage.Visibility = Visibility.Collapsed; } // Setup channel details (invites are technically to a channel) ChannelName.Text = "#" + DisplayedInvite.Channel.Name; ChannelName.Fade(0.6f, 200).Start(); // Guild details visibility GuildName.Fade(1, 100).Start(); GuildImage.Fade(1, 300).Start(); // Member values MemberCounters.Visibility = Visibility.Visible; MemberCounters.Fade(1, 400).Start(); onlineCounter.Text = DisplayedInvite.OnlineCount + " online"; offlineCounter.Text = DisplayedInvite.MemberCount + " members"; // Return error if the user has already joined if (LocalState.Guilds.ContainsKey(DisplayedInvite.Guild.Id) || Join) { GuildName.Text = App.GetString("/Controls/InviteJoined") + " " + DisplayedInvite.Guild.Name; Status = InviteStatus.AlreadyJoined; return; } // Return error if the invite uses has already been maxed if (DisplayedInvite.MaxUses != 0 && DisplayedInvite.MaxUses <= DisplayedInvite.Uses) { InvalidInvite(InvalidReason.MaxUses); return; } // Return error if the invite has timed out if (timeDiff.TotalSeconds > 0) { GuildName.Text = App.GetString("/Controls/InviteJoin") + " " + DisplayedInvite.Guild.Name; Status = InviteStatus.Canjoin; } else { InvalidInvite(InvalidReason.Default); } } catch { // Something went wrong, return an error InvalidInvite(InvalidReason.Default); } }