Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add MessageCallData #2934

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Discord.Net.Core/Entities/Messages/IMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ public interface IMessage : ISnowflakeEntity, IDeletable
/// </returns>
MessageRoleSubscriptionData RoleSubscriptionData { get; }

/// <summary>
/// Gets the call data of the message.
/// </summary>
MessageCallData? CallData { get; }

/// <summary>
/// Adds a reaction to this message.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions src/Discord.Net.Core/Entities/Messages/MessageCallData.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions src/Discord.Net.Rest/API/Common/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ internal class Message

[JsonProperty("poll")]
public Optional<Poll> Poll { get; set; }

[JsonProperty("call")]
public Optional<MessageCallData> Call { get; set; }
}
13 changes: 13 additions & 0 deletions src/Discord.Net.Rest/API/Common/MessageCallData.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
6 changes: 6 additions & 0 deletions src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public abstract class RestMessage : RestEntity<ulong>, IMessage, IUpdateable
/// <inheritdoc />
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }

/// <inheritdoc />
public MessageCallData? CallData { get; private set; }

/// <inheritdoc cref="IMessage.Components"/>
public IReadOnlyCollection<ActionRowComponent> Components { get; private set; }
/// <summary>
Expand Down Expand Up @@ -271,6 +274,9 @@ internal virtual void Update(Model model)

if (model.Thread.IsSpecified)
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 />
public async Task UpdateAsync(RequestOptions options = null)
Expand Down
6 changes: 6 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public abstract class SocketMessage : SocketEntity<ulong>, IMessage
/// <inheritdoc />
IThreadChannel IMessage.Thread => Thread;

/// <inheritdoc />
public MessageCallData? CallData { get; private set; }

/// <summary>
/// Returns all attachments included in this message.
/// </summary>
Expand Down Expand Up @@ -298,6 +301,9 @@ internal virtual void Update(ClientState state, Model model)
SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;
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 />
Expand Down