@@ -26,24 +26,45 @@ namespace Discord
[JsonIgnore]
public User Inviter => _inviter.Value;
private readonly Reference<User> _inviter;
private User _generatedInviter;
/// <summary> Returns the server this invite is to. </summary>
[JsonIgnore]
public Server Server => _server.Value;
private readonly Reference<Server> _server;
private Server _generatedServer;
/// <summary> Returns the channel this invite is to. </summary>
[JsonIgnore]
public Channel Channel => _channel.Value;
private readonly Reference<Channel> _channel;
private Channel _generatedChannel;
internal Invite(DiscordClient client, string code, string xkcdPass, string serverId, string inviterId, string channelId)
: base(client, code)
{
XkcdCode = xkcdPass;
_server = new Reference<Server>(serverId, x => _client.Servers[x] ?? new Server(client, x));
_inviter = new Reference<User>(serverId, x => _client.Users[x, _server.Id] ?? new User(client, x, _server.Id));
_channel = new Reference<Channel>(serverId, x => _client.Channels[x] ?? new Channel(client, x, _server.Id, null));
_server = new Reference<Server>(serverId, x =>
{
var server = _client.Servers[x];
if (server == null)
server = _generatedServer = new Server(client, x);
return server;
});
_inviter = new Reference<User>(serverId, x =>
{
var inviter = _client.Users[x, _server.Id];
if (inviter == null)
inviter = _generatedInviter = new User(client, x, _server.Id);
return inviter;
});
_channel = new Reference<Channel>(serverId, x =>
{
var channel = _client.Channels[x];
if (channel == null)
channel = _generatedChannel = new Channel(client, x, _server.Id, null);
return channel;
});
}
internal override void LoadReferences()
{
@@ -58,6 +79,13 @@ namespace Discord
internal void Update(InviteInfo model)
{
if (model.Guild != null && _generatedServer != null)
_generatedServer.Update(model.Guild);
if (model.Inviter != null && _generatedInviter != null)
_generatedInviter.Update(model.Inviter);
if (model.Channel != null && _generatedChannel != null)
_generatedChannel.Update(model.Channel);
if (model.IsRevoked != null)
IsRevoked = model.IsRevoked.Value;
if (model.IsTemporary != null)