Browse Source

Added property to socket user to get relationship, I also fucked up on the "AddRelationship" internal method.

pull/369/head
ObsidianMinor 8 years ago
parent
commit
e5023b2b03
4 changed files with 6 additions and 6 deletions
  1. +1
    -1
      src/Discord.Net.Core/Entities/Users/IUser.cs
  2. +1
    -1
      src/Discord.Net.WebSocket/ClientState.cs
  3. +1
    -1
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  4. +3
    -3
      src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs

+ 1
- 1
src/Discord.Net.Core/Entities/Users/IUser.cs View File

@@ -21,7 +21,7 @@ namespace Discord
Task<IDMChannel> GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); Task<IDMChannel> GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> /// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary>
Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null); Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null);
/// <summary> Adds this user as a friend, this will remove a block </summary> /// <summary> Adds this user as a friend, this will remove a block </summary>
Task AddFriendAsync(RequestOptions options = null); Task AddFriendAsync(RequestOptions options = null);
/// <summary> Blocks this user, and removes friend relation </summary> /// <summary> Blocks this user, and removes friend relation </summary>


+ 1
- 1
src/Discord.Net.WebSocket/ClientState.cs View File

@@ -39,7 +39,7 @@ namespace Discord.WebSocket
_dmChannels = new ConcurrentDictionary<ulong, SocketDMChannel>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _dmChannels = new ConcurrentDictionary<ulong, SocketDMChannel>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier));
_guilds = new ConcurrentDictionary<ulong, SocketGuild>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary<ulong, SocketGuild>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier));
_users = new ConcurrentDictionary<ulong, SocketGlobalUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); _users = new ConcurrentDictionary<ulong, SocketGlobalUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier));
_relations = new ConcurrentDictionary<ulong, SocketRelationship>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)AverageRelationshipsPerUser);
_relations = new ConcurrentDictionary<ulong, SocketRelationship>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier));
_groupChannels = new ConcurrentHashSet<ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet<ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier));
} }




+ 1
- 1
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1679,7 +1679,7 @@ namespace Discord.WebSocket
internal SocketRelationship AddRelationship(Relationship model, ClientState state) internal SocketRelationship AddRelationship(Relationship model, ClientState state)
{ {
var relation = SocketRelationship.Create(this, state, model); var relation = SocketRelationship.Create(this, state, model);
State.AddRelationship(relation);
state.AddRelationship(relation);
return relation; return relation;
} }
internal SocketRelationship RemoveRelationship(ulong id) internal SocketRelationship RemoveRelationship(ulong id)


+ 3
- 3
src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs View File

@@ -1,5 +1,6 @@
using Discord.Rest; using Discord.Rest;
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.User; using Model = Discord.API.User;
using PresenceModel = Discord.API.Presence; using PresenceModel = Discord.API.Presence;
@@ -21,6 +22,7 @@ namespace Discord.WebSocket
public string Mention => MentionUtils.MentionUser(Id); public string Mention => MentionUtils.MentionUser(Id);
public Game? Game => Presence.Game; public Game? Game => Presence.Game;
public UserStatus Status => Presence.Status; 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) internal SocketUser(DiscordSocketClient discord, ulong id)
: base(discord, id) : base(discord, id)
@@ -55,13 +57,11 @@ namespace Discord.WebSocket
=> Task.FromResult<IDMChannel>(GlobalUser.DMChannel); => Task.FromResult<IDMChannel>(GlobalUser.DMChannel);
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options) async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
=> await CreateDMChannelAsync(options).ConfigureAwait(false); => await CreateDMChannelAsync(options).ConfigureAwait(false);
public async Task AddFriendAsync(RequestOptions options = null) public async Task AddFriendAsync(RequestOptions options = null)
=> await Discord.ApiClient.AddFriendAsync(Id, options); => await Discord.ApiClient.AddFriendAsync(Id, options);

public async Task BlockUserAsync(RequestOptions options = null) public async Task BlockUserAsync(RequestOptions options = null)
=> await Discord.ApiClient.BlockUserAsync(Id, options); => await Discord.ApiClient.BlockUserAsync(Id, options);

public async Task RemoveRelationshipAsync(RequestOptions options = null) public async Task RemoveRelationshipAsync(RequestOptions options = null)
=> await Discord.ApiClient.RemoveRelationshipAsync(Id, options); => await Discord.ApiClient.RemoveRelationshipAsync(Id, options);
} }


Loading…
Cancel
Save