[Feature] Add MessageCallData (#2934)

This commit is contained in:
Mihail Gribkov
2024-06-14 11:23:34 +03:00
committed by GitHub
parent 35b102a7c0
commit 21195a8a93
6 changed files with 58 additions and 0 deletions

View File

@@ -226,6 +226,11 @@ namespace Discord
/// </returns> /// </returns>
MessageRoleSubscriptionData RoleSubscriptionData { get; } MessageRoleSubscriptionData RoleSubscriptionData { get; }
/// <summary>
/// Gets the call data of the message.
/// </summary>
MessageCallData? CallData { get; }
/// <summary> /// <summary>
/// Adds a reaction to this message. /// Adds a reaction to this message.
/// </summary> /// </summary>

View File

@@ -0,0 +1,25 @@
using System;
namespace Discord;
/// <summary>
/// Represents the call data of a message.
/// </summary>
public readonly struct MessageCallData
{
/// <summary>
/// Gets the participants of the call.
/// </summary>
public readonly ulong[] Participants;
/// <summary>
/// Gets the timestamp when the call ended. This is <see langword="null"/> if the call is still ongoing.
/// </summary>
public readonly DateTimeOffset? EndedTimestamp;
internal MessageCallData(ulong[] participants, DateTimeOffset? endedTimestamp)
{
Participants = participants;
EndedTimestamp = endedTimestamp;
}
}

View File

@@ -104,4 +104,7 @@ internal class Message
[JsonProperty("poll")] [JsonProperty("poll")]
public Optional<Poll> Poll { get; set; } public Optional<Poll> Poll { get; set; }
[JsonProperty("call")]
public Optional<MessageCallData> Call { get; set; }
} }

View File

@@ -0,0 +1,13 @@
using Newtonsoft.Json;
using System;
namespace Discord.API;
internal class MessageCallData
{
[JsonProperty("ended_timestamp")]
public Optional<DateTimeOffset> EndedTimestamp { get; set; }
[JsonProperty("participants")]
public ulong[] Participants { get; set; }
}

View File

@@ -93,6 +93,9 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; } public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
/// <inheritdoc />
public MessageCallData? CallData { get; private set; }
/// <inheritdoc cref="IMessage.Components"/> /// <inheritdoc cref="IMessage.Components"/>
public IReadOnlyCollection<ActionRowComponent> Components { get; private set; } public IReadOnlyCollection<ActionRowComponent> Components { get; private set; }
/// <summary> /// <summary>
@@ -272,6 +275,9 @@ namespace Discord.Rest
if (model.Thread.IsSpecified) if (model.Thread.IsSpecified)
Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value); Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value);
if (model.Call.IsSpecified)
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task UpdateAsync(RequestOptions options = null) public async Task UpdateAsync(RequestOptions options = null)

View File

@@ -87,6 +87,9 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
IThreadChannel IMessage.Thread => Thread; IThreadChannel IMessage.Thread => Thread;
/// <inheritdoc />
public MessageCallData? CallData { get; private set; }
/// <summary> /// <summary>
/// Returns all attachments included in this message. /// Returns all attachments included in this message.
/// </summary> /// </summary>
@@ -299,6 +302,9 @@ namespace Discord.WebSocket
SocketGuild guild = (Channel as SocketGuildChannel)?.Guild; SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;
Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel; Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel;
} }
if (model.Call.IsSpecified)
CallData = new MessageCallData(model.Call.Value.Participants, model.Call.Value.EndedTimestamp.ToNullable());
} }
/// <inheritdoc /> /// <inheritdoc />