| @@ -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,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> | ||||
| @@ -0,0 +1,9 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public interface IRelationship | |||||
| { | |||||
| RelationshipType Type { get; } | |||||
| IUser User { get; } | |||||
| } | |||||
| } | |||||
| @@ -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); | |||||
| } | } | ||||
| } | } | ||||
| @@ -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 | |||||
| } | |||||
| } | |||||
| @@ -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); | ||||
| @@ -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; | ||||
| @@ -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) | ||||
| { | { | ||||
| @@ -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!"); | |||||
| } | } | ||||
| } | } | ||||
| @@ -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(); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -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(); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -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; } | |||||
| } | |||||
| } | |||||
| @@ -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; | ||||
| } | } | ||||
| } | } | ||||
| @@ -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(); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||