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(serializers): implement api serializers #140

Merged
merged 55 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
888d902
feat(api): added fromJson method for PartialApplication
LeadcodeDev Dec 30, 2023
b481e9f
feat(api): added fromJson method for role
LeadcodeDev Dec 30, 2023
a99a6f3
feat(api): added avatar decoration
LeadcodeDev Jan 2, 2024
ad2ad3b
feat(api): added member collection
LeadcodeDev Jan 2, 2024
e56281e
feat(api): added true types and implemented factory
LeadcodeDev Jan 2, 2024
fbba1bf
feat(api): implemented factories
LeadcodeDev Jan 2, 2024
c9f2e58
feat(api): implemented factories
LeadcodeDev Jan 2, 2024
b022997
feat(api): implemented channels factories
LeadcodeDev Jan 2, 2024
b61058e
feat(api): added dynamic intent value
LeadcodeDev Jan 2, 2024
4a18564
feat(api): enhanced types and implemented factory
LeadcodeDev Jan 2, 2024
2424bf3
feat(api): implement role and emoji collection
LeadcodeDev Jan 2, 2024
70e9a14
feat(api): added createOrNull utils
LeadcodeDev Jan 2, 2024
6fef31f
feat(api): changed types
LeadcodeDev Jan 2, 2024
77d910f
feat(api): changed emoji constructor declaration
LeadcodeDev Jan 2, 2024
9ffbe1a
feat(api): implemented guild create packet
LeadcodeDev Jan 2, 2024
23dc0ba
feat(api): implemented guild create event
LeadcodeDev Jan 2, 2024
38e02af
feat(api): implemented forum channel factory
LeadcodeDev Jan 2, 2024
06d3160
feat(api): implemented partial emoji factory and changed description …
LeadcodeDev Jan 2, 2024
22f2c08
feat(api): implemented some guild channels
LeadcodeDev Jan 2, 2024
a3fa756
feat(api): added generics to createOrNull method
LeadcodeDev Jan 2, 2024
cda1a02
feat(api): implemented sticker
LeadcodeDev Jan 2, 2024
f5e20cb
feat(api): implemented guild create event
LeadcodeDev Jan 2, 2024
e49db4c
feat(kernel): added create guild event packet
LeadcodeDev Jan 3, 2024
337071e
feat(api): implemented enums on guild
LeadcodeDev Jan 3, 2024
7e53e23
feat(api): remove late field in guild
LeadcodeDev Jan 3, 2024
8180dfb
feat(api): add get methods
LeadcodeDev Jan 3, 2024
588fa14
feat(api): implemented mfa level
LeadcodeDev Jan 3, 2024
4984bbc
feat(api): implemented system channel flag flags
LeadcodeDev Jan 3, 2024
8ce4866
feat(api): implemented widget channel and remove channelIds
LeadcodeDev Jan 3, 2024
52cb3de
feat(api): create findInEnum helper
LeadcodeDev Jan 3, 2024
99e44b0
feat(api): move guildChannels to dedicated collection
LeadcodeDev Jan 3, 2024
839ccf6
feat(api): implement guild assets and move asset fields into them
LeadcodeDev Jan 3, 2024
aedb2ef
feat(api): move settings to dedicated guild settings class
LeadcodeDev Jan 3, 2024
25f8f25
feat(api): implemented nsfw level enum
LeadcodeDev Jan 3, 2024
1ebdd40
feat(api): implemented premium tier enum
LeadcodeDev Jan 3, 2024
0c70e52
feat(api): change channel as abstract class
LeadcodeDev Jan 3, 2024
aaf1dd6
feat(api): move position to constructor parameters
LeadcodeDev Jan 3, 2024
ebbcd9e
feat(api): move max member
LeadcodeDev Jan 4, 2024
08c0e9a
feat(api): move subscriptions to dedicated class
LeadcodeDev Jan 4, 2024
0256581
feat(api): move hasEnabledProgressBar
LeadcodeDev Jan 4, 2024
36b2dbd
fix(api): add missing tokens
LeadcodeDev Jan 4, 2024
050c9c6
fix(api): add extends of Channel instead of implement
LeadcodeDev Jan 5, 2024
e4a2a52
fix(logger): implemented logger
LeadcodeDev Jan 5, 2024
d749db7
refactor(guild): rename Guild terme to Server
LeadcodeDev Jan 5, 2024
5e9c7cb
refactor(collections): rename collection to manager
LeadcodeDev Jan 5, 2024
3a36937
refactor(collections): move stickers and emoji into server assets
LeadcodeDev Jan 5, 2024
44c4233
refactor(collections): move stickers and emoji into server assets
LeadcodeDev Jan 5, 2024
fb42d37
refactor(members): move bots to members getter
LeadcodeDev Jan 5, 2024
43bb871
refactor(members): change order declaration
LeadcodeDev Jan 5, 2024
6663205
feat(memory): implemented memory storage
LeadcodeDev Jan 5, 2024
7864ead
refactor(api): refactor GuildMember to Member
LeadcodeDev Jan 5, 2024
d34fb96
feat(memory): implemented memory storage
LeadcodeDev Jan 5, 2024
2d580d8
feat(api): implemented server message event
LeadcodeDev Jan 6, 2024
7119ec3
feat(api): refactor message packet
LeadcodeDev Jan 6, 2024
e40909a
feat(api): implemented logger
LeadcodeDev Jan 6, 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
10 changes: 10 additions & 0 deletions lib/api/common/avatar_decoration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
final class AvatarDecoration {
final String skuId;
final String asset;

AvatarDecoration({ required this.skuId, required this.asset });

factory AvatarDecoration.fromJson(Map<String, dynamic> json) {
return AvatarDecoration(skuId: json['sku_id'], asset: json['asset']);
}
}
8 changes: 5 additions & 3 deletions lib/api/common/channel.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
abstract interface class Channel {
String get id;
String get name;
abstract class Channel {
final String id;
final String name;

const Channel(this.id, this.name);
}
33 changes: 26 additions & 7 deletions lib/api/common/emoji.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import 'package:mineral/api/server/role.dart';

final class Emoji extends PartialEmoji {
final String? globalName;
final List<Role> roles;
final User? user;
final Map<String, Role> roles;
final bool managed;
final bool animated;
final bool available;
Expand All @@ -15,12 +14,32 @@ final class Emoji extends PartialEmoji {
required String name,
required this.globalName,
required this.roles,
required this.user,
required this.managed,
required this.animated,
required this.available,
}) : super(
id: id,
name: name,
);
}) : super(id, name);

