Skip to content

Commit

Permalink
use enum in input media
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 31, 2024
1 parent 5857f58 commit bba3764
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
26 changes: 19 additions & 7 deletions lib/src/telegram/models/input_media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@

part of '../model.dart';

@JsonEnum()
enum InputMediaType {
@JsonValue('animation')
animation,
@JsonValue('audio')
audio,
@JsonValue('document')
document,
@JsonValue('photo')
photo,
@JsonValue('video')
video,
}

extension InputMediaTypeExtenson on InputMediaType {
String value() => _$InputMediaTypeEnumMap[this]!;
}

/// This object represents the content of a media message to be sent.
///
/// It should be one of
Expand All @@ -30,13 +48,7 @@ part of '../model.dart';
/// https://core.telegram.org/bots/api#inputmedia
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMedia {
static const typeAnimation = 'animation';
static const typeAudio = 'audio';
static const typeDocument = 'document';
static const typePhoto = 'photo';
static const typeVideo = 'video';

String type;
InputMediaType type;
String media;
String? caption;
String? parseMode;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/input_media_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaAnimation implements InputMediaWithThumbnail {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand All @@ -48,7 +48,7 @@ class InputMediaAnimation implements InputMediaWithThumbnail {
MultipartFile? thumbnailFile;

InputMediaAnimation({
this.type = InputMedia.typeAnimation,
this.type = InputMediaType.animation,
required this.media,
this.thumbnail,
this.caption,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/input_media_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaAudio implements InputMediaWithThumbnail {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand All @@ -47,7 +47,7 @@ class InputMediaAudio implements InputMediaWithThumbnail {
MultipartFile? thumbnailFile;

InputMediaAudio({
this.type = InputMedia.typeAudio,
this.type = InputMediaType.audio,
required this.media,
this.thumbnail,
this.caption,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/telegram/models/input_media_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaDocument implements InputMediaWithThumbnail {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand All @@ -45,7 +45,7 @@ class InputMediaDocument implements InputMediaWithThumbnail {
MultipartFile? thumbnailFile;

InputMediaDocument({
this.type = InputMedia.typeDocument,
this.type = InputMediaType.document,
required this.media,
this.thumbnail,
this.caption,
Expand Down Expand Up @@ -83,7 +83,7 @@ class InputMediaDocument implements InputMediaWithThumbnail {
bool? disableContentTypeDetection,
}) =>
InputMediaDocument(
type: InputMedia.typeDocument,
type: InputMediaType.document,
media: media,
thumbnail: 'attach://${thumbnail.path}',
caption: caption,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/input_media_photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaPhoto implements InputMedia {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand All @@ -40,7 +40,7 @@ class InputMediaPhoto implements InputMedia {
MultipartFile? mediaFile;

InputMediaPhoto({
this.type = InputMedia.typePhoto,
this.type = InputMediaType.photo,
required this.media,
this.caption,
this.parseMode,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/input_media_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaVideo implements InputMediaWithThumbnail {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand All @@ -49,7 +49,7 @@ class InputMediaVideo implements InputMediaWithThumbnail {
MultipartFile? thumbnailFile;

InputMediaVideo({
this.type = InputMedia.typeVideo,
this.type = InputMediaType.video,
required this.media,
this.caption,
this.parseMode,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/telegram/models/input_media_with_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ part of '../model.dart';
@JsonSerializable(fieldRename: FieldRename.snake)
class InputMediaWithThumbnail implements InputMedia {
@override
String type;
InputMediaType type;
@override
String media;
@override
Expand Down

0 comments on commit bba3764

Please sign in to comment.