@@ -39,6 +39,13 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
bool IsSuppressed { get; } | bool IsSuppressed { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the value that indicates whether this message mentioned everyone. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// <c>true</c> if this message mentioned everyone; otherwise <c>false</c>. | |||||
/// </returns> | |||||
bool MentionedEveryone { get; } | |||||
/// <summary> | |||||
/// Gets the content for this message. | /// Gets the content for this message. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -37,6 +37,9 @@ namespace Discord.Rest | |||||
public virtual bool IsSuppressed => false; | public virtual bool IsSuppressed => false; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public virtual DateTimeOffset? EditedTimestamp => null; | public virtual DateTimeOffset? EditedTimestamp => null; | ||||
/// <inheritdoc /> | |||||
public virtual bool MentionedEveryone => false; | |||||
/// <summary> | /// <summary> | ||||
/// Gets a collection of the <see cref="Attachment"/>'s on the message. | /// Gets a collection of the <see cref="Attachment"/>'s on the message. | ||||
/// </summary> | /// </summary> | ||||
@@ -18,6 +18,8 @@ namespace Discord.Rest | |||||
private ImmutableArray<Attachment> _attachments = ImmutableArray.Create<Attachment>(); | private ImmutableArray<Attachment> _attachments = ImmutableArray.Create<Attachment>(); | ||||
private ImmutableArray<Embed> _embeds = ImmutableArray.Create<Embed>(); | private ImmutableArray<Embed> _embeds = ImmutableArray.Create<Embed>(); | ||||
private ImmutableArray<ITag> _tags = ImmutableArray.Create<ITag>(); | private ImmutableArray<ITag> _tags = ImmutableArray.Create<ITag>(); | ||||
private ImmutableArray<ulong> _roleMentionIds = ImmutableArray.Create<ulong>(); | |||||
private ImmutableArray<RestUser> _userMentions = ImmutableArray.Create<RestUser>(); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool IsTTS => _isTTS; | public override bool IsTTS => _isTTS; | ||||
@@ -28,15 +30,17 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); | public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool MentionedEveryone => _isMentioningEveryone; | |||||
/// <inheritdoc /> | |||||
public override IReadOnlyCollection<Attachment> Attachments => _attachments; | public override IReadOnlyCollection<Attachment> Attachments => _attachments; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<Embed> Embeds => _embeds; | public override IReadOnlyCollection<Embed> Embeds => _embeds; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<ulong> MentionedChannelIds => MessageHelper.FilterTagsByKey(TagType.ChannelMention, _tags); | public override IReadOnlyCollection<ulong> MentionedChannelIds => MessageHelper.FilterTagsByKey(TagType.ChannelMention, _tags); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<ulong> MentionedRoleIds => MessageHelper.FilterTagsByKey(TagType.RoleMention, _tags); | |||||
public override IReadOnlyCollection<ulong> MentionedRoleIds => _roleMentionIds; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<RestUser> MentionedUsers => MessageHelper.FilterTagsByValue<RestUser>(TagType.UserMention, _tags); | |||||
public override IReadOnlyCollection<RestUser> MentionedUsers => _userMentions; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<ITag> Tags => _tags; | public override IReadOnlyCollection<ITag> Tags => _tags; | ||||
@@ -67,6 +71,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
_isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); | _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); | ||||
} | } | ||||
if (model.RoleMentions.IsSpecified) | |||||
_roleMentionIds = model.RoleMentions.Value.ToImmutableArray(); | |||||
if (model.Attachments.IsSpecified) | if (model.Attachments.IsSpecified) | ||||
{ | { | ||||
@@ -96,20 +102,19 @@ namespace Discord.Rest | |||||
_embeds = ImmutableArray.Create<Embed>(); | _embeds = ImmutableArray.Create<Embed>(); | ||||
} | } | ||||
ImmutableArray<IUser> mentions = ImmutableArray.Create<IUser>(); | |||||
if (model.UserMentions.IsSpecified) | if (model.UserMentions.IsSpecified) | ||||
{ | { | ||||
var value = model.UserMentions.Value; | var value = model.UserMentions.Value; | ||||
if (value.Length > 0) | if (value.Length > 0) | ||||
{ | { | ||||
var newMentions = ImmutableArray.CreateBuilder<IUser>(value.Length); | |||||
var newMentions = ImmutableArray.CreateBuilder<RestUser>(value.Length); | |||||
for (int i = 0; i < value.Length; i++) | for (int i = 0; i < value.Length; i++) | ||||
{ | { | ||||
var val = value[i]; | var val = value[i]; | ||||
if (val.Object != null) | if (val.Object != null) | ||||
newMentions.Add(RestUser.Create(Discord, val.Object)); | newMentions.Add(RestUser.Create(Discord, val.Object)); | ||||
} | } | ||||
mentions = newMentions.ToImmutable(); | |||||
_userMentions = newMentions.ToImmutable(); | |||||
} | } | ||||
} | } | ||||
@@ -118,7 +123,7 @@ namespace Discord.Rest | |||||
var text = model.Content.Value; | var text = model.Content.Value; | ||||
var guildId = (Channel as IGuildChannel)?.GuildId; | var guildId = (Channel as IGuildChannel)?.GuildId; | ||||
var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; | var guild = guildId != null ? (Discord as IDiscordClient).GetGuildAsync(guildId.Value, CacheMode.CacheOnly).Result : null; | ||||
_tags = MessageHelper.ParseTags(text, null, guild, mentions); | |||||
_tags = MessageHelper.ParseTags(text, null, guild, _userMentions); | |||||
model.Content = text; | model.Content = text; | ||||
} | } | ||||
} | } | ||||
@@ -46,6 +46,8 @@ namespace Discord.WebSocket | |||||
public virtual bool IsSuppressed => false; | public virtual bool IsSuppressed => false; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public virtual DateTimeOffset? EditedTimestamp => null; | public virtual DateTimeOffset? EditedTimestamp => null; | ||||
/// <inheritdoc /> | |||||
public virtual bool MentionedEveryone => false; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public MessageActivity Activity { get; private set; } | public MessageActivity Activity { get; private set; } | ||||
@@ -20,7 +20,9 @@ namespace Discord.WebSocket | |||||
private ImmutableArray<Attachment> _attachments = ImmutableArray.Create<Attachment>(); | private ImmutableArray<Attachment> _attachments = ImmutableArray.Create<Attachment>(); | ||||
private ImmutableArray<Embed> _embeds = ImmutableArray.Create<Embed>(); | private ImmutableArray<Embed> _embeds = ImmutableArray.Create<Embed>(); | ||||
private ImmutableArray<ITag> _tags = ImmutableArray.Create<ITag>(); | private ImmutableArray<ITag> _tags = ImmutableArray.Create<ITag>(); | ||||
private ImmutableArray<SocketRole> _roleMentions = ImmutableArray.Create<SocketRole>(); | |||||
private ImmutableArray<SocketUser> _userMentions = ImmutableArray.Create<SocketUser>(); | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool IsTTS => _isTTS; | public override bool IsTTS => _isTTS; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -30,6 +32,8 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); | public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool MentionedEveryone => _isMentioningEveryone; | |||||
/// <inheritdoc /> | |||||
public override IReadOnlyCollection<Attachment> Attachments => _attachments; | public override IReadOnlyCollection<Attachment> Attachments => _attachments; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<Embed> Embeds => _embeds; | public override IReadOnlyCollection<Embed> Embeds => _embeds; | ||||
@@ -38,9 +42,9 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags); | public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _tags); | |||||
public override IReadOnlyCollection<SocketRole> MentionedRoles => _roleMentions; | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override IReadOnlyCollection<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags); | |||||
public override IReadOnlyCollection<SocketUser> MentionedUsers => _userMentions; | |||||
internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source) | internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source) | ||||
: base(discord, id, channel, author, source) | : base(discord, id, channel, author, source) | ||||
@@ -57,6 +61,8 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
base.Update(state, model); | base.Update(state, model); | ||||
SocketGuild guild = (Channel as SocketGuildChannel)?.Guild; | |||||
if (model.IsTextToSpeech.IsSpecified) | if (model.IsTextToSpeech.IsSpecified) | ||||
_isTTS = model.IsTextToSpeech.Value; | _isTTS = model.IsTextToSpeech.Value; | ||||
if (model.Pinned.IsSpecified) | if (model.Pinned.IsSpecified) | ||||
@@ -69,6 +75,8 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
_isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); | _isSuppressed = model.Flags.Value.HasFlag(API.MessageFlags.Suppressed); | ||||
} | } | ||||
if (model.RoleMentions.IsSpecified) | |||||
_roleMentions = model.RoleMentions.Value.Select(x => guild.GetRole(x)).ToImmutableArray(); | |||||
if (model.Attachments.IsSpecified) | if (model.Attachments.IsSpecified) | ||||
{ | { | ||||
@@ -98,28 +106,29 @@ namespace Discord.WebSocket | |||||
_embeds = ImmutableArray.Create<Embed>(); | _embeds = ImmutableArray.Create<Embed>(); | ||||
} | } | ||||
IReadOnlyCollection<IUser> mentions = ImmutableArray.Create<SocketUnknownUser>(); //Is passed to ParseTags to get real mention collection | |||||
if (model.UserMentions.IsSpecified) | if (model.UserMentions.IsSpecified) | ||||
{ | { | ||||
var value = model.UserMentions.Value; | var value = model.UserMentions.Value; | ||||
if (value.Length > 0) | if (value.Length > 0) | ||||
{ | { | ||||
var newMentions = ImmutableArray.CreateBuilder<SocketUnknownUser>(value.Length); | |||||
var newMentions = ImmutableArray.CreateBuilder<SocketUser>(value.Length); | |||||
for (int i = 0; i < value.Length; i++) | for (int i = 0; i < value.Length; i++) | ||||
{ | { | ||||
var val = value[i]; | var val = value[i]; | ||||
if (val.Object != null) | |||||
var guildUser = guild.GetUser(val.Id); | |||||
if (guildUser != null) | |||||
newMentions.Add(guildUser); | |||||
else if (val.Object != null) | |||||
newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object)); | newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object)); | ||||
} | } | ||||
mentions = newMentions.ToImmutable(); | |||||
_userMentions = newMentions.ToImmutable(); | |||||
} | } | ||||
} | } | ||||
if (model.Content.IsSpecified) | if (model.Content.IsSpecified) | ||||
{ | { | ||||
var text = model.Content.Value; | var text = model.Content.Value; | ||||
var guild = (Channel as SocketGuildChannel)?.Guild; | |||||
_tags = MessageHelper.ParseTags(text, Channel, guild, mentions); | |||||
_tags = MessageHelper.ParseTags(text, Channel, guild, _userMentions); | |||||
model.Content = text; | model.Content = text; | ||||
} | } | ||||
} | } | ||||