Skip to content

Commit

Permalink
feat(component): add customId with default value as null
Browse files Browse the repository at this point in the history
  • Loading branch information
LeadcodeDev authored and PandaGuerrier committed Aug 15, 2024
1 parent 50698db commit 91b9af0
Show file tree
Hide file tree
Showing 37 changed files with 98 additions and 29 deletions.
3 changes: 3 additions & 0 deletions lib/domains/events/contracts/common/ready_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ReadyEvent implements ListenableEvent {
@override
Event get event => Event.ready;

@override
String? customId;

FutureOr<void> handle(Bot bot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class PrivateButtonClickEvent implements ListenableEvent {
@override
Event get event => Event.privateButtonClick;

@override
String? customId;

FutureOr<void> handle(PrivateButtonContext ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ import 'package:mineral/domains/events/types/listenable_event.dart';
typedef PrivateChannelCreateEventHandler = FutureOr<void> Function(PrivateChannel);

abstract class PrivateChannelCreateEvent implements ListenableEvent {
@override
String? customId;

FutureOr<void> handle(PrivateChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class PrivateChannelDeleteEvent implements ListenableEvent {
@override
Event get event => Event.privateChannelDelete;

@override
String? customId;

FutureOr<void> handle(PrivateChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class PrivateChannelPinsUpdateEvent implements ListenableEvent {
@override
Event get event => Event.privateChannelPinsUpdate;

@override
String? customId;

FutureOr<void> handle(PrivateChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class PrivateChannelUpdateEvent implements ListenableEvent {
@override
Event get event => Event.privateChannelUpdate;

@override
String? customId;

FutureOr<void> handle(PrivateChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class PrivateDialogSubmitEvent implements ListenableEvent {
@override
Event get event => Event.privateDialogSubmit;

@override
String? customId;

FutureOr<void> handle(PrivateDialogContext ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class PrivateMessageCreateEvent implements ListenableEvent {
@override
Event get event => Event.privateMessageCreate;

@override
String? customId;

FutureOr<void> handle(PrivateMessage message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class PrivateTextSelectEvent implements ListenableEvent {
@override
Event get event => Event.serverTextSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(PrivateSelectContext ctx, List<String> values);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ abstract class PrivateUserSelectEvent implements ListenableEvent {
@override
Event get event => Event.privateUserSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(PrivateSelectContext ctx, List<User> roles);
}
3 changes: 3 additions & 0 deletions lib/domains/events/contracts/server/server_ban_add_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ abstract class ServerBanAddEvent implements ListenableEvent {
@override
Event get event => Event.serverBanAdd;

@override
String? customId;

FutureOr<void> handle(Member? member, User user, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerBanRemoveEvent implements ListenableEvent {
@override
Event get event => Event.serverBanRemove;

@override
String? customId;

FutureOr<void> handle(User user, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class ServerButtonClickEvent implements ListenableEvent {
@override
Event get event => Event.serverButtonClick;

@override
String? customId;

FutureOr<void> handle(ServerButtonContext ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerChannelCreateEvent implements ListenableEvent {
@override
Event get event => Event.serverChannelCreate;

@override
String? customId;

FutureOr<void> handle(ServerChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerChannelDeleteEvent implements ListenableEvent {
@override
Event get event => Event.serverChannelDelete;

@override
String? customId;

FutureOr<void> handle(ServerChannel? channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerChannelPinsUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverChannelPinsUpdate;

@override
String? customId;

FutureOr<void> handle(Server server, ServerChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ abstract class ServerChannelSelectEvent implements ListenableEvent {
@override
Event get event => Event.serverChannelSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(ServerSelectContext ctx, List<ServerChannel> channels);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerChannelUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverChannelUpdate;

@override
String? customId;

FutureOr<void> handle(ServerChannel before, ServerChannel after);
}
3 changes: 3 additions & 0 deletions lib/domains/events/contracts/server/server_create_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerCreateEvent implements ListenableEvent {
@override
Event get event => Event.serverCreate;

@override
String? customId;

FutureOr<void> handle(Server server);
}
3 changes: 3 additions & 0 deletions lib/domains/events/contracts/server/server_delete_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerDeleteEvent implements ListenableEvent {
@override
Event get event => Event.serverDelete;

@override
String? customId;

FutureOr<void> handle(Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class ServerDialogSubmitEvent implements ListenableEvent {
@override
Event get event => Event.serverDialogSubmit;

String? get customId;
@override
String? customId;

FutureOr<void> handle(ServerDialogContext ctx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerEmojisUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverEmojisUpdate;

@override
String? customId;

FutureOr<void> handle(EmojiManager emojisManager, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerMemberAddEvent implements ListenableEvent {
@override
Event get event => Event.serverMemberAdd;

@override
String? customId;

FutureOr<void> handle(Member member, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerMemberRemoveEvent implements ListenableEvent {
@override
Event get event => Event.serverMemberRemove;

@override
String? customId;

FutureOr<void> handle(User? user, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ abstract class ServerMemberSelectEvent implements ListenableEvent {
@override
Event get event => Event.serverMemberSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(ServerSelectContext ctx, List<Member> members);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerMemberUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverMemberUpdate;

@override
String? customId;

FutureOr<void> handle(Member after, Member before, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerMessageCreateEvent implements ListenableEvent {
@override
Event get event => Event.serverMessageCreate;

@override
String? customId;

FutureOr<void> handle(ServerMessage message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ abstract class ServerPresenceUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverPresenceUpdate;

@override
String? customId;

FutureOr<void> handle(Member member, Server server, Presence presence);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:mineral/api/server/channels/server_channel.dart';
import 'package:mineral/api/server/role.dart';
import 'package:mineral/domains/components/selects/contexts/server_select_context.dart';
import 'package:mineral/domains/events/event.dart';
Expand All @@ -12,7 +11,8 @@ abstract class ServerRoleSelectEvent implements ListenableEvent {
@override
Event get event => Event.serverRoleSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(ServerSelectContext ctx, List<Role> roles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerRolesCreateEvent implements ListenableEvent {
@override
Event get event => Event.serverRoleCreate;

@override
String? customId;

FutureOr<void> handle(Role role, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerRolesDeleteEvent implements ListenableEvent {
@override
Event get event => Event.serverRoleDelete;

@override
String? customId;

FutureOr<void> handle(Role? role, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ abstract class ServerRolesUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverRoleUpdate;

@override
String? customId;

FutureOr<void> handle(Role before, Role after, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerStickersUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverStickersUpdate;

@override
String? customId;

FutureOr<void> handle(StickerManager stickerManager, Server server);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class ServerTextSelectEvent implements ListenableEvent {
@override
Event get event => Event.serverTextSelect;

String? get customId;
@override
String? customId;

FutureOr<void> handle(ServerSelectContext ctx, List<String> values);
}
3 changes: 3 additions & 0 deletions lib/domains/events/contracts/server/server_update_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ abstract class ServerUpdateEvent implements ListenableEvent {
@override
Event get event => Event.serverUpdate;

@override
String? customId;

FutureOr<void> handle(Server before, Server after);
}
1 change: 1 addition & 0 deletions lib/domains/events/types/listenable_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import 'package:mineral/infrastructure/commons/listenable.dart';

abstract interface class ListenableEvent implements Listenable {
Event get event;
String? get customId;
}
24 changes: 3 additions & 21 deletions lib/infrastructure/kernel/mineral_client.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import 'package:mineral/api/common/commands/command_contract.dart';
import 'package:mineral/domains/commands/command_declaration_bucket.dart';
import 'package:mineral/domains/events/contracts/server/server_channel_select_event.dart';
import 'package:mineral/domains/events/contracts/server/server_dialog_submit_event.dart';
import 'package:mineral/domains/events/contracts/server/server_member_select_event.dart';
import 'package:mineral/domains/events/contracts/server/server_role_select_event.dart';
import 'package:mineral/domains/events/contracts/server/server_text_select_event.dart';
import 'package:mineral/domains/events/contracts/private/private_dialog_submit_event.dart';
import 'package:mineral/domains/events/contracts/private/private_user_select_event.dart';
import 'package:mineral/domains/events/contracts/private/private_text_select_event.dart';
import 'package:mineral/domains/events/event_bucket.dart';
import 'package:mineral/domains/events/types/listenable_event.dart';
import 'package:mineral/infrastructure/commons/listenable.dart';
Expand Down Expand Up @@ -52,19 +44,9 @@ final class MineralClient implements MineralClientContract {
switch (instance) {
case ListenableEvent():
_kernel.eventListener.listen(
event: instance.event,
handle: (instance as dynamic).handle as Function,
customId: switch(instance) {
final ServerDialogSubmitEvent instance => instance.customId,
final ServerChannelSelectEvent instance => instance.customId,
final ServerRoleSelectEvent instance => instance.customId,
final ServerMemberSelectEvent instance => instance.customId,
final ServerTextSelectEvent instance => instance.customId,
final PrivateDialogSubmitEvent instance => instance.customId,
final PrivateUserSelectEvent instance => instance.customId,
final PrivateTextSelectEvent instance => instance.customId,
_ => null
}
event: instance.event,
handle: (instance as dynamic).handle as Function,
customId: instance.customId
);
}
}
Expand Down

0 comments on commit 91b9af0

Please sign in to comment.