@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Diagnostics;
using System.Linq;
using Model = Discord.API.Connection;
using Model = Discord.API.Connection;
namespace Discord.Rest
namespace Discord.Rest
@@ -9,28 +11,49 @@ namespace Discord.Rest
public class RestConnection : IConnection
public class RestConnection : IConnection
{
{
/// <inheritdoc />
/// <inheritdoc />
public string Id { get; }
public string Id { get; private set; }
/// <inheritdoc />
/// <inheritdoc />
public string Type { g et; }
public string Name { get; private s et; }
/// <inheritdoc />
/// <inheritdoc />
public string Name { g et; }
public string Type { get; private s et; }
/// <inheritdoc />
/// <inheritdoc />
public bool IsRevoked { get; }
public bool? IsRevoked { get; private s et; }
/// <inheritdoc />
/// <inheritdoc />
public IReadOnlyCollection<ulong> IntegrationIds { get; }
public IReadOnlyCollection<IIntegration> Integrations { get; private set; }
/// <inheritdoc />
public bool Verified { get; private set; }
/// <inheritdoc />
public bool FriendSync { get; private set; }
/// <inheritdoc />
public bool ShowActivity { get; private set; }
/// <inheritdoc />
public ConnectionVisibility Visibility { get; private set; }
internal RestConnection(string id, string type, string name, bool isRevoked, IReadOnlyCollection<ulong> integrationIds)
{
Id = id;
Type = type;
Name = name;
IsRevoked = isRevoked;
internal BaseDiscordClient Discord { get; }
IntegrationIds = integrationIds;
internal RestConnection(BaseDiscordClient discord) {
Discord = discord;
}
}
internal static RestConnection Create(Model model)
internal static RestConnection Create(BaseDiscordClient discord, Model model)
{
var entity = new RestConnection(discord);
entity.Update(model);
return entity;
}
internal void Update(Model model)
{
{
return new RestConnection(model.Id, model.Type, model.Name, model.Revoked, model.Integrations.ToImmutableArray());
Id = model.Id;
Name = model.Name;
Type = model.Type;
IsRevoked = model.Revoked.IsSpecified ? model.Revoked.Value : null;
Integrations = model.Integrations.IsSpecified ?model.Integrations.Value
.Select(intergration => RestIntegration.Create(Discord, null, intergration)).ToImmutableArray() : null;
Verified = model.Verified;
FriendSync = model.FriendSync;
ShowActivity = model.ShowActivity;
Visibility = model.Visibility;
}
}
/// <summary>
/// <summary>
@@ -40,6 +63,6 @@ namespace Discord.Rest
/// Name of the connection.
/// Name of the connection.
/// </returns>
/// </returns>
public override string ToString() => Name;
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}, {Type}{(IsRevoked ? ", Revoked" : "")})";
private string DebuggerDisplay => $"{Name} ({Id}, {Type}{(IsRevoked.GetValueOrDefault() ? ", Revoked" : "")})";
}
}
}
}