From bba37642a8574563a9bb96f0a7ee6a33f0f2968f Mon Sep 17 00:00:00 2001 From: DinoLeung Date: Sun, 31 Mar 2024 19:55:04 +1030 Subject: [PATCH] use enum in input media --- lib/src/telegram/models/input_media.dart | 26 ++++++++++++++----- .../models/input_media_animation.dart | 4 +-- .../telegram/models/input_media_audio.dart | 4 +-- .../telegram/models/input_media_document.dart | 6 ++--- .../telegram/models/input_media_photo.dart | 4 +-- .../telegram/models/input_media_video.dart | 4 +-- .../models/input_media_with_thumbnail.dart | 2 +- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/src/telegram/models/input_media.dart b/lib/src/telegram/models/input_media.dart index a1960fd..e5ef577 100644 --- a/lib/src/telegram/models/input_media.dart +++ b/lib/src/telegram/models/input_media.dart @@ -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 @@ -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; diff --git a/lib/src/telegram/models/input_media_animation.dart b/lib/src/telegram/models/input_media_animation.dart index 98eff42..37dd12f 100644 --- a/lib/src/telegram/models/input_media_animation.dart +++ b/lib/src/telegram/models/input_media_animation.dart @@ -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 @@ -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, diff --git a/lib/src/telegram/models/input_media_audio.dart b/lib/src/telegram/models/input_media_audio.dart index f934110..d6422d1 100644 --- a/lib/src/telegram/models/input_media_audio.dart +++ b/lib/src/telegram/models/input_media_audio.dart @@ -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 @@ -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, diff --git a/lib/src/telegram/models/input_media_document.dart b/lib/src/telegram/models/input_media_document.dart index ac5c5d5..2367013 100644 --- a/lib/src/telegram/models/input_media_document.dart +++ b/lib/src/telegram/models/input_media_document.dart @@ -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 @@ -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, @@ -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, diff --git a/lib/src/telegram/models/input_media_photo.dart b/lib/src/telegram/models/input_media_photo.dart index c211968..1ed1e3b 100644 --- a/lib/src/telegram/models/input_media_photo.dart +++ b/lib/src/telegram/models/input_media_photo.dart @@ -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 @@ -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, diff --git a/lib/src/telegram/models/input_media_video.dart b/lib/src/telegram/models/input_media_video.dart index 2448bc6..877a964 100644 --- a/lib/src/telegram/models/input_media_video.dart +++ b/lib/src/telegram/models/input_media_video.dart @@ -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 @@ -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, diff --git a/lib/src/telegram/models/input_media_with_thumbnail.dart b/lib/src/telegram/models/input_media_with_thumbnail.dart index 806bc6e..e6784c1 100644 --- a/lib/src/telegram/models/input_media_with_thumbnail.dart +++ b/lib/src/telegram/models/input_media_with_thumbnail.dart @@ -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