[abibrk] change: Update ISystemMessage interface to allow reactions (#1368)

* Move reaction methods of IUserMessage to IReactionMessage

Moves the reaction-related methods contained in IUserMessage to the IReactionMessage type. Updates the type of ISystemMessage so that it implements IReactionMessage.

* Move rest reaction implementation to RestReactionMessage

Copies the reaction implementation from RestUserMessage to RestReactionMessage. Updates RestUserMessage and RestSystemMessage to be derived from RestReactionMessage instead of RestMessage.

* Move WS reaction implementation to SocketReactionMessage

Copies the reaction implementation from SocketUserMessage into SocketReactionMessage. Updates SocketSystemMessage and SocketUserMessage to use SocketReactionMessage as the base class.

* docs: update summary for ReactionMessage classes

* Remove ReactionMessage types, move reaction impl to IMessage

Removes the IReactionMessage and derived types, which was unnecessary since all classes derived from IReactionMessage were IMessage.

Moves the reaction implementation to IMessage and derived types.
This commit is contained in:
Chris Johnston
2019-09-08 08:18:52 -07:00
committed by Christopher F
parent dcd9cdd13e
commit 07f4d5f353
6 changed files with 155 additions and 153 deletions

View File

@@ -15,7 +15,6 @@ namespace Discord.WebSocket
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketUserMessage : SocketMessage, IUserMessage
{
private readonly List<SocketReaction> _reactions = new List<SocketReaction>();
private bool _isMentioningEveryone, _isTTS, _isPinned, _isSuppressed;
private long? _editedTimestampTicks;
private ImmutableArray<Attachment> _attachments = ImmutableArray.Create<Attachment>();
@@ -42,8 +41,6 @@ namespace Discord.WebSocket
public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _tags);
/// <inheritdoc />
public override IReadOnlyCollection<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags);
/// <inheritdoc />
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) });
internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source)
: base(discord, id, channel, author, source)
@@ -126,42 +123,13 @@ namespace Discord.WebSocket
model.Content = text;
}
}
internal void AddReaction(SocketReaction reaction)
{
_reactions.Add(reaction);
}
internal void RemoveReaction(SocketReaction reaction)
{
if (_reactions.Contains(reaction))
_reactions.Remove(reaction);
}
internal void ClearReactions()
{
_reactions.Clear();
}
/// <inheritdoc />
/// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)
=> MessageHelper.ModifyAsync(this, Discord, func, options);
/// <inheritdoc />
public Task AddReactionAsync(IEmote emote, RequestOptions options = null)
=> MessageHelper.AddReactionAsync(this, emote, Discord, options);
/// <inheritdoc />
public Task RemoveReactionAsync(IEmote emote, IUser user, RequestOptions options = null)
=> MessageHelper.RemoveReactionAsync(this, user.Id, emote, Discord, options);
/// <inheritdoc />
public Task RemoveReactionAsync(IEmote emote, ulong userId, RequestOptions options = null)
=> MessageHelper.RemoveReactionAsync(this, userId, emote, Discord, options);
/// <inheritdoc />
public Task RemoveAllReactionsAsync(RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
/// <inheritdoc />
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
/// <inheritdoc />
public Task PinAsync(RequestOptions options = null)
=> MessageHelper.PinAsync(this, Discord, options);