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

feat(api): implement stage voice channels #164

Merged
merged 1 commit into from
Jul 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
69 changes: 69 additions & 0 deletions lib/api/server/channels/server_stage_channel.dart
Original file line number Diff line number Diff line change
@@ -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<ServerMessage> 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<ChannelPermissionOverwrite> 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<void> setName(String name, {String? reason}) => _methods.setName(name, reason);

Future<void> setDescription(String description, {String? reason}) =>
_methods.setDescription(description, reason);

Future<void> setCategory(String categoryId, {String? reason}) =>
_methods.setCategory(categoryId, reason);

Future<void> setPosition(int position, {String? reason}) =>
_methods.setPosition(position, reason);

Future<void> setNsfw(bool nsfw, {String? reason}) => _methods.setNsfw(nsfw, reason);

Future<void> setRateLimitPerUser(int rateLimitPerUser, {String? reason}) =>
_methods.setRateLimitPerUser(rateLimitPerUser, reason);

Future<void> setDefaultAutoArchiveDuration(int defaultAutoArchiveDuration, {String? reason}) =>
_methods.setDefaultAutoArchiveDuration(defaultAutoArchiveDuration, reason);

Future<void> setDefaultThreadRateLimitPerUser(int value, {String? reason}) =>
_methods.setDefaultThreadRateLimitPerUser(value, reason);

Future<void> send({String? content, List<MessageEmbed>? embeds, Poll? poll}) =>
_methods.send(guildId: _properties.guildId, content: content, embeds: embeds, poll: poll);

Future<void> delete({String? reason}) => _methods.delete(reason);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class ServerForumChannelFactory implements ChannelFactoryContract<ServerFo
'position': channel.position,
'guild_id': channel.guildId,
'permission_overwrites': permissions,
'parent_id': channel.category?.id,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:mineral/api/common/channel_properties.dart';
import 'package:mineral/api/common/types/channel_type.dart';
import 'package:mineral/api/server/channels/server_stage_channel.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
import 'package:mineral/infrastructure/internals/marshaller/types/channel_factory.dart';

final class ServerStageChannelFactory implements ChannelFactoryContract<ServerStageChannel> {
@override
ChannelType get type => ChannelType.guildStageVoice;

@override
Future<ServerStageChannel> make(
MarshallerContract marshaller, String guildId, Map<String, dynamic> json) async {
final properties = await ChannelProperties.make(marshaller, json);

return ServerStageChannel(properties);
}

@override
Future<Map<String, dynamic>> 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,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ final class ServerTextChannelFactory implements ChannelFactoryContract<ServerTex
'position': channel.position,
'guild_id': channel.guildId,
'topic': channel.description,
'permission_overwrites': permissions
'permission_overwrites': permissions,
'parent_id': channel.category?.id,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:mineral/infrastructure/internals/marshaller/factories/channels/p
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_announcement_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_category_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_forum_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_stage_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_text_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/factories/channels/server_voice_channel_factory.dart';
import 'package:mineral/infrastructure/internals/marshaller/marshaller.dart';
Expand All @@ -19,6 +20,7 @@ final class ChannelSerializer<T extends Channel?> implements SerializerContract<
ServerCategoryChannelFactory(),
ServerAnnouncementChannelFactory(),
ServerForumChannelFactory(),
ServerStageChannelFactory(),
PrivateChannelFactory(),
];

Expand Down