diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index 6196630a5..a92f96f7e 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -21,7 +21,7 @@ namespace Discord Task GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Returns a private message channel to this user, creating one if it does not already exist. Task CreateDMChannelAsync(RequestOptions options = null); - + /// Adds this user as a friend, this will remove a block Task AddFriendAsync(RequestOptions options = null); /// Blocks this user, and removes friend relation diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index 392791f62..5586577d6 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -39,7 +39,7 @@ namespace Discord.WebSocket _dmChannels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); - _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)AverageRelationshipsPerUser); + _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index c3db1b379..f791e55b1 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1679,7 +1679,7 @@ namespace Discord.WebSocket internal SocketRelationship AddRelationship(Relationship model, ClientState state) { var relation = SocketRelationship.Create(this, state, model); - State.AddRelationship(relation); + state.AddRelationship(relation); return relation; } internal SocketRelationship RemoveRelationship(ulong id) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 452f7f50e..0acbdb32c 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -1,5 +1,6 @@ using Discord.Rest; using System; +using System.Linq; using System.Threading.Tasks; using Model = Discord.API.User; using PresenceModel = Discord.API.Presence; @@ -21,6 +22,7 @@ namespace Discord.WebSocket public string Mention => MentionUtils.MentionUser(Id); public Game? Game => Presence.Game; public UserStatus Status => Presence.Status; + public RelationshipType Relationship => Discord.Relationships.FirstOrDefault(r => r.User.Id == Id)?.Type ?? RelationshipType.None; internal SocketUser(DiscordSocketClient discord, ulong id) : base(discord, id) @@ -55,13 +57,11 @@ namespace Discord.WebSocket => Task.FromResult(GlobalUser.DMChannel); async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); - + public async Task AddFriendAsync(RequestOptions options = null) => await Discord.ApiClient.AddFriendAsync(Id, options); - public async Task BlockUserAsync(RequestOptions options = null) => await Discord.ApiClient.BlockUserAsync(Id, options); - public async Task RemoveRelationshipAsync(RequestOptions options = null) => await Discord.ApiClient.RemoveRelationshipAsync(Id, options); }