Skip to content

Commit

Permalink
[Feature] Add MessageCallData (discord-net#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Jun 14, 2024
1 parent 35b102a commit 21195a8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
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 @@ -272,6 +275,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 @@ -299,6 +302,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

0 comments on commit 21195a8

Please sign in to comment.