factory Emoji.fromJson(
{required Map<String, Role> guildRoles, required Map<String, dynamic> json}) {
final Map<String, Role> roles = List<String>.from(json['roles']).fold({}, (value, element) {
final role = guildRoles[element];

if (role == null) {
// Todo add report case
return value;
}

return {...value, role.id: role};
});

return Emoji(
id: json['id'],
name: json['name'],
globalName: json['global_name'],
roles: roles,
managed: json['managed'],
animated: json['animated'],
available: json['available'],
);
}
}
38 changes: 38 additions & 0 deletions lib/api/common/image_asset.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:mineral/api/common/types/enhanced_enum.dart';

enum ImageExtension implements EnhancedEnum<String> {
png('.png'),
jpeg('.jpeg'),
webp('.webp'),
gif('.gif'),
lottie('.json');

@override
final String value;

const ImageExtension(this.value);
}

final class ImageAsset {
String get _baseUrl => 'https://cdn.discordapp.com';

final List<String> _fragments;
final String _hash;

ImageAsset(this._fragments, this._hash);

String get url => '$_baseUrl/${_fragments.join('/')}/$_hash.png';

String makeUrl({ ImageExtension extension = ImageExtension.png, int? size }) {
if (size case int() when size < 16 || size > 4096) {
throw ArgumentError('Size must be between 16 and 4096');
}

final fragments = [..._fragments, _hash, extension.value];
if (size != null) {
fragments.add('size=$size');
}

return '$url/${fragments.join('/')}';
}
}
21 changes: 14 additions & 7 deletions lib/api/common/message.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'package:mineral/api/common/channel.dart';

abstract interface class Message {
String get id;
String get content;
String get createdAt;
String get updatedAt;
String get channelId;
Channel get channel;
abstract class Message<T extends Channel> {
final String id;
final String content;
final T channel;
final DateTime createdAt;
final DateTime? updatedAt;

Message(
this.id,
this.content,
this.channel,
this.createdAt,
this.updatedAt,
);
}
7 changes: 7 additions & 0 deletions lib/api/common/partial_appication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ final class PartialApplication {
required this.id,
required this.flags,
});

