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/enhance serialization #195

Merged
merged 44 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
21fd083
fix(datastore): add cache methods
LeadcodeDev Aug 16, 2024
a59e6e6
fix(datastore): rework server serializers
LeadcodeDev Aug 16, 2024
dcd4bff
feat(serialization): delete file server role, unused
PandaGuerrier Aug 16, 2024
6f1f7ad
feat(serialization): stickers
PandaGuerrier Aug 16, 2024
f586c81
feat(marshaller): rework member and user serialization
LeadcodeDev Aug 16, 2024
167bf39
feat(serialization): replace all serialize
PandaGuerrier Aug 16, 2024
9a99937
feat(serialization): replace all serialize
PandaGuerrier Aug 16, 2024
fff2e2a
feat(serialization): refractor channels factories
PandaGuerrier Aug 16, 2024
9a52f37
feat(serialization): replace all serialize
PandaGuerrier Aug 16, 2024
196bdeb
feat(serialization): replace the Snowflake to nullable
PandaGuerrier Aug 16, 2024
a84af4e
feat(serialization): replace String to Snowflake
PandaGuerrier Aug 16, 2024
0e860dc
feat(serialization): finish message serialization
PandaGuerrier Aug 16, 2024
7304304
feat(serialization): set the new serialize service
PandaGuerrier Aug 16, 2024
7a4a58c
feat(marshaller): add normalize return map
LeadcodeDev Aug 16, 2024
eb44c9b
feat(marshaller): rework member part
LeadcodeDev Aug 16, 2024
3ff8661
feat(marshaller): rework server part
LeadcodeDev Aug 16, 2024
bec0641
feat(marshaller): rework user part
LeadcodeDev Aug 16, 2024
18862a4
feat(datastore): rework message part
LeadcodeDev Aug 17, 2024
62bad8d
feat(marshaller): apply newer channel key
LeadcodeDev Aug 17, 2024
4c9cc10
feat(serialization): rework channel part
PandaGuerrier Aug 17, 2024
9202b7a
feat(serialization): change guild to server
PandaGuerrier Aug 17, 2024
964da39
feat(serialization): rework serialization uses
PandaGuerrier Aug 17, 2024
d6fc4fd
fix(serialization): fix somes littles things
PandaGuerrier Aug 17, 2024
e8ceb99
feat: restore required marshaller service
LeadcodeDev Aug 19, 2024
a2052e7
feat(marshaller): implement server subscription serializer
LeadcodeDev Aug 19, 2024
23eed28
feat(marshaller): implement newer serialization and support server an…
LeadcodeDev Aug 19, 2024
5fc6abe
feat(packets): rework channel create packet
LeadcodeDev Aug 20, 2024
424b257
feat(packets): rework channel delete packet
LeadcodeDev Aug 20, 2024
12c7abf
feat(packets): rework channel pin updates packet
LeadcodeDev Aug 20, 2024
a23b819
feat(packets): rework channel update packet
LeadcodeDev Aug 20, 2024
2cd2e62
feat(packets): rework server delete packet
LeadcodeDev Aug 20, 2024
317f37f
feat(packets): rework server emoji updates packet
LeadcodeDev Aug 20, 2024
c7fb33c
feat(packets): rework server member add packet
LeadcodeDev Aug 20, 2024
a34d8bb
feat(hmr): enhance hmr declaration
LeadcodeDev Aug 20, 2024
3ded0e7
feat(packets): rework server member chunk packet
LeadcodeDev Aug 20, 2024
9322bfc
feat(packets): rework server member remove packet
LeadcodeDev Aug 20, 2024
faab9ac
feat(packets): rework server member update packet
LeadcodeDev Aug 20, 2024
7af7da8
feat(packets): rework server role create packet
LeadcodeDev Aug 20, 2024
beaeeea
feat(packets): rework server role delete packet
LeadcodeDev Aug 21, 2024
b14af17
feat(packets): rework server role update packet
LeadcodeDev Aug 21, 2024
1e1bc96
feat(packets): rework server stickers update packet
LeadcodeDev Aug 21, 2024
c9fcf13
feat(packets): rework server update packet
LeadcodeDev Aug 21, 2024
8893cdc
feat(packets): rework presence update packet
LeadcodeDev Aug 21, 2024
4f8b7fd
feat(packets): make adjustments
LeadcodeDev Aug 21, 2024
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
18 changes: 9 additions & 9 deletions lib/api/common/channel_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ChannelProperties {
final ChannelType type;
final String? name;
final String? description;
final Snowflake? guildId;
final Snowflake? serverId;
final Snowflake? categoryId;
final int? position;
final bool nsfw;
Expand Down Expand Up @@ -48,7 +48,7 @@ final class ChannelProperties {
required this.type,
required this.name,
required this.description,
required this.guildId,
required this.serverId,
required this.categoryId,
required this.position,
required this.nsfw,
Expand Down Expand Up @@ -83,15 +83,15 @@ final class ChannelProperties {
fn: () async => Future.wait(
List.from(element['permission_overwrites'])
.map((json) async =>
marshaller.serializers.channelPermissionOverwrite.serializeRemote(json))
marshaller.serializers.channelPermissionOverwrite.serialize(json))
.toList(),
));

final recipients = await Helper.createOrNullAsync(
field: element['recipients'],
fn: () async => Future.wait(
List.from(element['recipients'])
.map((json) async => marshaller.serializers.user.serializeRemote(json))
.map((json) async => marshaller.serializers.user.serialize(json))
.toList(),
));

Expand All @@ -100,7 +100,7 @@ final class ChannelProperties {
type: findInEnum(ChannelType.values, element['type']),
name: element['name'],
description: element['description'],
guildId: Helper.createOrNull(
serverId: Helper.createOrNull(
field: element['guild_id'], fn: () => Snowflake(element['guild_id'])),
categoryId: Helper.createOrNull(
field: element['parent_id'], fn: () => Snowflake(element['parent_id'])),
Expand Down Expand Up @@ -139,15 +139,15 @@ final class ChannelProperties {
fn: () async => Future.wait(
List.from(element['permission_overwrites'])
.map((json) async =>
marshaller.serializers.channelPermissionOverwrite.serializeRemote(json))
marshaller.serializers.channelPermissionOverwrite.serialize(json))
.toList(),
));

final recipients = await Helper.createOrNullAsync(
field: element['recipients'],
fn: () async => Future.wait(
List.from(element['recipients'])
.map((json) async => marshaller.serializers.user.serializeRemote(json))
.map((json) async => marshaller.serializers.user.serialize(json))
.toList(),
));

Expand All @@ -156,8 +156,8 @@ final class ChannelProperties {
type: findInEnum(ChannelType.values, element['type']),
name: element['name'],
description: element['description'],
guildId: Helper.createOrNull(
field: element['guild_id'], fn: () => Snowflake(element['guild_id'])),
serverId: Helper.createOrNull(
field: element['server_id'], fn: () => Snowflake(element['server_id'])),
categoryId: Helper.createOrNull(
field: element['parent_id'], fn: () => Snowflake(element['parent_id'])),
position: element['position'],
Expand Down
2 changes: 0 additions & 2 deletions lib/api/common/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/api/server/role.dart';

final class Emoji extends PartialEmoji {
final String? globalName;
final Map<Snowflake, Role> roles;
final bool managed;
final bool available;

Emoji({
required Snowflake id,
required String name,
required this.globalName,
required this.roles,
required this.managed,
required this.available,
Expand Down
2 changes: 1 addition & 1 deletion lib/api/common/message_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class MessageProperties<T extends Channel> {
factory MessageProperties.fromJson(T channel, Map<String, dynamic> json) {
final embedSerializer = ioc.resolve<MarshallerContract>().serializers.embed;
final embeds = List.from(json['embeds'])
.map((element) => embedSerializer.serializeRemote(element) as MessageEmbed)
.map((element) => embedSerializer.serialize(element) as MessageEmbed)
.toList();

return MessageProperties(
Expand Down
3 changes: 3 additions & 0 deletions lib/api/common/polls/poll.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'package:mineral/api/common/polls/poll_answer.dart';
import 'package:mineral/api/common/polls/poll_layout.dart';
import 'package:mineral/api/common/polls/poll_question.dart';
import 'package:mineral/api/common/snowflake.dart';

final class Poll {
final PollQuestion question;
final List<PollAnswer> answers;
final Duration? expireAt;
final bool isAllowMultiple;
final Snowflake? messageId;
final PollLayout layout;

Poll({
required this.question,
required this.answers,
required this.expireAt,
required this.isAllowMultiple,
this.messageId,
this.layout = PollLayout.initial,
});
}
2 changes: 2 additions & 0 deletions lib/api/common/sticker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class Sticker {
final FormatType? formatType;
final bool isAvailable;
final int? sortValue;
final Snowflake? serverId;

Sticker({
required this.id,
Expand All @@ -25,5 +26,6 @@ final class Sticker {
this.asset,
this.formatType,
this.sortValue,
this.serverId,
});
}
2 changes: 1 addition & 1 deletion lib/api/private/private_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class PrivateMessage implements Message<PrivateChannel> {

DateTime? get updatedAt => _properties.updatedAt;

final String userId;
final Snowflake userId;

final User author;

Expand Down
15 changes: 3 additions & 12 deletions lib/api/private/user_assets.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import 'package:mineral/api/common/image_asset.dart';
import 'package:mineral/api/common/snowflake.dart';
import 'package:mineral/infrastructure/commons/helper.dart';

final class UserAssets {
final Snowflake userId;
final ImageAsset? avatar;
final ImageAsset? avatarDecoration;
final ImageAsset? banner;

UserAssets({
required this.userId,
required this.avatar,
required this.avatarDecoration,
required this.banner,
});

factory UserAssets.fromJson(Map<String, dynamic> json) {
return UserAssets(
avatar: Helper.createOrNull(
field: json['avatar'], fn: () => ImageAsset(['avatars', json['id']], json['avatar'])),
avatarDecoration: Helper.createOrNull(
field: json['avatar_decoration_data']?['sku_id'],
fn: () => ImageAsset(['avatar-decorations', json['id']], json['avatar_decoration_data']['sku_id'])),
banner: Helper.createOrNull(
field: json['banner'], fn: () => ImageAsset(['banners', json['id']], json['banner'])),
);
}
}
2 changes: 1 addition & 1 deletion lib/api/server/channels/server_announcement_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ServerAnnouncementChannel extends ServerChannel {
bool get isNsfw => _properties.nsfw;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

Snowflake? get categoryId => _properties.categoryId;

Expand Down
2 changes: 1 addition & 1 deletion lib/api/server/channels/server_category_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ServerCategoryChannel extends ServerChannel {
List<ChannelPermissionOverwrite> get permissions => _properties.permissions!;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

ServerCategoryChannel(this._properties): _methods = ChannelMethods(_properties.id);

Expand Down
2 changes: 1 addition & 1 deletion lib/api/server/channels/server_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class ServerChannel implements Channel {
String get name;
List<ChannelPermissionOverwrite> get permissions;
int get position;
Snowflake get guildId;
Snowflake get serverId;

@override
T cast<T extends Channel>() => this as T;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/server/channels/server_forum_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class ServerForumChannel extends ServerChannel {
late final ServerCategoryChannel? category;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

ServerForumChannel(this._properties,
{required this.sortOrder, required this.layoutType});
Expand Down
4 changes: 2 additions & 2 deletions lib/api/server/channels/server_stage_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ServerStageChannel extends ServerChannel {
String? get description => _properties.description;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

Snowflake? get categoryId => _properties.categoryId;

Expand Down Expand Up @@ -65,7 +65,7 @@ final class ServerStageChannel extends ServerChannel {
_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);
_methods.send(guildId: _properties.serverId, content: content, embeds: embeds, poll: poll);

Future<void> delete({String? reason}) => _methods.delete(reason);
}
4 changes: 2 additions & 2 deletions lib/api/server/channels/server_text_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class ServerTextChannel extends ServerChannel {
String? get description => _properties.description;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

Snowflake? get categoryId => _properties.categoryId;

Expand Down Expand Up @@ -71,7 +71,7 @@ final class ServerTextChannel extends ServerChannel {
Poll? poll,
List<MessageComponent>? components}) =>
_methods.send(
guildId: _properties.guildId,
guildId: _properties.serverId,
content: content,
embeds: embeds,
poll: poll,
Expand Down
2 changes: 1 addition & 1 deletion lib/api/server/channels/server_voice_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class ServerVoiceChannel extends ServerChannel {
List<ChannelPermissionOverwrite> get permissions => _properties.permissions!;

@override
Snowflake get guildId => _properties.guildId!;
Snowflake get serverId => _properties.serverId!;

Snowflake? get categoryId => _properties.categoryId;

Expand Down
29 changes: 19 additions & 10 deletions lib/api/server/managers/channel_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ enum _ServerNamedChannel {

final class ChannelManager {
final Map<_ServerNamedChannel, Snowflake?> _namedChannels = {};
final Map<Snowflake, ServerChannel> _channels = {};

ChannelManager(Map<String, dynamic> json) {
_namedChannels..putIfAbsent(
_ServerNamedChannel.afkChannel, () => json['afk_channel_id'])..putIfAbsent(
_ServerNamedChannel.systemChannel, () => json['system_channel_id'])..putIfAbsent(
_ServerNamedChannel.rulesChannel, () => json['rules_channel_id'])..putIfAbsent(
_ServerNamedChannel
.publicUpdatesChannel, () => json['public_updates_channel_id'])..putIfAbsent(
_ServerNamedChannel.safetyAlertsChannel, () => json['safety_alerts_channel_id']);
final Map<Snowflake, ServerChannel> _channels;

ChannelManager(this._channels, Map<String, dynamic> json) {
_namedChannels
..putIfAbsent(_ServerNamedChannel.afkChannel, () => json['afk_channel_id'])
..putIfAbsent(_ServerNamedChannel.systemChannel, () => json['system_channel_id'])
..putIfAbsent(_ServerNamedChannel.rulesChannel, () => json['rules_channel_id'])
..putIfAbsent(
_ServerNamedChannel.publicUpdatesChannel, () => json['public_updates_channel_id'])
..putIfAbsent(
_ServerNamedChannel.safetyAlertsChannel, () => json['safety_alerts_channel_id']);
}

Map<Snowflake, ServerChannel> get list => _channels;
Expand Down Expand Up @@ -51,4 +52,12 @@ final class ChannelManager {

ServerTextChannel? get widgetChannel =>
getOrNull<ServerTextChannel>(_namedChannels[_ServerNamedChannel.widgetChannel]);

factory ChannelManager.fromList(List<ServerChannel> channels, payload) {
return ChannelManager(
Map<Snowflake, ServerChannel>.from(channels.fold({}, (value, element) {
return {...value, element.id: element};
})),
payload);
}
}
12 changes: 3 additions & 9 deletions lib/api/server/managers/emoji_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ final class EmojiManager {

Map<Snowflake, Emoji> get list => _emojis;

factory EmojiManager.fromJson(MarshallerContract marshaller,
{required List<Role> roles, required List<dynamic> payload}) {
return EmojiManager(Map<Snowflake, Emoji>.from(payload.fold({}, (value, element) {
final emoji = marshaller.serializers.emojis.serializeRemote({
'guildRoles': roles,
...element,
}) as Emoji;

return {...value, emoji.id: emoji};
factory EmojiManager.fromList(List<Role> roles, List<Emoji> emojis) {
return EmojiManager(Map<Snowflake, Emoji>.from(emojis.fold({}, (value, element) {
return {...value, element.id: element};
})));
}
}
11 changes: 4 additions & 7 deletions lib/api/server/managers/sticker_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ final class StickerManager {

Map<Snowflake, Sticker> get list => _stickers;

factory StickerManager.fromJson(MarshallerContract marshaller, List<dynamic> payload) {
final Map<Snowflake, Sticker> stickers = payload.fold({}, (value, element) {
final sticker = marshaller.serializers.sticker.serializeRemote(element) as Sticker;
return {...value, sticker.id: sticker};
});

return StickerManager(stickers);
factory StickerManager.fromList(List<Sticker> stickers) {
return StickerManager(stickers.fold({}, (acc, sticker) {
return {...acc, sticker.id: sticker};
}));
}
}
2 changes: 0 additions & 2 deletions lib/api/server/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ final class Member {
final PremiumTier premiumType;
final DateTime? joinedAt;
final Permissions permissions;
final bool pending;
final int? accentColor;
final MemberFlagsManager flags;
Presence? presence;
Expand Down Expand Up @@ -114,7 +113,6 @@ final class Member {
required this.premiumType,
required this.joinedAt,
required this.permissions,
required this.pending,
required this.accentColor,
required this.presence,
}) {
Expand Down
18 changes: 5 additions & 13 deletions lib/api/server/member_assets.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import 'package:mineral/api/common/image_asset.dart';
import 'package:mineral/infrastructure/commons/helper.dart';
import 'package:mineral/api/common/snowflake.dart';

final class MemberAssets {
final ImageAsset? avatar;
final ImageAsset? avatarDecoration;
final ImageAsset? banner;
final Snowflake memberId;
final Snowflake serverId;

MemberAssets({
required this.avatar,
required this.avatarDecoration,
required this.banner,
required this.memberId,
required this.serverId,
});

factory MemberAssets.fromJson(Map<String, dynamic> json) {
return MemberAssets(
avatar: Helper.createOrNull(
field: json['avatar'], fn: () => ImageAsset(['avatars', json['id']], json['avatar'])),
avatarDecoration: Helper.createOrNull(
field: json['avatar_decoration_data']?['sku_id'],
fn: () => ImageAsset(['avatar-decorations', json['id']], json['avatar_decoration_data']['sku_id'])),
banner: Helper.createOrNull(
field: json['banner'], fn: () => ImageAsset(['banners', json['id']], json['banner'])),
);
}
}
Loading