| @@ -596,7 +596,7 @@ namespace Discord | |||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case "GUILD_EMOJIS_UPDATE": //TODO: Add | |||||
| case "GUILD_EMOJIS_UPDATE": | |||||
| { | { | ||||
| await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_EMOJIS_UPDATE)").ConfigureAwait(false); | await _gatewayLogger.DebugAsync("Received Dispatch (GUILD_EMOJIS_UPDATE)").ConfigureAwait(false); | ||||
| @@ -28,11 +28,9 @@ namespace Discord | |||||
| } | } | ||||
| public void Update(Model model, UpdateSource source) | public void Update(Model model, UpdateSource source) | ||||
| { | { | ||||
| if (source == UpdateSource.Rest && IsAttached) return; | |||||
| if (/*source == UpdateSource.Rest && */IsAttached) return; | |||||
| //TODO: Is this cast okay? | |||||
| if (Recipient is User) | |||||
| (Recipient as User).Update(model.Recipient.Value, source); | |||||
| (Recipient as User).Update(model.Recipient.Value, source); | |||||
| } | } | ||||
| public async Task UpdateAsync() | public async Task UpdateAsync() | ||||
| @@ -7,11 +7,12 @@ namespace Discord | |||||
| { | { | ||||
| public CachedGlobalUser User { get; } | public CachedGlobalUser User { get; } | ||||
| public Game Game { get; private set; } | |||||
| public UserStatus Status { get; private set; } | |||||
| public DiscordSocketClient Discord => User.Discord; | public DiscordSocketClient Discord => User.Discord; | ||||
| public Game Game => Presence.Game; | |||||
| public UserStatus Status => Presence.Status; | |||||
| public Presence Presence => User.Presence; //{ get; private set; } | |||||
| public ulong Id => User.Id; | public ulong Id => User.Id; | ||||
| public string AvatarUrl => User.AvatarUrl; | public string AvatarUrl => User.AvatarUrl; | ||||
| public DateTimeOffset CreatedAt => User.CreatedAt; | public DateTimeOffset CreatedAt => User.CreatedAt; | ||||
| @@ -30,8 +31,7 @@ namespace Discord | |||||
| public void Update(PresenceModel model, UpdateSource source) | public void Update(PresenceModel model, UpdateSource source) | ||||
| { | { | ||||
| Status = model.Status; | |||||
| Game = model.Game != null ? new Game(model.Game) : null; | |||||
| User.Update(model, source); | |||||
| } | } | ||||
| public CachedDMUser Clone() => MemberwiseClone() as CachedDMUser; | public CachedDMUser Clone() => MemberwiseClone() as CachedDMUser; | ||||
| @@ -1,6 +1,6 @@ | |||||
| using System; | using System; | ||||
| using Discord.API; | |||||
| using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
| using PresenceModel = Discord.API.Presence; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| @@ -8,9 +8,9 @@ namespace Discord | |||||
| { | { | ||||
| private ushort _references; | private ushort _references; | ||||
| public Presence Presence { get; private set; } | |||||
| public new DiscordSocketClient Discord { get { throw new NotSupportedException(); } } | public new DiscordSocketClient Discord { get { throw new NotSupportedException(); } } | ||||
| public override UserStatus Status => UserStatus.Unknown;// _status; | |||||
| public override Game Game => null; //_game; | |||||
| public CachedGlobalUser(Model model) | public CachedGlobalUser(Model model) | ||||
| : base(model) | : base(model) | ||||
| @@ -39,6 +39,16 @@ namespace Discord | |||||
| lock (this) | lock (this) | ||||
| base.Update(model, source); | base.Update(model, source); | ||||
| } | } | ||||
| public void Update(PresenceModel model, UpdateSource source) | |||||
| { | |||||
| //Race conditions are okay here. Multiple shards racing already cant guarantee presence in order. | |||||
| //lock (this) | |||||
| //{ | |||||
| var game = model.Game != null ? new Game(model.Game) : null; | |||||
| Presence = new Presence(game, model.Status); | |||||
| //} | |||||
| } | |||||
| public CachedGlobalUser Clone() => MemberwiseClone() as CachedGlobalUser; | public CachedGlobalUser Clone() => MemberwiseClone() as CachedGlobalUser; | ||||
| ICachedUser ICachedUser.Clone() => Clone(); | ICachedUser ICachedUser.Clone() => Clone(); | ||||
| @@ -3,28 +3,12 @@ using PresenceModel = Discord.API.Presence; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| //TODO: C#7 Candidate for record type | |||||
| internal struct Presence : IPresence | |||||
| { | |||||
| public Game Game { get; } | |||||
| public UserStatus Status { get; } | |||||
| public Presence(Game game, UserStatus status) | |||||
| { | |||||
| Game = game; | |||||
| Status = status; | |||||
| } | |||||
| public Presence Clone() => this; | |||||
| } | |||||
| internal class CachedGuildUser : GuildUser, ICachedUser | internal class CachedGuildUser : GuildUser, ICachedUser | ||||
| { | { | ||||
| public Presence Presence { get; private set; } | |||||
| public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | ||||
| public new CachedGuild Guild => base.Guild as CachedGuild; | public new CachedGuild Guild => base.Guild as CachedGuild; | ||||
| public new CachedGlobalUser User => base.User as CachedGlobalUser; | public new CachedGlobalUser User => base.User as CachedGlobalUser; | ||||
| public Presence Presence => User.Presence; //{ get; private set; } | |||||
| public override Game Game => Presence.Game; | public override Game Game => Presence.Game; | ||||
| public override UserStatus Status => Presence.Status; | public override UserStatus Status => Presence.Status; | ||||
| @@ -38,7 +22,7 @@ namespace Discord | |||||
| public CachedGuildUser(CachedGuild guild, CachedGlobalUser user, Model model) | public CachedGuildUser(CachedGuild guild, CachedGlobalUser user, Model model) | ||||
| : base(guild, user, model) | : base(guild, user, model) | ||||
| { | { | ||||
| Presence = new Presence(null, UserStatus.Offline); | |||||
| //Presence = new Presence(null, UserStatus.Offline); | |||||
| } | } | ||||
| public CachedGuildUser(CachedGuild guild, CachedGlobalUser user, PresenceModel model) | public CachedGuildUser(CachedGuild guild, CachedGlobalUser user, PresenceModel model) | ||||
| : base(guild, user, model) | : base(guild, user, model) | ||||
| @@ -50,7 +34,9 @@ namespace Discord | |||||
| base.Update(model, source); | base.Update(model, source); | ||||
| var game = model.Game != null ? new Game(model.Game) : null; | var game = model.Game != null ? new Game(model.Game) : null; | ||||
| Presence = new Presence(game, model.Status); | |||||
| //Presence = new Presence(game, model.Status); | |||||
| User.Update(model, source); | |||||
| } | } | ||||
| public CachedGuildUser Clone() => MemberwiseClone() as CachedGuildUser; | public CachedGuildUser Clone() => MemberwiseClone() as CachedGuildUser; | ||||
| @@ -0,0 +1,17 @@ | |||||
| namespace Discord | |||||
| { | |||||
| //TODO: C#7 Candidate for record type | |||||
| internal struct Presence : IPresence | |||||
| { | |||||
| public Game Game { get; } | |||||
| public UserStatus Status { get; } | |||||
| public Presence(Game game, UserStatus status) | |||||
| { | |||||
| Game = game; | |||||
| Status = status; | |||||
| } | |||||
| public Presence Clone() => this; | |||||
| } | |||||
| } | |||||