@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Linq;
using Discord.API.Gateway;
using Model = Discord.API.Message;
@@ -19,7 +20,7 @@ namespace Discord.WebSocket
private ImmutableArray<Attachment> _attachments;
private ImmutableArray<Embed> _embeds;
private ImmutableArray<ITag> _tags;
private ImmutableArray<IReaction> _reactions ;
private List<SocketReaction> _reactions = new List<SocketReaction>() ;
public override bool IsTTS => _isTTS;
public override bool IsPinned => _isPinned;
@@ -31,7 +32,7 @@ namespace Discord.WebSocket
public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags);
public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _tags);
public override IReadOnlyCollection<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags);
public override IReadOnlyCollection<IReaction> Reactions => _reactions ;
public IReadOnlyDictionary<Emoji, int> Reactions => _reactions.GroupBy(r => r.Emoji).ToDictionary(x => x.Key, x => x.Count()) ;
internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author)
: base(discord, id, channel, author)
@@ -104,20 +105,6 @@ namespace Discord.WebSocket
}
}
if (model.Reactions.IsSpecified)
{
var value = model.Reactions.Value;
if (value.Length > 0)
{
var reactions = ImmutableArray.CreateBuilder<IReaction>(value.Length);
for (int i = 0; i < value.Length; i++)
reactions.Add(new SocketReaction(value[i] as GatewayReaction));
_reactions = reactions.ToImmutable();
}
else
_reactions = ImmutableArray.Create<IReaction>();
}
if (model.Content.IsSpecified)
{
var text = model.Content.Value;
@@ -126,6 +113,15 @@ 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);
}
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options = null)
=> MessageHelper.ModifyAsync(this, Discord, func, options);