using Model = Discord.API.Gateway.Reaction; namespace Discord.WebSocket { /// /// Represents a WebSocket-based reaction object. /// public class SocketReaction : IReaction { /// /// Gets the ID of the user who added the reaction. /// /// /// This property retrieves the snowflake identifier of the user responsible for this reaction. This /// property will always contain the user identifier in event that /// cannot be retrieved. /// /// /// A user snowflake identifier associated with the user. /// public ulong UserId { get; } /// /// Gets the user who added the reaction if possible. /// /// /// /// This property attempts to retrieve a WebSocket-cached user that is responsible for this reaction from /// the client. In other words, when the user is not in the WebSocket cache, this property may not /// contain a value, leaving the only identifiable information to be /// . /// /// /// If you wish to obtain an identifiable user object, consider utilizing /// which will attempt to retrieve the user from REST. /// /// /// /// A user object where possible; a value is not always returned. /// /// public Optional User { get; } /// /// Gets the ID of the message that has been reacted to. /// /// /// A message snowflake identifier associated with the message. /// public ulong MessageId { get; } /// /// Gets the message that has been reacted to if possible. /// /// /// A WebSocket-based message where possible; a value is not always returned. /// /// public Optional Message { get; } /// /// Gets the channel where the reaction takes place in. /// /// /// A WebSocket-based message channel. /// public ISocketMessageChannel Channel { get; } /// public IEmote Emote { get; } internal SocketReaction(ISocketMessageChannel channel, ulong messageId, Optional message, ulong userId, Optional user, IEmote emoji) { Channel = channel; MessageId = messageId; Message = message; UserId = userId; User = user; Emote = emoji; } internal static SocketReaction Create(Model model, ISocketMessageChannel channel, Optional message, Optional user) { IEmote emote; if (model.Emoji.Id.HasValue) emote = new Emote(model.Emoji.Id.Value, model.Emoji.Name, model.Emoji.Animated.GetValueOrDefault()); else emote = new Emoji(model.Emoji.Name); return new SocketReaction(channel, model.MessageId, message, model.UserId, user, emote); } /// public override bool Equals(object other) { if (other == null) return false; if (other == this) return true; var otherReaction = other as SocketReaction; if (otherReaction == null) return false; return UserId == otherReaction.UserId && MessageId == otherReaction.MessageId && Emote.Equals(otherReaction.Emote); } /// public override int GetHashCode() { unchecked { var hashCode = UserId.GetHashCode(); hashCode = (hashCode * 397) ^ MessageId.GetHashCode(); hashCode = (hashCode * 397) ^ Emote.GetHashCode(); return hashCode; } } } }