Browse Source

misc: Internal change to GetOrCreateUser (#1852)

tags/3.0.0
Paulo GitHub 4 years ago
parent
commit
dfaaa21e0e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions
  1. +6
    -4
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  2. +3
    -3
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  3. +1
    -1
      src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs
  4. +3
    -3
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs

+ 6
- 4
src/Discord.Net.WebSocket/DiscordSocketClient.cs 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)
{


+ 3
- 3
src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs 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;
}


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs 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;
}


+ 3
- 3
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs 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;
}


Loading…
Cancel
Save