Merged UserPresenceUpdated into UserUpdated

This commit is contained in:
RogueException
2017-03-13 23:19:54 -03:00
parent 506b4ff36a
commit 3bd920ce66
3 changed files with 8 additions and 44 deletions

View File

@@ -297,7 +297,7 @@ namespace Discord.WebSocket
client.UserBanned += (user, guild) => _userBannedEvent.InvokeAsync(user, guild);
client.UserUnbanned += (user, guild) => _userUnbannedEvent.InvokeAsync(user, guild);
client.UserUpdated += (oldUser, newUser) => _userUpdatedEvent.InvokeAsync(oldUser, newUser);
client.UserPresenceUpdated += (guild, user, oldPresence, newPresence) => _userPresenceUpdatedEvent.InvokeAsync(guild, user, oldPresence, newPresence);
client.GuildMemberUpdated += (oldUser, newUser) => _guildMemberUpdatedEvent.InvokeAsync(oldUser, newUser);
client.UserVoiceStateUpdated += (user, oldVoiceState, newVoiceState) => _userVoiceStateUpdatedEvent.InvokeAsync(user, oldVoiceState, newVoiceState);
client.CurrentUserUpdated += (oldUser, newUser) => _selfUpdatedEvent.InvokeAsync(oldUser, newUser);
client.UserIsTyping += (oldUser, newUser) => _userIsTypingEvent.InvokeAsync(oldUser, newUser);

View File

@@ -185,12 +185,6 @@ namespace Discord.WebSocket
remove { _guildMemberUpdatedEvent.Remove(value); }
}
private readonly AsyncEvent<Func<SocketGuildUser, SocketGuildUser, Task>> _guildMemberUpdatedEvent = new AsyncEvent<Func<SocketGuildUser, SocketGuildUser, Task>>();
public event Func<Optional<SocketGuild>, SocketUser, SocketPresence, SocketPresence, Task> UserPresenceUpdated
{
add { _userPresenceUpdatedEvent.Add(value); }
remove { _userPresenceUpdatedEvent.Remove(value); }
}
private readonly AsyncEvent<Func<Optional<SocketGuild>, SocketUser, SocketPresence, SocketPresence, Task>> _userPresenceUpdatedEvent = new AsyncEvent<Func<Optional<SocketGuild>, SocketUser, SocketPresence, SocketPresence, Task>>();
public event Func<SocketUser, SocketVoiceState, SocketVoiceState, Task> UserVoiceStateUpdated
{
add { _userVoiceStateUpdatedEvent.Add(value); }

View File

@@ -1318,46 +1318,16 @@ namespace Discord.WebSocket
return;
}
SocketPresence beforePresence;
SocketGlobalUser beforeGlobal;
var user = guild.GetUser(data.User.Id);
if (user != null)
{
beforePresence = user.Presence.Clone();
beforeGlobal = user.GlobalUser.Clone();
user.Update(State, data);
}
else
{
beforePresence = new SocketPresence(UserStatus.Offline, null);
user = guild.AddOrUpdateUser(data);
beforeGlobal = user.GlobalUser.Clone();
}
if (data.User.Username.IsSpecified || data.User.Avatar.IsSpecified)
{
await _userUpdatedEvent.InvokeAsync(beforeGlobal, user).ConfigureAwait(false);
return;
}
await _userPresenceUpdatedEvent.InvokeAsync(guild, user, beforePresence, user.Presence).ConfigureAwait(false);
if (user == null)
guild.AddOrUpdateUser(data);
}
else
{
var channel = State.GetChannel(data.User.Id);
if (channel != null)
{
var user = channel.GetUser(data.User.Id);
var beforePresence = user.Presence.Clone();
var before = user.GlobalUser.Clone();
user.Update(State, data);
await _userPresenceUpdatedEvent.InvokeAsync(Optional.Create<SocketGuild>(), user, beforePresence, user.Presence).ConfigureAwait(false);
if (data.User.Username.IsSpecified || data.User.Avatar.IsSpecified)
{
await _userUpdatedEvent.InvokeAsync(before, user).ConfigureAwait(false);
}
}
}
var globalUser = State.GetUser(data.User.Id);
var before = globalUser.Clone();
globalUser.Update(State, data);
await _userUpdatedEvent.InvokeAsync(before, globalUser).ConfigureAwait(false);
}
break;
case "TYPING_START":