Browse Source

Implement message Activity and Application model update

pull/1165/head
Chris Johnston 7 years ago
parent
commit
2d78162c4d
9 changed files with 195 additions and 0 deletions
  1. +20
    -0
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  2. +27
    -0
      src/Discord.Net.Core/Entities/Messages/MessageActivity.cs
  3. +16
    -0
      src/Discord.Net.Core/Entities/Messages/MessageActivityType.cs
  4. +37
    -0
      src/Discord.Net.Core/Entities/Messages/MessageApplication.cs
  5. +6
    -0
      src/Discord.Net.Rest/API/Common/Message.cs
  6. +17
    -0
      src/Discord.Net.Rest/API/Common/MessageActivity.cs
  7. +38
    -0
      src/Discord.Net.Rest/API/Common/MessageApplication.cs
  8. +3
    -0
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  9. +31
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs

+ 20
- 0
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -100,5 +100,25 @@ namespace Discord
/// A read-only collection of user IDs.
/// </returns>
IReadOnlyCollection<ulong> MentionedUserIds { get; }
/// <summary>
/// Returns the Activity associated with a message.
/// </summary>
/// <remarks>
/// Sent with Rich Presence-related chat embeds.
/// </remarks>
/// <returns>
/// A message's activity, if any is associated.
/// </returns>
MessageActivity Activity { get; }
/// <summary>
/// Returns the Application associated with a messsage.
/// </summary>
/// <remarks>
/// Sent with Rich-Presence-related chat embeds.
/// </remarks>
/// <returns>
/// A message's application, if any is associated.
/// </returns>
MessageApplication Application { get; }
}
}

+ 27
- 0
src/Discord.Net.Core/Entities/Messages/MessageActivity.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class MessageActivity
{
/// <summary>
/// Gets the type of activity of this message.
/// </summary>
public MessageActivityType Type { get; set; }
/// <summary>
/// Gets the party ID of this activity, if any.
/// </summary>
public string PartyId { get; set; }

private string DebuggerDisplay
=> $"{Type}{(string.IsNullOrWhiteSpace(PartyId) ? "" : $" {PartyId}")}";

public override string ToString() => DebuggerDisplay;
}
}

+ 16
- 0
src/Discord.Net.Core/Entities/Messages/MessageActivityType.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
{
public enum MessageActivityType
{
Join = 1,
Spectate = 2,
Listen = 3,
JoinRequest = 5
}
}

+ 37
- 0
src/Discord.Net.Core/Entities/Messages/MessageApplication.cs View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
{
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class MessageApplication
{
/// <summary>
/// Gets the snowflake ID of the application.
/// </summary>
public ulong Id { get; set; }
/// <summary>
/// Gets the ID of the embed's image asset.
/// </summary>
public string CoverImage { get; set; }
/// <summary>
/// Gets the application's description.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Gets the ID of the application's icon.
/// </summary>
public string Icon { get; set; }
/// <summary>
/// Gets the name of the application.
/// </summary>
public string Name { get; set; }

private string DebuggerDisplay
=> $"{Name} ({Id}): {Description}";
}
}

+ 6
- 0
src/Discord.Net.Rest/API/Common/Message.cs View File

@@ -44,5 +44,11 @@ namespace Discord.API
public Optional<bool> Pinned { get; set; }
[JsonProperty("reactions")]
public Optional<Reaction[]> Reactions { get; set; }
// sent with Rich Presence-related chat embeds
[JsonProperty("activity")]
public Optional<MessageActivity> Activity { get; set; }
// sent with Rich Presence-related chat embeds
[JsonProperty("application")]
public Optional<MessageApplication> Application { get; set; }
}
}

+ 17
- 0
src/Discord.Net.Rest/API/Common/MessageActivity.cs View File

@@ -0,0 +1,17 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord.API
{
public class MessageActivity
{
[JsonProperty("type")]
public Optional<MessageActivityType> Type { get; set; }
[JsonProperty("party_id")]
public Optional<string> PartyId { get; set; }
}
}

+ 38
- 0
src/Discord.Net.Rest/API/Common/MessageApplication.cs View File

@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord.API
{
public class MessageApplication
{
/// <summary>
/// Gets the snowflake ID of the application.
/// </summary>
[JsonProperty("id")]
public ulong Id { get; set; }
/// <summary>
/// Gets the ID of the embed's image asset.
/// </summary>
[JsonProperty("cover_image")]
public string CoverImage { get; set; }
/// <summary>
/// Gets the application's description.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }
/// <summary>
/// Gets the ID of the application's icon.
/// </summary>
[JsonProperty("icon")]
public string Icon { get; set; }
/// <summary>
/// Gets the name of the application.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
}
}

+ 3
- 0
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -55,6 +55,9 @@ namespace Discord.Rest

/// <inheritdoc />
public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks);
//todo Rest impl
public MessageActivity Activity => null;
public MessageApplication Application => null;

internal RestMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, IUser author, MessageSource source)
: base(discord, id)


+ 31
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -43,6 +43,14 @@ namespace Discord.WebSocket
public virtual bool IsPinned => false;
/// <inheritdoc />
public virtual DateTimeOffset? EditedTimestamp => null;

/// <inheritdoc />
public MessageActivity Activity { get; private set; }

/// <inheritdoc />
public MessageApplication Application { get; private set; }


/// <summary>
/// Returns all attachments included in this message.
/// </summary>
@@ -105,6 +113,29 @@ namespace Discord.WebSocket

if (model.Content.IsSpecified)
Content = model.Content.Value;

if (model.Application.IsSpecified)
{
// create a new Application from the API model
Application = new MessageApplication()
{
Id = model.Application.Value.Id,
CoverImage = model.Application.Value.CoverImage,
Description = model.Application.Value.Description,
Icon = model.Application.Value.Icon,
Name = model.Application.Value.Name
};
}

if (model.Activity.IsSpecified)
{
// create a new Activity from the API model
Activity = new MessageActivity()
{
Type = model.Activity.Value.Type.Value,
PartyId = model.Activity.Value.PartyId.Value
};
}
}

/// <inheritdoc />


Loading…
Cancel
Save