示例#1
0
        private SimpleFriend NewSF(Friend f)
        {
            var friend = new SimpleFriend();

            friend.User = f.user;
            friend.RelationshipStatus = f.Type;
            friend.SharedGuilds       = new List <SimpleFriend.SharedGuild>();
            foreach (var guild in LocalState.Guilds)
            {
                if (guild.Value.members.ContainsKey(friend.User.Id))
                {
                    friend.SharedGuilds.Add(new SimpleFriend.SharedGuild()
                    {
                        Id       = guild.Value.Raw.Id,
                        ImageUrl = "https://discordapp.com/api/guilds/" + guild.Value.Raw.Id + "/icons/" + guild.Value.Raw.Icon + ".jpg",
                        Name     = guild.Value.Raw.Name
                    });
                }
            }
            if (LocalState.PresenceDict.ContainsKey(f.user.Id))
            {
                friend.UserStatus = LocalState.PresenceDict[f.user.Id].Status;
            }
            else
            {
                friend.UserStatus = "offline";
            }
            return(friend);
        }
示例#2
0
        /// <summary>
        /// Add relation ship to Panel
        /// </summary>
        private async Task AddRelationshipToUI(GatewayEventArgs <Friend> e)
        {
            // Run on UI thread
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                      async() =>
            {
                // Create SimpleFriend Object
                SimpleFriend sfriend = await NewSF(e.EventData);

                // Add to appropiate list(s)
                if (sfriend.RelationshipStatus == 1)
                {
                    AllView.Items.Add(sfriend);
                }
                else if (sfriend.RelationshipStatus == 2)
                {
                    BlockedView.Items.Add(sfriend);
                }
                else if (sfriend.RelationshipStatus == 3 || sfriend.RelationshipStatus == 4)
                {
                    if (sfriend.RelationshipStatus == 3)
                    {
                        FriendNotification(sfriend.User);
                    }
                    App.FriendNotifications += 1;
                    App.UpdateUnreadIndicators();
                    PendingCounter.Text = App.FriendNotifications.ToString();
                    PendingView.Items.Add(sfriend);
                }
            });
        }
示例#3
0
 private async Task AddRelationshipToUI(Gateway.GatewayEventArgs <Friend> e)
 {
     await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                   () =>
     {
         SimpleFriend sfriend = NewSF(e.EventData);
         if (sfriend.RelationshipStatus == 1)
         {
             AllView.Items.Add(sfriend);
         }
         else if (sfriend.RelationshipStatus == 2)
         {
             BlockedView.Items.Add(sfriend);
         }
         else if (sfriend.RelationshipStatus == 3 || sfriend.RelationshipStatus == 4)
         {
             if (sfriend.RelationshipStatus == 3)
             {
                 FriendNotification(sfriend.User);
             }
             App.FriendNotifications += 1;
             App.UpdateUnreadIndicators();
             PendingCounter.Text = App.FriendNotifications.ToString();
             PendingView.Items.Add(NewSF(e.EventData));
         }
     });
 }
示例#4
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);
        }