Пример #1
0
        /// <summary>
        /// Create SimpleFriend from API Friend data
        /// </summary>
        /// <param name="f">API Friend data</param>
        /// <returns>SimpleFriend</returns>
        private async Task <SimpleFriend> NewSF(Friend f)
        {
            // Blank tample
            var friend = new SimpleFriend();

            // Set basic user details
            friend.User = f.user;
            friend.RelationshipStatus = f.Type;

            // Add Shared Guilds to List: "SharedGuilds"
            friend.SharedGuilds = new List <SimpleFriend.SharedGuild>();
            //TODO: real fix instead of work around.
            if (f.Type != 2)
            {
                UserProfile profile = await RESTCalls.GetUserProfile(friend.User.Id);

                if (profile.MutualGuilds != null)
                {
                    foreach (MutualGuild guild in profile.MutualGuilds)
                    {
                        friend.SharedGuilds.Add(new SimpleFriend.SharedGuild()
                        {
                            Id       = guild.Id,
                            ImageUrl = LocalState.Guilds[guild.Id].Raw.Icon,
                            Name     = LocalState.Guilds[guild.Id].Raw.Name
                        });
                    }
                }
            }

            // Set Presence
            if (LocalState.PresenceDict.ContainsKey(f.user.Id))
            {
                friend.UserStatus = LocalState.PresenceDict[f.user.Id].Status;
            }
            else
            {
                friend.UserStatus = "offline";
            }

            // Return value
            return(friend);
        }
