Browse Source

Working on redoing relations because the original version was shit

pull/369/head
ObsidianMinor 8 years ago
parent
commit
be26adc2e7
14 changed files with 110 additions and 23 deletions
  1. +0
    -11
      src/Discord.Net.Core/API/Rest/BlockUserParams.cs
  2. +1
    -1
      src/Discord.Net.Core/Discord.Net.Core.csproj
  3. +9
    -0
      src/Discord.Net.Core/Entities/Users/IRelationship.cs
  4. +7
    -0
      src/Discord.Net.Core/Entities/Users/IUser.cs
  5. +14
    -0
      src/Discord.Net.Core/Entities/Users/RelationshipType.cs
  6. +1
    -4
      src/Discord.Net.Core/IDiscordClient.cs
  7. +1
    -4
      src/Discord.Net.Rest/BaseDiscordClient.cs
  8. +3
    -3
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  9. +9
    -0
      src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs
  10. +15
    -0
      src/Discord.Net.Rest/Entities/Users/RestUser.cs
  11. +15
    -0
      src/Discord.Net.Rpc/Entities/Users/RpcUser.cs
  12. +11
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs
  13. +9
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs
  14. +15
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs

+ 0
- 11
src/Discord.Net.Core/API/Rest/BlockUserParams.cs View File

@@ -1,11 +0,0 @@
using Newtonsoft.Json;

namespace Discord.API.Rest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class BlockUserParams
{
[JsonProperty("type")]
public RelationshipType Type { get; } = RelationshipType.Blocked;
}
}

+ 1
- 1
src/Discord.Net.Core/Discord.Net.Core.csproj View File

@@ -1,4 +1,4 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix> <VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix Condition="'$(BuildNumber)' == ''">rc-dev</VersionSuffix> <VersionSuffix Condition="'$(BuildNumber)' == ''">rc-dev</VersionSuffix>


+ 9
- 0
src/Discord.Net.Core/Entities/Users/IRelationship.cs View File

@@ -0,0 +1,9 @@
namespace Discord
{
public interface IRelationship
{
RelationshipType Type { get; }

IUser User { get; }
}
}

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

@@ -21,5 +21,12 @@ 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>
Task AddFriendAsync(RequestOptions options = null);
/// <summary> Blocks this user, and removes friend relation </summary>
Task BlockUserAsync(RequestOptions options = null);
/// <summary> Removes the relationship of this user </summary>
Task RemoveRelationshipAsync(RequestOptions options = null);
} }
} }

+ 14
- 0
src/Discord.Net.Core/Entities/Users/RelationshipType.cs View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Discord
{
public enum RelationshipType
{
Friend = 1,
Blocked = 2,
IncomingPending = 3,
OutgoingPending = 4
}
}

+ 1
- 4
src/Discord.Net.Core/IDiscordClient.cs View File

@@ -31,10 +31,7 @@ namespace Discord
Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
Task<IUser> GetUserAsync(string username, string discriminator); Task<IUser> GetUserAsync(string username, string discriminator);


Task<IReadOnlyCollection<Relationship>> GetRelationshipsAsync();
Task RemoveRelationshipAsync(ulong userId);
Task AddFriendAsync(ulong userId);
Task BlockUserAsync(ulong userId);
Task<IReadOnlyCollection<IRelationship>> GetRelationshipsAsync();


Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(); Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync();
Task<IVoiceRegion> GetVoiceRegionAsync(string id); Task<IVoiceRegion> GetVoiceRegionAsync(string id);


+ 1
- 4
src/Discord.Net.Rest/BaseDiscordClient.cs View File

@@ -122,10 +122,7 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() => Dispose(true); public void Dispose() => Dispose(true);


public Task<IReadOnlyCollection<API.Relationship>> GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync();
public Task AddFriendAsync(ulong userId) => ApiClient.AddFriendAsync(userId);
public Task BlockUserAsync(ulong userId) => ApiClient.BlockUserAsync(userId);
public Task RemoveRelationshipAsync(ulong userId) => ApiClient.RemoveRelationshipAsync(userId);
public Task<IReadOnlyCollection<IRelationship>> GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync();


//IDiscordClient //IDiscordClient
ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected;


+ 3
- 3
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -1030,10 +1030,10 @@ namespace Discord.API
} }
//Relationships //Relationships
public async Task<IReadOnlyCollection<Relationship>> GetRelationshipsAsync(RequestOptions options = null)
public async Task<IReadOnlyCollection<IRelationship>> GetRelationshipsAsync(RequestOptions options = null)
{ {
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);
return await SendAsync<IReadOnlyCollection<Relationship>>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false);
return await SendAsync<IReadOnlyCollection<IRelationship>>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false);
} }
public async Task AddFriendAsync(ulong userId, RequestOptions options = null) public async Task AddFriendAsync(ulong userId, RequestOptions options = null)
{ {
@@ -1047,7 +1047,7 @@ namespace Discord.API
Preconditions.NotEqual(userId, 0, nameof(userId)); Preconditions.NotEqual(userId, 0, nameof(userId));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new BlockUserParams(), new BucketIds(), options: options).ConfigureAwait(false);
await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new { value = 2 }, new BucketIds(), options: options).ConfigureAwait(false);
} }
public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null) public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null)
{ {


+ 9
- 0
src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs View File

@@ -49,5 +49,14 @@ namespace Discord.Rest
var model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); var model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
Update(model); Update(model);
} }

Task IUser.AddFriendAsync(RequestOptions options) =>
throw new InvalidOperationException("You can't friend yourself!");

Task IUser.BlockUserAsync(RequestOptions options) =>
throw new InvalidOperationException("You can't block yourself!");

Task IUser.RemoveRelationshipAsync(RequestOptions options) =>
throw new InvalidOperationException("You don't have any relations with yourself!");
} }
} }

+ 15
- 0
src/Discord.Net.Rest/Entities/Users/RestUser.cs View File

@@ -59,5 +59,20 @@ namespace Discord.Rest
=> Task.FromResult<IDMChannel>(null); => Task.FromResult<IDMChannel>(null);
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 Task AddFriendAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task BlockUserAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemoveRelationshipAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}
} }
} }

+ 15
- 0
src/Discord.Net.Rpc/Entities/Users/RpcUser.cs View File

@@ -54,5 +54,20 @@ namespace Discord.Rpc
=> Task.FromResult<IDMChannel>(null); => Task.FromResult<IDMChannel>(null);
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 Task AddFriendAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task BlockUserAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemoveRelationshipAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}
} }
} }

+ 11
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs View File

@@ -0,0 +1,11 @@
using System;

namespace Discord.WebSocket
{
public class SocketRelationship : IRelationship
{
public RelationshipType Type { get; private set; }

public IUser User { get; private set; }
}
}

+ 9
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs View File

@@ -46,6 +46,15 @@ namespace Discord.WebSocket
public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options); => UserHelper.ModifyAsync(this, Discord, func, options);


Task IUser.AddFriendAsync(RequestOptions options) =>
throw new InvalidOperationException("You can't friend yourself!");

Task IUser.BlockUserAsync(RequestOptions options) =>
throw new InvalidOperationException("You can't block yourself!");

Task IUser.RemoveRelationshipAsync(RequestOptions options) =>
throw new InvalidOperationException("You don't have any relations with yourself!");

internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;
} }
} }

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

@@ -55,5 +55,20 @@ 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 Task AddFriendAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task BlockUserAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemoveRelationshipAsync(RequestOptions options = null)
{
throw new NotImplementedException();
}
} }
} }

Loading…
Cancel
Save