Fix: RestDMChannel relies on recipient (#2910)
* don't assume we have a DM user * also check nullable for Update/GetUser * Update src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> --------- Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
This commit is contained in:
@@ -29,23 +29,26 @@ namespace Discord.Rest
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a collection that is the current logged-in user and the recipient.
|
/// Gets a collection that is the current logged-in user and the recipient.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyCollection<RestUser> Users => ImmutableArray.Create(CurrentUser, Recipient);
|
public IReadOnlyCollection<RestUser> Users => Recipient is null
|
||||||
|
? ImmutableArray<RestUser>.Empty
|
||||||
|
: ImmutableArray.Create(CurrentUser, Recipient);
|
||||||
|
|
||||||
internal RestDMChannel(BaseDiscordClient discord, ulong id, ulong recipientId)
|
internal RestDMChannel(BaseDiscordClient discord, ulong id, ulong? recipientId)
|
||||||
: base(discord, id)
|
: base(discord, id)
|
||||||
{
|
{
|
||||||
Recipient = new RestUser(Discord, recipientId);
|
Recipient = recipientId.HasValue ? new RestUser(Discord, recipientId.Value) : null;
|
||||||
CurrentUser = new RestUser(Discord, discord.CurrentUser.Id);
|
CurrentUser = new RestUser(Discord, discord.CurrentUser.Id);
|
||||||
}
|
}
|
||||||
internal new static RestDMChannel Create(BaseDiscordClient discord, Model model)
|
internal new static RestDMChannel Create(BaseDiscordClient discord, Model model)
|
||||||
{
|
{
|
||||||
var entity = new RestDMChannel(discord, model.Id, model.Recipients.Value[0].Id);
|
var entity = new RestDMChannel(discord, model.Id, model.Recipients.GetValueOrDefault(null)?[0].Id);
|
||||||
entity.Update(model);
|
entity.Update(model);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
internal override void Update(Model model)
|
internal override void Update(Model model)
|
||||||
{
|
{
|
||||||
Recipient.Update(model.Recipients.Value[0]);
|
if(model.Recipients.IsSpecified)
|
||||||
|
Recipient?.Update(model.Recipients.Value[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -68,7 +71,7 @@ namespace Discord.Rest
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public RestUser GetUser(ulong id)
|
public RestUser GetUser(ulong id)
|
||||||
{
|
{
|
||||||
if (id == Recipient.Id)
|
if (id == Recipient?.Id)
|
||||||
return Recipient;
|
return Recipient;
|
||||||
else if (id == Discord.CurrentUser.Id)
|
else if (id == Discord.CurrentUser.Id)
|
||||||
return CurrentUser;
|
return CurrentUser;
|
||||||
|
|||||||
Reference in New Issue
Block a user