factory PartialApplication.fromJson(Map<String, dynamic> json) {
return PartialApplication(
id: json['id'],
flags: json['flags'],
);
}
}
18 changes: 11 additions & 7 deletions lib/api/common/partial_emoji.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
abstract class PartialEmoji {
String name;
String id;
class PartialEmoji {
final String id;
final String name;

PartialEmoji({
required this.name,
required this.id,
});
const PartialEmoji(this.name, this.id);

factory PartialEmoji.fromJson(Map<String, dynamic> json) {
return PartialEmoji(
json['id'],
json['name'],
);
}
}
43 changes: 43 additions & 0 deletions lib/api/common/sticker.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:mineral/api/common/types/format_type.dart';
import 'package:mineral/api/common/types/sticker_type.dart';

final class Sticker {
final String id;
final String? packId;
final String name;
final String? description;
final String? tags;
final String? asset;
final StickerType type;
final FormatType? formatType;
final bool isAvailable;
final int? sortValue;

Sticker({
required this.id,
required this.name,
required this.type,
required this.isAvailable,
this.packId,
this.description,
this.tags,
this.asset,
this.formatType,
this.sortValue,
});

factory Sticker.fromJson(Map<String, dynamic> json) {
return Sticker(
id: json['id'],
name: json['name'],
type: StickerType.values.firstWhere((element) => element.value == json['type']),
isAvailable: json['available'],
packId: json['pack_id'],
description: json['description'],
tags: json['tags'],
asset: json['asset'],
formatType: FormatType.values.firstWhere((element) => element.value == json['format_type']),
sortValue: json['sort_value'],
);
}
}
18 changes: 18 additions & 0 deletions lib/api/common/types/channel_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum ChannelType {
guildText(0),
dm(1),
guildVoice(2),
groupDm(3),
guildCategory(4),
guildAnnouncement(5),
announcementThread(10),
guildPublicThread(11),
guildPrivateThread(12),
guildStageVoice(13),
guildDirectory(14),
guildForum(15),
guildMedia(16);

final int value;
const ChannelType(this.value);
}
4 changes: 4 additions & 0 deletions lib/api/common/types/enhanced_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface class EnhancedEnum<R> {
final R value;
const EnhancedEnum(this.value);
}
7 changes: 7 additions & 0 deletions lib/api/common/types/format_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum FormatType {
standard(1),
guild(2);

final int value;
const FormatType(this.value);
}
7 changes: 7 additions & 0 deletions lib/api/common/types/sticker_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum StickerType {
standard(1),
guild(2);

final int value;
const StickerType(this.value);
}
14 changes: 4 additions & 10 deletions lib/api/private/channels/private_channel.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import 'package:mineral/api/common/channel.dart';

final class PrivateChannel implements Channel {
@override
final String id;

@override
final String name;

final class PrivateChannel extends Channel {
PrivateChannel({
required this.id,
required this.name,
});
required String id,
required String name,
}): super(id, name);
}
16 changes: 5 additions & 11 deletions lib/api/private/channels/private_group_channel.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import 'package:mineral/api/common/channel.dart';

final class PrivateChannel implements Channel {
@override
final String id;

@override
final String name;

final class PrivateGroupChannel extends Channel {
final List<String> users;

PrivateChannel({
required this.id,
required this.name,
PrivateGroupChannel({
required String id,
required String name,
required this.users,
});
}): super(id, name);
}
35 changes: 8 additions & 27 deletions lib/api/private/private_message.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import 'package:mineral/api/common/channel.dart';
import 'package:mineral/api/common/message.dart';
import 'package:mineral/api/private/channels/private_channel.dart';
import 'package:mineral/api/private/user.dart';

final class PrivateMessage implements Message {
@override
final String id;

@override
final String content;

@override
final String createdAt;

@override
final String updatedAt;

@override
final String channelId;

@override
PrivateChannel channel;

final class PrivateMessage extends Message<Channel> {
final String userId;

final User user;

PrivateMessage({
required this.id,
required this.content,
required this.createdAt,
required this.updatedAt,
required this.channelId,
required this.channel,
required String id,
required String content,
required DateTime createdAt,
required DateTime updatedAt,
required Channel channel,
required this.userId,
required this.user,
});
}): super(id, content, channel, createdAt, updatedAt);
}
30 changes: 0 additions & 30 deletions lib/api/server/channels/guild_announcement_channel.dart

This file was deleted.

Loading