Skip to content

Commit

Permalink
Add new member objects to events
Browse files Browse the repository at this point in the history
  • Loading branch information
foxbot committed May 27, 2018
1 parent a06e212 commit 8fb2c71
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/Discord.Net.Rest/API/Common/Message.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;
using System;

Expand All @@ -12,10 +12,16 @@ internal class Message
public MessageType Type { get; set; }
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
// ALWAYS sent on WebSocket messages
[JsonProperty("guild_id")]
public Optional<ulong> GuildId { get; set; }
[JsonProperty("webhook_id")]
public Optional<ulong> WebhookId { get; set; }
[JsonProperty("author")]
public Optional<User> Author { get; set; }
// ALWAYS sent on WebSocket messages
[JsonProperty("member")]
public Optional<GuildMember> Member { get; set; }
[JsonProperty("content")]
public Optional<string> Content { get; set; }
[JsonProperty("timestamp")]
Expand Down
5 changes: 4 additions & 1 deletion src/Discord.Net.Rest/API/Common/VoiceState.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API
Expand All @@ -11,6 +11,9 @@ internal class VoiceState
public ulong? ChannelId { get; set; }
[JsonProperty("user_id")]
public ulong UserId { get; set; }
// ALWAYS sent over WebSocket, never on REST
[JsonProperty("member")]
public Optional<GuildMember> Member { get; set; }
[JsonProperty("session_id")]
public string SessionId { get; set; }
[JsonProperty("deaf")]
Expand Down
6 changes: 5 additions & 1 deletion src/Discord.Net.WebSocket/API/Gateway/TypingStartEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591
#pragma warning disable CS1591
using Newtonsoft.Json;

namespace Discord.API.Gateway
Expand All @@ -9,6 +9,10 @@ internal class TypingStartEvent
public ulong UserId { get; set; }
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
[JsonProperty("member")]
public GuildMember Member { get; set; }
[JsonProperty("timestamp")]
public int Timestamp { get; set; }
}
Expand Down
10 changes: 8 additions & 2 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
if (author == null)
{
if (guild != null)
author = guild.AddOrUpdateUser(data.Author.Value); //User has no guild-specific data
author = guild.AddOrUpdateUser(data.Member.Value); //per g250k, we can create an entire member now
else if (channel is SocketGroupChannel)
author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value);
else
Expand Down Expand Up @@ -1361,6 +1361,11 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
}

var user = (channel as SocketChannel).GetUser(data.UserId);
if (user == null)
{
if (guild != null)
user = guild.AddOrUpdateUser(data.Member);
}
if (user != null)
await TimedInvokeAsync(_userIsTypingEvent, nameof(UserIsTyping), user, channel).ConfigureAwait(false);
}
Expand Down Expand Up @@ -1427,7 +1432,8 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
user = guild.GetUser(data.UserId);
if (user == null)
{
await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false);
user = guild.AddOrUpdateUser(data.Member.Value); //per g250k, this is always sent
//await UnknownGuildUserAsync(type, data.UserId, guild.Id).ConfigureAwait(false);
return;
}
}
Expand Down

0 comments on commit 8fb2c71

Please sign in to comment.