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

Implement basic support for GUILD_MEDIA channels. #109

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
using System;
using System.Collections.Generic;

namespace Disqord;

/// <summary>
/// Represents a guild forum channel.
/// </summary>
public interface IForumChannel : IThreadParentChannel, ITopicChannel, ISlowmodeChannel
{
/// <summary>
/// Gets the ID of the last thread created in this channel.
/// </summary>
Snowflake? LastThreadId { get; }

/// <summary>
/// Gets the available tags that can be applied to threads in this channel.
/// </summary>
IReadOnlyList<IForumTag> Tags { get; }

/// <summary>
/// Gets the emoji that can be reacted with by default to threads in this channel.
/// </summary>
IEmoji? DefaultReactionEmoji { get; }

/// <summary>
/// Gets the default slowmode applied to threads upon their creation in this channel.
/// </summary>
TimeSpan DefaultThreadSlowmode { get; }

/// <summary>
/// Gets the default sort order of posts in this channel.
/// </summary>
ForumSortOrder? DefaultSortOrder { get; }

/// <summary>
/// Gets the default layout of posts in this channel.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Disqord;

/// <summary>
/// Represents a tag that can be applied to threads in a forum channel.
/// Represents a tag that can be applied to threads in a forum or media channel.
/// </summary>
public interface IForumTag : IIdentifiableEntity, INamableEntity, IJsonUpdatable<ForumTagJsonModel>
public interface IChannelTag : IIdentifiableEntity, INamableEntity, IJsonUpdatable<ChannelTagJsonModel>
{
/// <summary>
/// Gets whether this tag can only be applied to threads
Expand Down
35 changes: 35 additions & 0 deletions src/Disqord.Core/Entities/Core/Channels/Guild/IMediaChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;

namespace Disqord;

/// <summary>
/// Represents a guild media channel.
/// </summary>
public interface IMediaChannel : IThreadParentChannel, ITopicChannel, ISlowmodeChannel
{
/// <summary>
/// Gets the ID of the last thread created in this channel.
/// </summary>
Snowflake? LastThreadId { get; }

/// <summary>
/// Gets the available tags that can be applied to threads in this channel.
/// </summary>
IReadOnlyList<IChannelTag> Tags { get; }

/// <summary>
/// Gets the emoji that can be reacted with by default to threads in this channel.
/// </summary>
IEmoji? DefaultReactionEmoji { get; }

/// <summary>
/// Gets the default slowmode applied to threads upon their creation in this channel.
/// </summary>
TimeSpan DefaultThreadSlowmode { get; }

/// <summary>
/// Gets the default sort order of posts in this channel.
/// </summary>
ForumSortOrder? DefaultSortOrder { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.ComponentModel;

namespace Disqord;

[EditorBrowsable(EditorBrowsableState.Never)]
public static class LocalChannelTagExtensions
{
public static TChannelTag WithId<TChannelTag>(this TChannelTag channelTag, Snowflake id)
where TChannelTag : LocalChannelTag
{
channelTag.Id = id;
return channelTag;
}

public static TChannelTag WithName<TChannelTag>(this TChannelTag channelTag, string name)
where TChannelTag : LocalChannelTag
{
channelTag.Name = name;
return channelTag;
}

public static TChannelTag WithIsModerated<TChannelTag>(this TChannelTag channelTag, bool isModerated = true)
where TChannelTag : LocalChannelTag
{
channelTag.IsModerated = isModerated;
return channelTag;
}

public static TChannelTag WithEmoji<TChannelTag>(this TChannelTag channelTag, LocalEmoji emoji)
where TChannelTag : LocalChannelTag
{
channelTag.Emoji = emoji;
return channelTag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
namespace Disqord;

/// <summary>
/// Represents a local forum tag to be created within a forum channel.
/// Represents a local channel tag to be created within a forum or media channel.
/// </summary>
/// <remarks>
/// Note that when updating a forum channel's tags,
/// Note that when updating a channel's tags,
/// you must provide the previous tags with their original values.
/// You can use <see cref="CreateFrom"/> for that purpose.
/// </remarks>
public class LocalForumTag : ILocalConstruct<LocalForumTag>, IJsonConvertible<ForumTagJsonModel>
public class LocalChannelTag : ILocalConstruct<LocalChannelTag>, IJsonConvertible<ChannelTagJsonModel>
{
/// <summary>
/// Gets or sets the ID of this tag.
Expand Down Expand Up @@ -44,16 +44,16 @@ public class LocalForumTag : ILocalConstruct<LocalForumTag>, IJsonConvertible<Fo
public Optional<LocalEmoji> Emoji { get; set; }

/// <summary>
/// Instantiates a new <see cref="LocalForumTag"/>.
/// Instantiates a new <see cref="LocalChannelTag"/>.
/// </summary>
public LocalForumTag()
public LocalChannelTag()
{ }

/// <summary>
/// Instantiates a new <see cref="LocalForumTag"/> with the properties copied from another instance.
/// Instantiates a new <see cref="LocalChannelTag"/> with the properties copied from another instance.
/// </summary>
/// <param name="other"> The other instance to copy properties from. </param>
protected LocalForumTag(LocalForumTag other)
protected LocalChannelTag(LocalChannelTag other)
{
Id = other.Id;
Name = other.Name;
Expand All @@ -62,17 +62,17 @@ protected LocalForumTag(LocalForumTag other)
}

/// <inheritdoc/>
public virtual LocalForumTag Clone()
public virtual LocalChannelTag Clone()
{
return new(this);
}

/// <inheritdoc/>
public ForumTagJsonModel ToModel()
public ChannelTagJsonModel ToModel()
{
OptionalGuard.HasValue(Name);

var model = new ForumTagJsonModel
var model = new ChannelTagJsonModel
{
Id = Id,
Name = Name.Value,
Expand Down Expand Up @@ -101,15 +101,15 @@ public ForumTagJsonModel ToModel()
}

/// <summary>
/// Converts the specified forum tag to a <see cref="LocalForumTag"/>.
/// Converts the specified channel tag to a <see cref="LocalChannelTag"/>.
/// </summary>
/// <param name="tag"> The forum tag to convert. </param>
/// <param name="tag"> The channel tag to convert. </param>
/// <returns>
/// The output <see cref="LocalForumTag"/>.
/// The output <see cref="LocalChannelTag"/>.
/// </returns>
public static LocalForumTag CreateFrom(IForumTag tag)
public static LocalChannelTag CreateFrom(IChannelTag tag)
{
return new LocalForumTag
return new LocalChannelTag
{
Id = tag.Id,
Name = tag.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public override string ToString()
case ChannelType.Stage:
case ChannelType.Directory:
case ChannelType.Forum:
case ChannelType.Media:
return TransientGuildChannel.Create(client, model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ protected TransientGuildChannel(IClient client, ChannelJsonModel model)

case ChannelType.Forum:
return new TransientForumChannel(client, model);

case ChannelType.Media:
return new TransientForumChannel(client, model);
}

return new TransientUnknownGuildChannel(client, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Disqord;

/// <inheritdoc cref="IForumTag"/>
public class TransientForumTag : TransientEntity<ForumTagJsonModel>, IForumTag
/// <inheritdoc cref="IChannelTag"/>
public class TransientChannelTag : TransientEntity<ChannelTagJsonModel>, IChannelTag
{
/// <inheritdoc/>
public Snowflake Id => Model.Id.Value;
Expand Down Expand Up @@ -32,7 +32,7 @@ public IEmoji Emoji

private IEmoji? _emoji;

public TransientForumTag(ForumTagJsonModel model)
public TransientChannelTag(ChannelTagJsonModel model)
: base(model)
{ }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Disqord.Models;
using Qommon;

namespace Disqord;

/// <inheritdoc cref="IForumChannel"/>
public class TransientForumChannel : TransientMediaChannel, IForumChannel
{
/// <inheritdoc/>
public ForumLayout DefaultLayout => Model.DefaultForumLayout.GetValueOrDefault();

public TransientForumChannel(IClient client, ChannelJsonModel model)
: base(client, model)
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Disqord;

/// <inheritdoc cref="IForumChannel"/>
public class TransientForumChannel : TransientCategorizableGuildChannel, IForumChannel
/// <inheritdoc cref="IMediaChannel"/>
public class TransientMediaChannel : TransientCategorizableGuildChannel, IMediaChannel
{
/// <inheritdoc/>
public string Topic => Model.Topic.Value;
Expand All @@ -25,20 +25,20 @@ public class TransientForumChannel : TransientCategorizableGuildChannel, IForumC
public Snowflake? LastThreadId => Model.LastMessageId.GetValueOrDefault();

/// <inheritdoc/>
public IReadOnlyList<IForumTag> Tags
public IReadOnlyList<IChannelTag> Tags
{
get
{
if (!Model.AvailableTags.HasValue)
return ReadOnlyList<IForumTag>.Empty;
return ReadOnlyList<IChannelTag>.Empty;

if (_availableTags != null)
return _availableTags;

return _availableTags = Model.AvailableTags.Value.ToReadOnlyList(model => new TransientForumTag(model));
return _availableTags = Model.AvailableTags.Value.ToReadOnlyList(model => new TransientChannelTag(model));
}
}
private IReadOnlyList<IForumTag>? _availableTags;
private IReadOnlyList<IChannelTag>? _availableTags;

/// <inheritdoc/>
public IEmoji? DefaultReactionEmoji
Expand Down Expand Up @@ -72,10 +72,7 @@ public IEmoji? DefaultReactionEmoji
/// <inheritdoc/>
public ForumSortOrder? DefaultSortOrder => Model.DefaultSortOrder.GetValueOrDefault();

/// <inheritdoc/>
public ForumLayout DefaultLayout => Model.DefaultForumLayout.GetValueOrDefault();

public TransientForumChannel(IClient client, ChannelJsonModel model)
public TransientMediaChannel(IClient client, ChannelJsonModel model)
: base(client, model)
{ }
}
6 changes: 4 additions & 2 deletions src/Disqord.Core/Enums/ChannelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public enum ChannelType : byte

Directory = 14,

Forum = 15
}
Forum = 15,

Media = 16
}
7 changes: 6 additions & 1 deletion src/Disqord.Core/Enums/GuildChannelFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ public enum GuildChannelFlags
/// <summary>
/// The forum channel requires a tag to be specified for threads created in it.
/// </summary>
RequiresTag = 1 << 4
RequiresTag = 1 << 4,

/// <summary>
/// The media channel hides the embedded media download options for media in the threads created in it.
/// </summary>
HideMediaDownloadOptions = 1 << 15
}
2 changes: 1 addition & 1 deletion src/Disqord.Core/Models/ChannelJsonModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class ChannelJsonModel : JsonModel
public Optional<GuildChannelFlags> Flags;

[JsonProperty("available_tags")]
public Optional<ForumTagJsonModel[]> AvailableTags;
public Optional<ChannelTagJsonModel[]> AvailableTags;

[JsonProperty("applied_tags")]
public Optional<Snowflake[]> AppliedTags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Disqord.Models;

public class ForumTagJsonModel : JsonModel
public class ChannelTagJsonModel : JsonModel
{
[JsonProperty("id")]
public Optional<Snowflake> Id;
Expand Down
Loading
Loading