Skip to content

Commit

Permalink
use enum in chat member
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 31, 2024
1 parent 8a8655b commit 107eca1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
22 changes: 21 additions & 1 deletion lib/src/telegram/models/chat_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@

part of '../model.dart';

@JsonEnum()
enum ChatMemberStatus {
@JsonValue('creator')
creator,
@JsonValue('administrator')
administrator,
@JsonValue('member')
member,
@JsonValue('restricted')
restricted,
@JsonValue('left')
left,
@JsonValue('kicked')
kicked,
}

extension ChatMemberStatusExtenson on ChatMemberStatus {
String value() => _$ChatMemberStatusEnumMap[this]!;
}

/// This object contains information about one member of a chat.
///
/// Currently, the following 6 types of chat members are supported:
Expand All @@ -32,7 +52,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMember {
String status;
ChatMemberStatus status;
User user;

ChatMember({
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_administrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberAdministrator implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;
bool canBeEdited;
Expand All @@ -48,8 +48,8 @@ class ChatMemberAdministrator implements ChatMember {
String? customTitle;

ChatMemberAdministrator({
required this.status,
required this.user,
this.status = ChatMemberStatus.administrator,
this.canBeEdited = false,
this.isAnonymous = false,
this.canManageChat = false,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_banned.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberBanned implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;
int untilDate;

ChatMemberBanned({
required this.status,
required this.user,
required this.untilDate,
this.status = ChatMemberStatus.kicked,
});

@JsonKey(includeFromJson: false, includeToJson: false)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_left.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberLeft implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;

ChatMemberLeft({
required this.status,
required this.user,
this.status = ChatMemberStatus.left,
});

factory ChatMemberLeft.fromJson(Map<String, dynamic> json) =>
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberMember implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;

ChatMemberMember({
required this.status,
required this.user,
this.status = ChatMemberStatus.member,
});

factory ChatMemberMember.fromJson(Map<String, dynamic> json) =>
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_owner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberOwner implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;
bool isAnonymous;
String? customTitle;

ChatMemberOwner({
required this.user,
required this.status,
required this.isAnonymous,
this.status = ChatMemberStatus.creator,
this.customTitle,
});

Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/chat_member_restricted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class ChatMemberRestricted implements ChatMember {
@override
String status;
ChatMemberStatus status;
@override
User user;
bool isMember;
Expand All @@ -48,8 +48,8 @@ class ChatMemberRestricted implements ChatMember {
int untilDate;

ChatMemberRestricted({
required this.status,
required this.user,
this.status = ChatMemberStatus.restricted,
this.isMember = false,
this.canChangeInfo = false,
this.canInviteUsers = false,
Expand Down

0 comments on commit 107eca1

Please sign in to comment.