Skip to content

Commit da1e01a

Browse files
committed
Added media channel, restructure forum channel, refactor forum tag -> channel tag
1 parent 2f2d8b0 commit da1e01a

16 files changed

+168
-126
lines changed

src/Disqord.Core/Entities/Core/Channels/Guild/Forums/IForumChannel.cs

-28
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
41
namespace Disqord;
52

63
/// <summary>
74
/// Represents a guild forum channel.
85
/// </summary>
96
public interface IForumChannel : IThreadParentChannel, ITopicChannel, ISlowmodeChannel
107
{
11-
/// <summary>
12-
/// Gets the ID of the last thread created in this channel.
13-
/// </summary>
14-
Snowflake? LastThreadId { get; }
15-
16-
/// <summary>
17-
/// Gets the available tags that can be applied to threads in this channel.
18-
/// </summary>
19-
IReadOnlyList<IForumTag> Tags { get; }
20-
21-
/// <summary>
22-
/// Gets the emoji that can be reacted with by default to threads in this channel.
23-
/// </summary>
24-
IEmoji? DefaultReactionEmoji { get; }
25-
26-
/// <summary>
27-
/// Gets the default slowmode applied to threads upon their creation in this channel.
28-
/// </summary>
29-
TimeSpan DefaultThreadSlowmode { get; }
30-
31-
/// <summary>
32-
/// Gets the default sort order of posts in this channel.
33-
/// </summary>
34-
ForumSortOrder? DefaultSortOrder { get; }
35-
368
/// <summary>
379
/// Gets the default layout of posts in this channel.
3810
/// </summary>

src/Disqord.Core/Entities/Core/Channels/Guild/Forums/IForumTag.cs src/Disqord.Core/Entities/Core/Channels/Guild/IChannelTag.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Disqord;
44

55
/// <summary>
6-
/// Represents a tag that can be applied to threads in a forum channel.
6+
/// Represents a tag that can be applied to threads in a forum or media channel.
77
/// </summary>
8-
public interface IForumTag : IIdentifiableEntity, INamableEntity, IJsonUpdatable<ForumTagJsonModel>
8+
public interface IChannelTag : IIdentifiableEntity, INamableEntity, IJsonUpdatable<ChannelTagJsonModel>
99
{
1010
/// <summary>
1111
/// Gets whether this tag can only be applied to threads
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Disqord;
5+
6+
/// <summary>
7+
/// Represents a guild media channel.
8+
/// </summary>
9+
public interface IMediaChannel : IThreadParentChannel, ITopicChannel, ISlowmodeChannel
10+
{
11+
/// <summary>
12+
/// Gets the ID of the last thread created in this channel.
13+
/// </summary>
14+
Snowflake? LastThreadId { get; }
15+
16+
/// <summary>
17+
/// Gets the available tags that can be applied to threads in this channel.
18+
/// </summary>
19+
IReadOnlyList<IChannelTag> Tags { get; }
20+
21+
/// <summary>
22+
/// Gets the emoji that can be reacted with by default to threads in this channel.
23+
/// </summary>
24+
IEmoji? DefaultReactionEmoji { get; }
25+
26+
/// <summary>
27+
/// Gets the default slowmode applied to threads upon their creation in this channel.
28+
/// </summary>
29+
TimeSpan DefaultThreadSlowmode { get; }
30+
31+
/// <summary>
32+
/// Gets the default sort order of posts in this channel.
33+
/// </summary>
34+
ForumSortOrder? DefaultSortOrder { get; }
35+
}

src/Disqord.Core/Entities/Local/Guild/Forums/LocalForumTag.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Disqord;
1111
/// you must provide the previous tags with their original values.
1212
/// You can use <see cref="CreateFrom"/> for that purpose.
1313
/// </remarks>
14-
public class LocalForumTag : ILocalConstruct<LocalForumTag>, IJsonConvertible<ForumTagJsonModel>
14+
public class LocalForumTag : ILocalConstruct<LocalForumTag>, IJsonConvertible<ChannelTagJsonModel>
1515
{
1616
/// <summary>
1717
/// Gets or sets the ID of this tag.
@@ -68,11 +68,11 @@ public virtual LocalForumTag Clone()
6868
}
6969

7070
/// <inheritdoc/>
71-
public ForumTagJsonModel ToModel()
71+
public ChannelTagJsonModel ToModel()
7272
{
7373
OptionalGuard.HasValue(Name);
7474

75-
var model = new ForumTagJsonModel
75+
var model = new ChannelTagJsonModel
7676
{
7777
Id = Id,
7878
Name = Name.Value,
@@ -107,7 +107,7 @@ public ForumTagJsonModel ToModel()
107107
/// <returns>
108108
/// The output <see cref="LocalForumTag"/>.
109109
/// </returns>
110-
public static LocalForumTag CreateFrom(IForumTag tag)
110+
public static LocalForumTag CreateFrom(IChannelTag tag)
111111
{
112112
return new LocalForumTag
113113
{

src/Disqord.Core/Entities/Transient/Channels/Guild/Common/TransientGuildChannel.cs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ protected TransientGuildChannel(IClient client, ChannelJsonModel model)
6060
return new TransientStageChannel(client, model);
6161

6262
case ChannelType.Forum:
63+
return new TransientForumChannel(client, model);
64+
6365
case ChannelType.Media:
6466
return new TransientForumChannel(client, model);
6567
}

src/Disqord.Core/Entities/Transient/Channels/Guild/Forums/TransientForumTag.cs src/Disqord.Core/Entities/Transient/Channels/Guild/TransientChannelTag.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Disqord;
44

5-
/// <inheritdoc cref="IForumTag"/>
6-
public class TransientForumTag : TransientEntity<ForumTagJsonModel>, IForumTag
5+
/// <inheritdoc cref="IChannelTag"/>
6+
public class TransientChannelTag : TransientEntity<ChannelTagJsonModel>, IChannelTag
77
{
88
/// <inheritdoc/>
99
public Snowflake Id => Model.Id.Value;
@@ -32,7 +32,7 @@ public IEmoji Emoji
3232

3333
private IEmoji? _emoji;
3434

35-
public TransientForumTag(ForumTagJsonModel model)
35+
public TransientChannelTag(ChannelTagJsonModel model)
3636
: base(model)
3737
{ }
3838
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Disqord.Models;
2+
using Qommon;
3+
4+
namespace Disqord;
5+
6+
/// <inheritdoc cref="IForumChannel"/>
7+
public class TransientForumChannel : TransientMediaChannel, IForumChannel
8+
{
9+
/// <inheritdoc/>
10+
public ForumLayout DefaultLayout => Model.DefaultForumLayout.GetValueOrDefault();
11+
12+
public TransientForumChannel(IClient client, ChannelJsonModel model)
13+
: base(client, model)
14+
{ }
15+
}

src/Disqord.Core/Entities/Transient/Channels/Guild/Forums/TransientForumChannel.cs src/Disqord.Core/Entities/Transient/Channels/Guild/TransientMediaChannel.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace Disqord;
88

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

2727
/// <inheritdoc/>
28-
public IReadOnlyList<IForumTag> Tags
28+
public IReadOnlyList<IChannelTag> Tags
2929
{
3030
get
3131
{
3232
if (!Model.AvailableTags.HasValue)
33-
return ReadOnlyList<IForumTag>.Empty;
33+
return ReadOnlyList<IChannelTag>.Empty;
3434

3535
if (_availableTags != null)
3636
return _availableTags;
3737

38-
return _availableTags = Model.AvailableTags.Value.ToReadOnlyList(model => new TransientForumTag(model));
38+
return _availableTags = Model.AvailableTags.Value.ToReadOnlyList(model => new TransientChannelTag(model));
3939
}
4040
}
41-
private IReadOnlyList<IForumTag>? _availableTags;
41+
private IReadOnlyList<IChannelTag>? _availableTags;
4242

4343
/// <inheritdoc/>
4444
public IEmoji? DefaultReactionEmoji
@@ -72,10 +72,7 @@ public IEmoji? DefaultReactionEmoji
7272
/// <inheritdoc/>
7373
public ForumSortOrder? DefaultSortOrder => Model.DefaultSortOrder.GetValueOrDefault();
7474

75-
/// <inheritdoc/>
76-
public ForumLayout DefaultLayout => Model.DefaultForumLayout.GetValueOrDefault();
77-
78-
public TransientForumChannel(IClient client, ChannelJsonModel model)
75+
public TransientMediaChannel(IClient client, ChannelJsonModel model)
7976
: base(client, model)
8077
{ }
8178
}

src/Disqord.Core/Models/ChannelJsonModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class ChannelJsonModel : JsonModel
9191
public Optional<GuildChannelFlags> Flags;
9292

9393
[JsonProperty("available_tags")]
94-
public Optional<ForumTagJsonModel[]> AvailableTags;
94+
public Optional<ChannelTagJsonModel[]> AvailableTags;
9595

9696
[JsonProperty("applied_tags")]
9797
public Optional<Snowflake[]> AppliedTags;

src/Disqord.Core/Models/Forum/ForumTagJsonModel.cs src/Disqord.Core/Models/ChannelTagJsonModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Disqord.Models;
55

6-
public class ForumTagJsonModel : JsonModel
6+
public class ChannelTagJsonModel : JsonModel
77
{
88
[JsonProperty("id")]
99
public Optional<Snowflake> Id;
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.ComponentModel;
42
using Disqord.Models;
53
using Qommon;
6-
using Qommon.Collections.ReadOnly;
74

85
namespace Disqord.Gateway;
96

107
/// <inheritdoc cref="IForumChannel"/>
11-
public class CachedForumChannel : CachedCategorizableGuildChannel, IForumChannel
8+
public class CachedForumChannel : CachedMediaChannel, IForumChannel
129
{
13-
/// <inheritdoc/>
14-
public string? Topic { get; private set; }
15-
16-
/// <inheritdoc/>
17-
public bool IsAgeRestricted { get; private set; }
18-
19-
/// <inheritdoc/>
20-
public TimeSpan Slowmode { get; private set; }
21-
22-
/// <inheritdoc/>
23-
public TimeSpan DefaultAutomaticArchiveDuration { get; private set; }
24-
25-
/// <inheritdoc/>
26-
public Snowflake? LastThreadId { get; private set; }
27-
28-
/// <inheritdoc/>
29-
public IEmoji? DefaultReactionEmoji { get; private set; }
30-
31-
/// <inheritdoc/>
32-
public IReadOnlyList<IForumTag> Tags { get; private set; } = ReadOnlyList<IForumTag>.Empty;
33-
34-
/// <inheritdoc/>
35-
public TimeSpan DefaultThreadSlowmode { get; private set; }
36-
37-
/// <inheritdoc/>
38-
public ForumSortOrder? DefaultSortOrder { get; private set; }
39-
4010
/// <inheritdoc/>
4111
public ForumLayout DefaultLayout { get; private set; }
4212

@@ -48,49 +18,6 @@ public CachedForumChannel(IGatewayClient client, ChannelJsonModel model)
4818
public override void Update(ChannelJsonModel model)
4919
{
5020
base.Update(model);
51-
52-
if (model.Topic.HasValue)
53-
Topic = model.Topic.Value;
54-
55-
if (model.Nsfw.HasValue)
56-
IsAgeRestricted = model.Nsfw.Value;
57-
58-
if (model.RateLimitPerUser.HasValue)
59-
Slowmode = TimeSpan.FromSeconds(model.RateLimitPerUser.Value);
60-
61-
DefaultAutomaticArchiveDuration = TimeSpan.FromMinutes(model.DefaultAutoArchiveDuration.GetValueOrDefault(1440));
62-
63-
if (model.LastMessageId.HasValue)
64-
LastThreadId = model.LastMessageId.Value;
65-
66-
if (model.DefaultReactionEmoji.HasValue)
67-
{
68-
IEmoji? defaultReactionEmoji;
69-
var defaultReactionEmojiModel = model.DefaultReactionEmoji.GetValueOrDefault();
70-
if (defaultReactionEmojiModel != null)
71-
{
72-
if (defaultReactionEmojiModel.EmojiId != null)
73-
{
74-
defaultReactionEmoji = new TransientCustomEmoji(defaultReactionEmojiModel.EmojiId.Value);
75-
}
76-
else
77-
{
78-
defaultReactionEmoji = new TransientEmoji(defaultReactionEmojiModel.EmojiName!);
79-
}
80-
}
81-
else
82-
{
83-
defaultReactionEmoji = null;
84-
}
85-
86-
DefaultReactionEmoji = defaultReactionEmoji;
87-
}
88-
89-
if (model.AvailableTags.HasValue)
90-
Tags = model.AvailableTags.Value.ToReadOnlyList(model => new TransientForumTag(model));
91-
92-
DefaultThreadSlowmode = TimeSpan.FromSeconds(model.DefaultThreadRateLimitPerUser.GetValueOrDefault(0));
93-
DefaultSortOrder = model.DefaultSortOrder.GetValueOrDefault();
9421
DefaultLayout = model.DefaultForumLayout.GetValueOrDefault();
9522
}
9623
}

0 commit comments

Comments
 (0)