From c4804ce88bd4230c0ee3c57297baa9bf0ac957ee Mon Sep 17 00:00:00 2001 From: Baptiste Parmantier Date: Sat, 13 Jul 2024 16:06:41 +0200 Subject: [PATCH] feat(api): implement stage voice channels --- .../server/channels/server_stage_channel.dart | 69 +++++++++++++++++++ .../server_forum_channel_factory.dart | 1 + .../server_stage_channel_factory.dart | 36 ++++++++++ .../channels/server_text_channel_factory.dart | 3 +- .../serializers/channel_serializer.dart | 2 + 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 lib/api/server/channels/server_stage_channel.dart create mode 100644 lib/infrastructure/internals/marshaller/factories/channels/server_stage_channel_factory.dart diff --git a/lib/api/server/channels/server_stage_channel.dart b/lib/api/server/channels/server_stage_channel.dart new file mode 100644 index 000000000..c1dae4081 --- /dev/null +++ b/lib/api/server/channels/server_stage_channel.dart @@ -0,0 +1,69 @@ +import 'package:mineral/api/common/channel_methods.dart'; +import 'package:mineral/api/common/channel_permission_overwrite.dart'; +import 'package:mineral/api/common/channel_properties.dart'; +import 'package:mineral/api/common/embed/message_embed.dart'; +import 'package:mineral/api/common/managers/message_manager.dart'; +import 'package:mineral/api/common/polls/poll.dart'; +import 'package:mineral/api/common/snowflake.dart'; +import 'package:mineral/api/common/types/channel_type.dart'; +import 'package:mineral/api/server/channels/server_category_channel.dart'; +import 'package:mineral/api/server/channels/server_channel.dart'; +import 'package:mineral/api/server/server_message.dart'; + +final class ServerStageChannel extends ServerChannel { + final ChannelProperties _properties; + final ChannelMethods _methods; + + final MessageManager messages = MessageManager(); + + @override + Snowflake get id => _properties.id; + + @override + ChannelType get type => _properties.type; + + @override + String get name => _properties.name!; + + @override + int get position => _properties.position!; + + @override + List get permissions => _properties.permissions!; + + String? get description => _properties.description; + + late final ServerCategoryChannel? category; + + @override + Snowflake get guildId => _properties.guildId!; + + ServerStageChannel(this._properties) : _methods = ChannelMethods(_properties.id); + + Future setName(String name, {String? reason}) => _methods.setName(name, reason); + + Future setDescription(String description, {String? reason}) => + _methods.setDescription(description, reason); + + Future setCategory(String categoryId, {String? reason}) => + _methods.setCategory(categoryId, reason); + + Future setPosition(int position, {String? reason}) => + _methods.setPosition(position, reason); + + Future setNsfw(bool nsfw, {String? reason}) => _methods.setNsfw(nsfw, reason); + + Future setRateLimitPerUser(int rateLimitPerUser, {String? reason}) => + _methods.setRateLimitPerUser(rateLimitPerUser, reason); + + Future setDefaultAutoArchiveDuration(int defaultAutoArchiveDuration, {String? reason}) => + _methods.setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason); + + Future setDefaultThreadRateLimitPerUser(int value, {String? reason}) => + _methods.setDefaultThreadRateLimitPerUser(value, reason); + + Future send({String? content, List? embeds, Poll? poll}) => + _methods.send(guildId: _properties.guildId, content: content, embeds: embeds, poll: poll); + + Future delete({String? reason}) => _methods.delete(reason); +} diff --git a/lib/infrastructure/internals/marshaller/factories/channels/server_forum_channel_factory.dart b/lib/infrastructure/internals/marshaller/factories/channels/server_forum_channel_factory.dart index f3c3b318a..1abdf9a3f 100644 --- a/lib/infrastructure/internals/marshaller/factories/channels/server_forum_channel_factory.dart +++ b/lib/infrastructure/internals/marshaller/factories/channels/server_forum_channel_factory.dart @@ -41,6 +41,7 @@ final class ServerForumChannelFactory implements ChannelFactoryContract { + @override + ChannelType get type => ChannelType.guildStageVoice; + + @override + Future make( + MarshallerContract marshaller, String guildId, Map json) async { + final properties = await ChannelProperties.make(marshaller, json); + + return ServerStageChannel(properties); + } + + @override + Future> deserialize( + MarshallerContract marshaller, ServerStageChannel channel) async { + final permissions = await Future.wait(channel.permissions.map( + (element) async => marshaller.serializers.channelPermissionOverwrite.deserialize(element))); + + return { + 'id': channel.id.value, + 'type': channel.type.value, + 'name': channel.name, + 'position': channel.position, + 'guild_id': channel.guildId, + 'topic': channel.description, + 'permission_overwrites': permissions, + 'parent_id': channel.category?.id, + }; + } +} diff --git a/lib/infrastructure/internals/marshaller/factories/channels/server_text_channel_factory.dart b/lib/infrastructure/internals/marshaller/factories/channels/server_text_channel_factory.dart index 764a26582..6c93995c7 100644 --- a/lib/infrastructure/internals/marshaller/factories/channels/server_text_channel_factory.dart +++ b/lib/infrastructure/internals/marshaller/factories/channels/server_text_channel_factory.dart @@ -29,7 +29,8 @@ final class ServerTextChannelFactory implements ChannelFactoryContract implements SerializerContract< ServerCategoryChannelFactory(), ServerAnnouncementChannelFactory(), ServerForumChannelFactory(), + ServerStageChannelFactory(), PrivateChannelFactory(), ];