misc: Internal change to GetOrCreateUser (#1852)

This commit is contained in:
Paulo
2021-05-26 20:08:15 -03:00
committed by GitHub
parent 8ed8714375
commit dfaaa21e0e
4 changed files with 13 additions and 11 deletions

View File

@@ -314,11 +314,13 @@ namespace Discord.WebSocket
/// Clears cached users from the client.
/// </summary>
public void PurgeUserCache() => State.PurgeUsers();
internal SocketGlobalUser GetOrCreateUser(ClientState state, Discord.API.User model, bool cache)
internal SocketGlobalUser GetOrCreateUser(ClientState state, Discord.API.User model)
{
if (cache)
return state.GetOrAddUser(model.Id, x => SocketGlobalUser.Create(this, state, model));
return state.GetUser(model.Id) ?? SocketGlobalUser.Create(this, state, model);
return state.GetOrAddUser(model.Id, x => SocketGlobalUser.Create(this, state, model));
}
internal SocketUser GetOrCreateTemporaryUser(ClientState state, Discord.API.User model)
{
return state.GetUser(model.Id) ?? (SocketUser)SocketUnknownUser.Create(this, state, model);
}
internal SocketGlobalUser GetOrCreateSelfUser(ClientState state, Discord.API.User model)
{

View File

@@ -29,14 +29,14 @@ namespace Discord.WebSocket
/// </summary>
public new IReadOnlyCollection<SocketUser> Users => ImmutableArray.Create(Discord.CurrentUser, Recipient);
internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketGlobalUser recipient)
internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketUser recipient)
: base(discord, id)
{
Recipient = recipient;
}
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model)
{
var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateUser(state, model.Recipients.Value[0], false));
var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateTemporaryUser(state, model.Recipients.Value[0]));
entity.Update(state, model);
return entity;
}
@@ -46,7 +46,7 @@ namespace Discord.WebSocket
}
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient)
{
var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateUser(state, recipient, false));
var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateTemporaryUser(state, recipient));
entity.Update(state, recipient);
return entity;
}

View File

@@ -38,7 +38,7 @@ namespace Discord.WebSocket
}
internal static SocketGroupUser Create(SocketGroupChannel channel, ClientState state, Model model)
{
var entity = new SocketGroupUser(channel, channel.Discord.GetOrCreateUser(state, model, true));
var entity = new SocketGroupUser(channel, channel.Discord.GetOrCreateUser(state, model));
entity.Update(state, model);
return entity;
}

View File

@@ -116,20 +116,20 @@ namespace Discord.WebSocket
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, UserModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model, true));
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model));
entity.Update(state, model);
entity.UpdateRoles(new ulong[0]);
return entity;
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, MemberModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User, true));
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model);
return entity;
}
internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model)
{
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User, true));
var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User));
entity.Update(state, model, false);
return entity;
}