Пример #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            ConnectedAnimation imageAnimation =
                ConnectedAnimationService.GetForCurrentView().GetAnimation("avatar");

            if (App.navImageCache != null)
            {
                AvatarFull.ImageSource = App.navImageCache;
                App.navImageCache      = null;
                navFromFlyout          = true;
            }



            if (imageAnimation != null)
            {
                imageAnimation.TryStart(FullAvatar);
            }

            //Windows.UI.Color? color = (await App.getUserColor((e.Parameter as User)));

            //UserAccent = new SolidColorBrush(color.HasValue ? color.Value : (Windows.UI.Color)App.Current.Resources["BlurpleColor"]);

            bool loadviaRest = true;

            if (e.Parameter is User)
            {
                profile      = new SharedModels.UserProfile();
                profile.user = (User)e.Parameter;
                if (profile.user.Bot)
                {
                    grid.VerticalAlignment = VerticalAlignment.Center;
                }

                userid = profile.user.Id;
            }
            else if (e.Parameter is string)
            {
                userid  = (e.Parameter as string);
                profile = await RESTCalls.GetUserProfile(e.Parameter as string);

                loadviaRest = false;
            }
            else
            {
                CloseButton_Click(null, null);
                return;
            }
            if (LocalState.Friends.ContainsKey(profile.user.Id))
            {
                profile.Friend = LocalState.Friends[profile.user.Id];
            }
            else
            {
                profile.Friend = null;
            }

            if (LocalState.PresenceDict.ContainsKey(userid))
            {
                if (LocalState.PresenceDict[userid].Status != null && LocalState.PresenceDict[userid].Status != "invisible")
                {
                    rectangle.Fill = (SolidColorBrush)App.Current.Resources[LocalState.PresenceDict[userid].Status];
                }
                else if (LocalState.PresenceDict[userid].Status == "invisible")
                {
                    rectangle.Fill = (SolidColorBrush)App.Current.Resources["offline"];
                }
            }
            else
            {
                rectangle.Fill = (SolidColorBrush)App.Current.Resources["offline"];
            }

            if (userid == LocalState.CurrentUser.Id)
            {
                AccountSettings.Visibility = Visibility.Visible;
            }
            else
            {
                AccountSettings.Visibility = Visibility.Collapsed;
            }


            if (LocalState.PresenceDict.ContainsKey(profile.user.Id))
            {
                if (LocalState.PresenceDict[profile.user.Id].Game != null)
                {
                    richPresence.GameContent = LocalState.PresenceDict[profile.user.Id].Game;
                }
                else
                {
                    richPresence.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                richPresence.Visibility = Visibility.Collapsed;
            }
            UpdateBorderColor();

            username.Text = profile.user.Username;
            username.Fade(1, 400);
            discriminator.Text = "#" + profile.user.Discriminator;
            discriminator.Fade(0.4f, 800);

            if (profile.Friend != null)
            {
                SwitchFriendValues(profile.Friend.Type);
            }
            else if (profile.user.Id == LocalState.CurrentUser.Id)
            {
            }
            else if (profile.user.Bot)
            {
                SendMessageLink.Visibility = Visibility.Visible;
                Block.Visibility           = Visibility.Visible;
                loadviaRest             = false;
                BotIndicator.Visibility = Visibility.Visible;
            }
            else
            {
                sendFriendRequest.Visibility = Visibility.Visible;
                SendMessageLink.Visibility   = Visibility.Visible;
                Block.Visibility             = Visibility.Visible;
                BotIndicator.Visibility      = Visibility.Collapsed;
            }


            if (LocalState.Notes.ContainsKey(profile.user.Id))
            {
                NoteBox.Text = LocalState.Notes[profile.user.Id];
            }

            GatewayManager.Gateway.UserNoteUpdated     += Gateway_UserNoteUpdated;
            GatewayManager.Gateway.PresenceUpdated     += Gateway_PresenceUpdated;
            GatewayManager.Gateway.RelationShipAdded   += Gateway_RelationshipAdded;
            GatewayManager.Gateway.RelationShipUpdated += Gateway_RelationshipUpdated;
            GatewayManager.Gateway.RelationShipRemoved += Gateway_RelationshipRemoved;

            //  BackgroundGrid.Blur(8, 0).Start();
            base.OnNavigatedTo(e);



            switch (profile.user.Flags)
            {
            case 1:
            {
                var img = new Image()
                {
                    MaxHeight = 28,
                    Source    = new BitmapImage(new Uri("ms-appx:///Assets/DiscordBadges/staff.png")),
                    Opacity   = 0
                };
                ToolTipService.SetToolTip(img, App.GetString("/Dialogs/FlagDiscordStaff").ToUpper());
                BadgePanel.Children.Add(img);
                img.Fade(1).Start();
                break;
            }

            case 2:
            {
                var img = new Image()
                {
                    MaxHeight = 28,
                    Source    = new BitmapImage(new Uri("ms-appx:///Assets/DiscordBadges/partner.png")),
                    Opacity   = 0
                };
                ToolTipService.SetToolTip(img, App.GetString("/Dialogs/FlagDiscordPartner").ToUpper());
                BadgePanel.Children.Add(img);
                img.Fade(1).Start();
                break;
            }

            case 4:
            {
                var img = new Image()
                {
                    MaxHeight = 28,
                    Source    = new BitmapImage(new Uri("ms-appx:///Assets/DiscordBadges/hypesquad.png")),
                    Opacity   = 0
                };
                ToolTipService.SetToolTip(img, App.GetString("/Dialogs/FlagHypesquad"));
                BadgePanel.Children.Add(img);
                img.Fade(1).Start();
                break;
            }
            }
            if (profile.user.Id == "109338686889476096")
            {
                ViewStats.Visibility = Visibility.Visible;
            }



            var imageurl = Common.AvatarUri(profile.user.Avatar, profile.user.Id);

            SetupComposition(imageurl);
            var image = new BitmapImage(imageurl);

            if (!navFromFlyout)
            {
                AvatarFull.ImageSource = image;
            }
            //  AvatarBlurred.Source = image;

            if (profile.user.Avatar != null)
            {
                AvatarBG.Fill = Common.GetSolidColorBrush("#00000000");
            }
            else
            {
                AvatarBG.Fill = Common.DiscriminatorColor(profile.user.Discriminator);
            }


            if (profile.user.Bot)
            {
                return;
            }
            if (loadviaRest)
            {
                profile = await RESTCalls.GetUserProfile(profile.user.Id);
            }
            try
            {
                if (profile.PremiumSince.HasValue)
                {
                    var img = new Image()
                    {
                        MaxHeight = 28,
                        Source    = new BitmapImage(new Uri("ms-appx:///Assets/DiscordBadges/nitro.png")),
                        Opacity   = 0
                    };
                    ToolTipService.SetToolTip(img, App.GetString("/Main/PremiumMemberSince") + " " + Common.HumanizeDate(profile.PremiumSince.Value, null));
                    BadgePanel.Children.Add(img);
                    img.Fade(1.2f);
                }

                if (profile.connected_accounts != null)
                {
                    for (int i = 0; i < profile.connected_accounts.Count(); i++)
                    {
                        var    element  = profile.connected_accounts.ElementAt(i);
                        string themeExt = "";
                        if (element.Type.ToLower() == "steam")
                        {
                            if (App.Current.RequestedTheme == ApplicationTheme.Dark)
                            {
                                themeExt = "_light";
                            }
                            else
                            {
                                themeExt = "_dark";
                            }
                        }
                        element.ImagePath = "/Assets/ConnectionLogos/" + element.Type.ToLower() + themeExt + ".png";
                        Connections.Items.Add(element);
                    }
                }

                if (profile.MutualGuilds != null)
                {
                    for (int i = 0; i < profile.MutualGuilds.Count(); i++)
                    {
                        var element = profile.MutualGuilds.ElementAt(i);
                        if (!LocalState.Guilds.ContainsKey(element.Id))
                        {
                            continue;
                        }
                        element.Name      = LocalState.Guilds[element.Id].Raw.Name;
                        element.ImagePath = "https://discordapp.com/api/guilds/" + LocalState.Guilds[element.Id].Raw.Id + "/icons/" + LocalState.Guilds[element.Id].Raw.Icon + ".jpg";

                        if (element.Nick != null)
                        {
                            element.NickVisibility = Visibility.Visible;
                        }
                        else
                        {
                            element.NickVisibility = Visibility.Collapsed;
                        }

                        MutualGuilds.Items.Add(element);
                    }
                    if (MutualGuilds.Items.Count > 0)
                    {
                        commonServerPanel.Visibility = Visibility.Visible;
                        commonserverHeader.Fade(1, 300, 0).Start();
                    }
                }
            }
            catch
            {
            }

            if (profile?.user?.Id != null)
            {
                IEnumerable <SharedFriend> relationships = await RESTCalls.GetUserRelationShips(profile.user.Id);

                int relationshipcount = relationships.Count();

                if (relationshipcount == 0)
                {
                    return;
                }

                commonFriendPanel.Visibility = Visibility.Visible;
                commonfriendHeader.Fade(1, 300, 0).Start();
                for (int i = 0; i < relationshipcount; i++)
                {
                    var relationship = relationships.ElementAt(i);
                    relationship.Discriminator = "#" + relationship.Discriminator;
                    if (relationship.Avatar != null)
                    {
                        relationship.ImagePath = "https://cdn.discordapp.com/avatars/" + relationship.Id + "/" + relationship.Avatar + ".png";
                    }
                    else
                    {
                        relationship.ImagePath = "ms-appx:///Assets/DiscordIcon-old.png";
                    }

                    MutualFriends.Items.Add(relationship);
                }


                //var contact = await Managers.ContactManager.GetContact(profile.user.Id);
                //if (contact != null)
                //{
                //    if (contact.FullName != profile.user.Username + "#" + profile.user.Discriminator)
                //    {
                //        Name.Text = contact.FullName;
                //        Seperate.Visibility = Visibility.Visible;
                //    }
                //}
            }
        }